]> ruin.nu Git - NDIRC.git/commitdiff
Converted Quotes
authorMichael Andreen <harv@ruin.nu>
Sat, 5 Dec 2009 23:08:30 +0000 (00:08 +0100)
committerMichael Andreen <harv@ruin.nu>
Sat, 5 Dec 2009 23:08:30 +0000 (00:08 +0100)
Commands/Quotes.pm

index 608832f9d38094c40173c8d92c0800105acf7d10..42fbc80ca8c3680b6fba24ab8e60ecbb6a405b3e 100644 (file)
 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 #**************************************************************************/
 
 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 #**************************************************************************/
 
-package NDIRC::Commands::Quotes;
-
 use strict;
 use warnings;
 use feature ':5.10';
 
 use strict;
 use warnings;
 use feature ':5.10';
 
-use Moose;
-use MooseX::MethodAttributes;
+use MooseX::Declare;
+use NDIRC::Dispatcher;
 
 use Tie::File;
 use File::Temp ();
 
 use Tie::File;
 use File::Temp ();
@@ -32,94 +30,98 @@ use File::Temp ();
 tie my @FILE, 'Tie::File', "quote.txt";
 tie my @OLDFILE, 'Tie::File',"oldquotes.txt" or die "test";
 
 tie my @FILE, 'Tie::File', "quote.txt";
 tie my @OLDFILE, 'Tie::File',"oldquotes.txt" or die "test";
 
-sub quote
-       : Help(syntax .quote [number] | if number isn't given, then a random quote is used)
-       : Alias(lastquote)
-{
-       my ($self,$c,$msg) = @_;
-       my ($n) = $msg =~ /(\d+)/;
-
-       $n = $n-1 if defined $n;
-       $n //= int(rand($#FILE));
-       $n = $#FILE if $self->name eq 'lastquote';
-
-       my $text = $FILE[$n];
-       $text =~ s/(.*?)[\r\n]*$/$1/;
-       $n++;
-       my $num = $#FILE+1;
-       $c->reply("Quote <b>$n</b> of <b>$num</b>: $text");
-}
+command quote => {
+       help => q(syntax .quote [number] | if number isn't given, then a random quote is used),
+       alias => q(lastquote),
+}, class extends NDIRC::Command {
+       method execute($c,$msg) {
+               my ($n) = $msg =~ /(\d+)/;
 
 
-sub addquote
-       : Help(syntax .addquote quote)
-{
-       my ($self,$c,$quote) = @_;
+               $n = $n-1 if defined $n;
+               $n //= int(rand($#FILE));
+               $n = $#FILE if $self->name eq 'lastquote';
 
 
-       die 'ARGS' unless $quote;
+               my $text = $FILE[$n];
+               $text =~ s/(.*?)[\r\n]*$/$1/;
+               $n++;
+               my $num = $#FILE+1;
+               $c->reply("Quote <b>$n</b> of <b>$num</b>: $text");
+       }
+};
 
 
-       push @FILE, $quote;
-       my $num = $#FILE+1;
-       $c->reply("Quote <b>$num</b> added");
-}
+command addquote => {
+       help => q(syntax .addquote quote),
+}, class extends NDIRC::Command {
+       method execute($c,$quote) {
 
 
-sub findquote
-       : Help(syntax .findquote pattern | findqre lets you use a regex pattern)
-       : Alias(findqre)
-{
-       my ($self,$c,$pattern) = @_;
-       die 'ARGS' unless $pattern;
+               die 'ARGS' unless $quote;
 
 
-       my $matcher;
-       if ($self->name eq 'findqre'){
-               if (defined (eval 'm/$pattern/ix')){
-                       $matcher = 'm/$pattern/ix';
-               }else {
-                       $c->reply("bad regexp");
-                       return;
-               }
-       }else{
-               $matcher = '(index uc($_), uc($pattern)) != -1';
+               push @FILE, $quote;
+               my $num = $#FILE+1;
+               $c->reply("Quote <b>$num</b> added");
        }
        }
-       my $file = new File::Temp( SUFFIX => '.txt' );
-       my $n = 1;
-       my $match = 0;
-       for (@FILE){
-               chomp;
-               if (eval $matcher){
-                       $match = 1;
-                       print $file "$n: $_\n";
+};
+
+command findquote => {
+       help => q(syntax .findquote pattern | findqre lets you use a regex pattern),
+       alias => q(findqre),
+}, class extends NDIRC::Command {
+       method execute($c,$pattern) {
+               die 'ARGS' unless $pattern;
+
+               my $matcher;
+               if ($self->name eq 'findqre'){
+                       if (defined (eval 'm/$pattern/ix')){
+                               $matcher = 'm/$pattern/ix';
+                       }else {
+                               $c->reply("bad regexp");
+                               return;
+                       }
+               }else{
+                       $matcher = '(index uc($_), uc($pattern)) != -1';
+               }
+               my $file = new File::Temp( SUFFIX => '.txt' );
+               my $n = 1;
+               my $match = 0;
+               for (@FILE){
+                       chomp;
+                       if (eval $matcher){
+                               $match = 1;
+                               print $file "$n: $_\n";
+                       }
+                       $n++;
+               }
+               if ($match){
+                       $file->flush;
+                       $c->command(dcc => $c->nick => SEND => $file);
+               }else{
+                       $c->reply("No quotes matching <b>$pattern.</b>");
                }
                }
-               $n++;
-       }
-       if ($match){
-               $file->flush;
-               $c->command(dcc => $c->nick => SEND => $file);
-       }else{
-               $c->reply("No quotes matching <b>$pattern.</b>");
        }
        }
-}
-
-sub delquote
-       : Help(syntax: .delquote number)
-       : ACL(irc_delquote)
-{
-       my ($self,$c,$msg) = @_;
-       my ($n) = $msg =~ /(\d+)/ or die 'ARGS';
-       $n = $n-1;
-       if (exists $FILE[$n]){
-               my ($uid,$username) = $c->model->selectrow_array(q{
+};
+
+command delquote => {
+       help => q(syntax: .delquote number),
+       acl => q(irc_delquote),
+}, class extends NDIRC::Command {
+       method execute($c,$msg) {
+               my ($n) = $msg =~ /(\d+)/ or die 'ARGS';
+               $n = $n-1;
+               if (exists $FILE[$n]){
+                       my ($uid,$username) = $c->model->selectrow_array(q{
 SELECT uid,username FROM users where uid = ?
 SELECT uid,username FROM users where uid = ?
-                       },undef,$c->uid);
-
-               my $text = $FILE[$n];
-               push @OLDFILE,"Removed by $username ($uid): $text";
-               splice @FILE,$n,1;
-               $n++;
-               my $num = $#FILE+1;
-               $c->reply("Quote <b>$n</b> {$text} removed, number of quotes now: <b>$num</b>");
-       }else{
-               $c->reply("No such quote.");
+                               },undef,$c->uid);
+
+                       my $text = $FILE[$n];
+                       push @OLDFILE,"Removed by $username ($uid): $text";
+                       splice @FILE,$n,1;
+                       $n++;
+                       my $num = $#FILE+1;
+                       $c->reply("Quote <b>$n</b> {$text} removed, number of quotes now: <b>$num</b>");
+               }else{
+                       $c->reply("No such quote.");
+               }
        }
        }
-}
+};
 
 1;
 
 1;