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

index a576f74d7b3545c9cb685e0df5ce8d5a1de822ae..ae4b561b5b5bb872c75dd7a5ddaf021666249124 100644 (file)
 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 #**************************************************************************/
 
-package NDIRC::Commands::Misc;
-
 use strict;
 use warnings;
 
-use Moose;
-use MooseX::MethodAttributes;
+use MooseX::Declare;
+use NDIRC::Dispatcher;
 
-sub nosmoke
-       : Help(.nosmoke nick | shows how long the person has been smoke free)
-{
-       my ($self, $c, $msg) = @_;
-       my ($nick) = $msg =~ /^(\w+)?/;
-       my $dbh = $c->model;
+command nosmoke => {
+       help => q(.nosmoke nick | shows how long the person has been smoke free),
+}, class extends NDIRC::Command {
+       method execute($c,$msg) {
+               my ($nick) = $msg =~ /^(\w+)?/;
+               my $dbh = $c->model;
 
-       my $time = $dbh->selectrow_hashref(q{
+               my $time = $dbh->selectrow_hashref(q{
 SELECT date_part('day',time) AS days, date_part('hour',time) AS hours, date_part('minute',time) AS mins
 FROM (SELECT now() - time AS time FROM last_smokes WHERE nick = $1) l
-               },undef,$nick);
-       if ($time){
-               my $weeks = int($time->{days} / 7);
-               if ($weeks){
-                       $weeks = "$weeks weeks";
+                       },undef,$nick);
+               if ($time){
+                       my $weeks = int($time->{days} / 7);
+                       if ($weeks){
+                               $weeks = "$weeks weeks";
+                       }else{
+                               $weeks = "";
+                       }
+                       my $days = $time->{days} % 7;
+                       $c->reply("$nick has been smoke free for: $weeks $days days $time->{hours} hours and $time->{mins} minutes");
                }else{
-                       $weeks = "";
-               }
-               my $days = $time->{days} % 7;
-               $c->reply("$nick has been smoke free for: $weeks $days days $time->{hours} hours and $time->{mins} minutes");
-       }else{
-               my $nonsmokers = $dbh->prepare(q{SELECT nick FROM last_smokes ORDER BY nick});
-               $nonsmokers->execute;
-               my @nonsmokers;
-               while (my $nonsmoker = $nonsmokers->fetchrow_hashref){
-                       push @nonsmokers,$nonsmoker->{nick};
+                       my $nonsmokers = $dbh->prepare(q{SELECT nick FROM last_smokes ORDER BY nick});
+                       $nonsmokers->execute;
+                       my @nonsmokers;
+                       while (my $nonsmoker = $nonsmokers->fetchrow_hashref){
+                               push @nonsmokers,$nonsmoker->{nick};
+                       }
+                       $c->reply("I keep track of the following ppl: @nonsmokers");
                }
-               $c->reply("I keep track of the following ppl: @nonsmokers");
        }
-}
+};
 
 1;