]> ruin.nu Git - NDIRC.git/commitdiff
Converted Members
authorMichael Andreen <harv@ruin.nu>
Sat, 5 Dec 2009 13:25:22 +0000 (14:25 +0100)
committerMichael Andreen <harv@ruin.nu>
Sat, 5 Dec 2009 13:25:22 +0000 (14:25 +0100)
Commands/Members.pm

index 960728904c05feea288bba004d1757a5c0a231ec..f16922e019d0af30eee77a7ecfc79f11b85933b4 100644 (file)
 #   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;
+use MooseX::Declare;
+use NDIRC::Dispatcher;
 
-sub def
-       : Help(Show current calls)
-       : Type(member)
-{
-       my ($self,$c,$msg) = @_;
-       my $f = $c->model->prepare(q{
+command def => {
+       help => q(Show current calls),
+       type => q(member),
+}, class extends NDIRC::Command {
+       method execute($c,$msg) {
+               my $f = $c->model->prepare(q{
 SELECT (c.landing_tick - tick()) AS eta
        ,array_to_string(array_agg(i.shiptype),'/') AS shiptype
        ,dc.username
@@ -41,112 +39,118 @@ FROM calls c
 WHERE status = 'Open' AND (c.landing_tick - tick()) >= 7
 GROUP BY call,c.landing_tick,dc.username
 ORDER BY c.landing_tick;
-               });
-       $f->execute();
-       my $calls = "";
-       while (my @row = $f->fetchrow()){
-               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");
+                       });
+               $f->execute();
+               my $calls = "";
+               while (my @row = $f->fetchrow()){
+                       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) = @_;
+command raids => {
+       help => q(List currently open raids),
+       type => q(member),
+}, class extends NDIRC::Command {
+       method execute($c,$msg) {
 
-       my $f = $c->model->prepare(q{
+               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 = 'M')
-               });
-       $f->execute();
-       my $calls = "";
-       while (my ($raid) = $f->fetchrow()){
-               $calls .= " https://nd.ruin.nu/raids/view/$raid |"
+                       });
+               $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);
        }
-       $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->uid;
-       if ($msg =~ /(\S+)/ && $c->check_user_roles(qw/irc_points_others/)){
-               $nick = $1;
-               $f = $c->model->prepare(q{
+command points => {
+       help => q(syntax: .points [nick] | not everyone have access to check for others.),
+}, class extends NDIRC::Command {
+       method execute($c,$msg) {
+               my $f;
+               my $nick = $c->uid;
+               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{
+                               });
+               }else{
+                       $f = $c->model->prepare(q{
 SELECT username, attack_points, defense_points, scan_points, humor_points
 FROM users WHERE uid = ?
-               });
-       }
-       $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");
+                               });
+               }
+               $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{
+command sms => {
+       help => q(syntax: .sms nick | % can be used for wildcards %arro% will match barrow),
+       acl => q(irc_sms),
+}, class extends NDIRC::Command {
+       method execute($c,$msg) {
+               my ($nick) = $msg =~ /(\S+)/ or die 'ARGS';
+               my $f = $c->model->prepare(q{
 SELECT username,COALESCE(sms,'nothing added'), call_if_needed, timezone, sms_note
        ,to_char(NOW() AT TIME ZONE timezone,'HH24:MI') AS time
 FROM users WHERE username ILIKE ?
-               });
-       if (my ($username,$sms, $call, $timezone, $note, $time) = $c->model->selectrow_array($f,undef,$nick)){
-               $call = $call ?  'Wake up if needed' : 'Do not wake up';
-               $c->reply("<b>$username</b> has sms <b>$sms</b>, $call, <b>$time</b> ($timezone), $note ");
-       }else{
-               $c->reply("No hit, maybe spelling mistake, or add % as wildcard");
+                       });
+               if (my ($username,$sms, $call, $timezone, $note, $time) = $c->model->selectrow_array($f,undef,$nick)){
+                       $call = $call ?  'Wake up if needed' : 'Do not wake up';
+                       $c->reply("<b>$username</b> has sms <b>$sms</b>, $call, <b>$time</b> ($timezone), $note ");
+               }else{
+                       $c->reply("No hit, maybe spelling mistake, or add % as wildcard");
+               }
        }
-}
+};
 
-sub links
-       : Help(Shows link to webbie and maybe more links later)
-{
-       my ($self,$c,$msg) = @_;
-       $c->reply("https://nd.ruin.nu/");
-}
+command links => {
+       help => q(Shows link to webbie and maybe more links later),
+}, class extends NDIRC::Command {
+       method execute($c,$msg) {
+               $c->reply("https://nd.ruin.nu/");
+       }
+};
 
-sub forum
-       : Help(syntax: .forum [nick] | not everyone have access to check for others.)
-{
-       my ($self,$c,$msg) = @_;
-       my $dbh = $c->model;
+command forum => {
+       help => q(syntax: .forum [nick] | not everyone have access to check for others.),
+}, class extends NDIRC::Command {
+       method execute($c,$msg) {
+               my $dbh = $c->model;
 
-       my $user;
-       if ($msg =~ /(\S+)/ && $c->check_user_roles('irc_forum_others')){
-               $user = $dbh->selectrow_hashref(q{
+               my $user;
+               if ($msg =~ /(\S+)/ && $c->check_user_roles('irc_forum_others')){
+                       $user = $dbh->selectrow_hashref(q{
 SELECT uid,username FROM users WHERE username ILIKE ?
-               }, undef, $1);
-       }else{
-               $user = $dbh->selectrow_hashref(q{
+                               }, undef, $1);
+               }else{
+                       $user = $dbh->selectrow_hashref(q{
 SELECT uid,username FROM users WHERE uid = ?
-               }, undef, $c->uid);
-       }
-       if ($user){
-               my $unread = $dbh->selectrow_hashref(q{SELECT * FROM unread_posts($1)},undef,$user->{uid});
-               if ($unread){
-                       $c->reply("$user->{username} has $unread->{new} posts since your last forum visit ($unread->{unread} unread posts in total) https://nd.ruin.nu/forum/allUnread");
+                               }, undef, $c->uid);
+               }
+               if ($user){
+                       my $unread = $dbh->selectrow_hashref(q{SELECT * FROM unread_posts($1)},undef,$user->{uid});
+                       if ($unread){
+                               $c->reply("$user->{username} has $unread->{new} posts since your last forum visit ($unread->{unread} unread posts in total) https://nd.ruin.nu/forum/allUnread");
+                       }
                }
        }
-}
+};
 
 1;