From: Michael Andreen Date: Fri, 15 May 2009 21:35:34 +0000 (+0200) Subject: Converted .def, .points, .raids and .sms X-Git-Url: https://ruin.nu/git/?p=NDIRC.git;a=commitdiff_plain;h=66ce902aff4400269e2c2de3b9dbeee61448e3d5 Converted .def, .points, .raids and .sms --- diff --git a/Commands/Members.pm b/Commands/Members.pm new file mode 100644 index 0000000..a2f54ee --- /dev/null +++ b/Commands/Members.pm @@ -0,0 +1,119 @@ +#************************************************************************** +# Copyright (C) 2009 by Michael Andreen * +# * +# This program is free software; you can redistribute it and/or modify * +# it under the terms of the GNU General Public License as published by * +# the Free Software Foundation; either version 2 of the License, or * +# (at your option) any later version. * +# * +# This program is distributed in the hope that it will be useful, * +# but WITHOUT ANY WARRANTY; without even the implied warranty of * +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# GNU General Public License for more details. * +# * +# You should have received a copy of the GNU General Public License * +# along with this program; if not, write to the * +# Free Software Foundation, Inc., * +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +#**************************************************************************/ + +package NDIRC::Commands::Members; + +use strict; +use warnings; +use feature ':5.10'; + +use Moose; +use MooseX::MethodAttributes; + +sub def + : Help(Show current calls) + : Type(member) +{ + my ($self,$c,$msg) = @_; + my $f = $c->model->prepare(q{ +SELECT (c.landing_tick - tick()) AS eta, concat(i.shiptype||'/') AS shiptype + , dc.username +FROM calls c + JOIN incomings i ON i.call = c.id + LEFT OUTER JOIN users dc ON dc.uid = c.dc + JOIN users u ON u.uid = c.member +WHERE open AND (c.landing_tick - tick()) >= 7 +GROUP BY c.id,c.landing_tick,dc.username +ORDER BY c.landing_tick; + }); + $f->execute(); + my $calls = ""; + while (my @row = $f->fetchrow()){ + chop($row[1]); + my $dc = $row[2] // ''; + $calls .= " (Anti $row[1] ETA: $row[0] DC: $dc) |" + } + chop($calls); + if ($msg ne 'q' || length $calls > 0){ + $c->reply("Current calls: $calls"); + } +} + +sub raids + : Help(List currently open raids) + : Type(member) +{ + my ($self,$c,$msg) = @_; + + my $f = $c->model->prepare(q{ +SELECT id FROM raids +WHERE open AND not removed AND tick + waves - 7 > tick() +AND id IN (SELECT raid FROM raid_access WHERE gid = 2) + }); + $f->execute(); + my $calls = ""; + while (my ($raid) = $f->fetchrow()){ + $calls .= " https://nd.ruin.nu/raids/view/$raid |" + } + $calls = "No open future raids" if ($f->rows == 0); + chop($calls); + $c->reply($calls); +} + +sub points + : Help(syntax: .points [nick] | not everyone have access to check for others.) +{ + my ($self,$c,$msg) = @_; + my $f; + my $nick = $c->host; + if ($msg =~ /(\S+)/ && $c->check_user_roles(qw/irc_points_others/)){ + $nick = $1; + $f = $c->model->prepare(q{ +SELECT username, attack_points, defense_points, scan_points, humor_points +FROM users WHERE username ILIKE ? LIMIT 5 + }); + }else{ + $f = $c->model->prepare(q{ +SELECT username, attack_points, defense_points, scan_points, humor_points +FROM users WHERE hostmask ILIKE ? + }); + } + $f->execute($nick); + while (my @row = $f->fetchrow()){ + $c->reply("$row[0] has $row[1] Attack, $row[2] Defense, $row[3] Scan, $row[4] Humor points"); + } +} + +sub sms + : Help(syntax: .sms nick | % can be used for wildcards %arro% will match barrow) + : ACL(irc_sms) +{ + my ($self,$c,$msg) = @_; + my ($nick) = $msg =~ /(\S+)/ or die 'ARGS'; + my $f = $c->model->prepare(q{ +SELECT username,COALESCE(sms,'nothing added') FROM users WHERE username ILIKE ? + }); + if (my ($username,$sms) = $c->model->selectrow_array($f,undef,$nick)){ + $c->reply("$username has sms $sms"); + }else{ + $c->reply("No hit, maybe spelling mistake, or add % as wildcard"); + } +} + +1; diff --git a/Members.pm b/Members.pm deleted file mode 100644 index 027ac7c..0000000 --- a/Members.pm +++ /dev/null @@ -1,114 +0,0 @@ -#************************************************************************** -# Copyright (C) 2006 by Michael Andreen * -# * -# This program is free software; you can redistribute it and/or modify * -# it under the terms of the GNU General Public License as published by * -# the Free Software Foundation; either version 2 of the License, or * -# (at your option) any later version. * -# * -# This program is distributed in the hope that it will be useful, * -# but WITHOUT ANY WARRANTY; without even the implied warranty of * -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -# GNU General Public License for more details. * -# * -# You should have received a copy of the GNU General Public License * -# along with this program; if not, write to the * -# Free Software Foundation, Inc., * -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -#**************************************************************************/ -package NDIRC::Members; -use strict; -use warnings; -use NDIRC::Access; -use ND::DB; -require Exporter; - -our @ISA = qw/Exporter/; - -our @EXPORT = qw/currentCalls showraids checkPoints findSMS/; - -sub currentCalls { - my ($msg, $command) = @_; - if (1){ #TODO: add check for member - my $f = $ND::DBH->prepare(<= 7 - GROUP BY c.id,c.landing_tick,dc.username - ORDER BY c.landing_tick; -SQL -); - $f->execute(); - my $calls = ""; - while (my @row = $f->fetchrow()){ - chop($row[1]); - my $dc = defined $row[2] ? $row[2] : ''; - $calls .= " (Anti $row[1] ETA: $row[0] DC: $dc) |" - } - chop($calls); - if (defined $command || length $calls > 0){ - $ND::server->command("msg $ND::target Current calls: $calls"); - } - } -} - -sub showraids { - if (1){ #TODO: add check for member - my $f = $ND::DBH->prepare(< tick() - AND id IN (SELECT raid FROM raid_access WHERE gid = 2) -SQL -); - $f->execute(); - my $calls = ""; - while (my ($raid) = $f->fetchrow()){ - $calls .= " https://nd.ruin.nu/raids/view/$raid |" - } - $calls = "No open future raids" if ($f->rows == 0); - chop($calls); - $ND::server->command("msg $ND::target $calls"); - } -} - -sub checkPoints { - my ($nick,$command) = @_; - my $f; - if ($nick){ - if (officer() || dc() || bc() || ia()){ - $f = $ND::DBH->prepare("SELECT username, attack_points, defense_points, scan_points, humor_points FROM users WHERE username ILIKE ?"); - }else{ - $ND::server->command("msg $ND::target Only officers are allowed to check for others"); - } - } else{ - $f = $ND::DBH->prepare("SELECT username, attack_points, defense_points, scan_points, humor_points FROM users WHERE hostmask ILIKE ?"); - $nick = $ND::address; - } - if ($f){ - $f->execute($nick); - while (my @row = $f->fetchrow()){ - $ND::server->command("msg $ND::target $row[0] has $row[1] Attack, $row[2] Defense, $row[3] Scan, $row[4] Humor points"); - } - } -} - -sub findSMS { - my ($nick,$command) = @_; - unless (defined $nick){ - $ND::server->command("notice $ND::nick syntax: .$command nick | % can be used for wildcards \%arro\% will match barrow"); - return; - } - if (officer() || dc()){ - my $f = $ND::DBH->prepare("SELECT username,COALESCE(sms,'nothing added') FROM users WHERE username ILIKE ?"); - if (my ($username,$sms) = $ND::DBH->selectrow_array($f,undef,$nick)){ - $ND::server->command("notice $ND::nick $ND::B$username$ND::B has sms $ND::B$sms$ND::B"); - }else{ - $ND::server->command("notice $ND::nick No hit, maybe spelling mistake, or add % as wildcard"); - } - } -} - -1; diff --git a/database/roles.sql b/database/roles.sql index 9b0bbd2..1a024f8 100644 --- a/database/roles.sql +++ b/database/roles.sql @@ -7,6 +7,8 @@ INSERT INTO roles VALUES('irc_scanreqs'); INSERT INTO roles VALUES('irc_scan'); INSERT INTO roles VALUES('irc_anonscan'); INSERT INTO roles VALUES('irc_delquote'); +INSERT INTO roles VALUES('irc_points_others'); +INSERT INTO roles VALUES('irc_sms'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel'); @@ -15,6 +17,8 @@ INSERT INTO group_roles (gid,role) VALUES(1,'irc_masterinvite'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_scanreqs'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_anonscan'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_delquote'); +INSERT INTO group_roles (gid,role) VALUES(1,'irc_points_others'); +INSERT INTO group_roles (gid,role) VALUES(1,'irc_sms'); INSERT INTO group_roles (gid,role) VALUES(2,'irc_gs'); INSERT INTO group_roles (gid,role) VALUES(2,'irc_scan'); @@ -25,17 +29,23 @@ INSERT INTO group_roles (gid,role) VALUES(3,'irc_masterinvite'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_scanreqs'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_anonscan'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_delquote'); +INSERT INTO group_roles (gid,role) VALUES(3,'irc_points_others'); +INSERT INTO group_roles (gid,role) VALUES(3,'irc_sms'); +INSERT INTO group_roles (gid,role) VALUES(4,'irc_points_others'); INSERT INTO group_roles (gid,role) VALUES(5,'irc_p_nick'); INSERT INTO group_roles (gid,role) VALUES(5,'irc_p_intel'); INSERT INTO group_roles (gid,role) VALUES(6,'irc_p_intel'); +INSERT INTO group_roles (gid,role) VALUES(6,'irc_points_others'); +INSERT INTO group_roles (gid,role) VALUES(6,'irc_sms'); INSERT INTO group_roles (gid,role) VALUES(8,'irc_scanreqs'); INSERT INTO group_roles (gid,role) VALUES(8,'irc_anonscan'); INSERT INTO group_roles (gid,role) VALUES(18,'irc_p_nick'); INSERT INTO group_roles (gid,role) VALUES(18,'irc_p_intel'); +INSERT INTO group_roles (gid,role) VALUES(18,'irc_points_others'); INSERT INTO group_roles (gid,role) VALUES(19,'irc_p_intel'); diff --git a/ndawn.pl b/ndawn.pl index d61640d..ca09a20 100644 --- a/ndawn.pl +++ b/ndawn.pl @@ -55,11 +55,11 @@ my $TICK = $DBH->selectrow_array('SELECT tick()'); my $disp = new NDIRC::Dispatcher; -$disp->load('Basic','PA','Channel','Scans','Quotes'); +$disp->load('Basic','PA','Channel','Scans','Quotes','Members'); $ND::scanchan = '#testarmer'; $disp->add_channel('#testarlite', ['pub','help','channel']); -$disp->add_channel($ND::scanchan, ['pub','help','channel','scan']); +$disp->add_channel($ND::scanchan, ['pub','help','channel','scan','member']); $disp->add_channel('pm', ['pub','help','pm']); sub event_pubmsg {