]> ruin.nu Git - NDIRC.git/blobdiff - Commands/Basic.pm
New infrastructure for commands with basic commands converted
[NDIRC.git] / Commands / Basic.pm
index fd30f0f728ec4b5aad9302e591166eadd6073211..1249f201586bc6155be184807f3ddee1697196bb 100644 (file)
@@ -1,5 +1,5 @@
 #**************************************************************************
-#   Copyright (C) 2008 by Michael Andreen <harvATruinDOTnu>               *
+#   Copyright (C) 2009 by Michael Andreen <harvATruinDOTnu>               *
 #                                                                         *
 #   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  *
 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 #**************************************************************************/
 
-package NDIRC::Commands::Basic;
-
 use strict;
 use warnings;
 
-use Moose;
-use MooseX::MethodAttributes;
+use MooseX::Declare;
+use NDIRC::Dispatcher;
 
-sub commands
-       : Help(commands <command> | Gives help about all available commands or lists all commands available in the current channel)
-{
-       my ($self, $c, $command) = @_;
+command commands => {
+       help => q(commands <command> | Gives help about all available commands or lists all commands available in the current channel),
+}, class extends NDIRC::Command {
+       method execute ($c,$command) {
+               unless($command){
+                       my @commands;
+                       for (sort keys %{$c->disp->commands}){
+                               next unless $c->disp->has_command($_,$c->channel);
+                               my $acl = $c->disp->commands->{$_}->acl;
+                               next if $acl && !$c->check_user_roles($acl);
 
-       unless($command){
-               my @commands;
-               for (sort keys %{$c->disp->commands}){
-                       next unless $c->disp->has_command($_,$c->channel);
-                       my $acl = $c->disp->commands->{$_}->acl;
-                       next if $acl && !$c->check_user_roles(@$acl);
-       
-                       push @commands,$_;
-               }
-               $c->reply(join ', ', @commands);
-       }elsif (exists $c->disp->commands->{$command}){
-               for (@{$c->disp->commands->{$command}->help}){
-                       $c->reply($_);
+                               push @commands,$_;
+                       }
+                       $c->reply(join ', ', @commands);
+               }elsif (exists $c->disp->commands->{$command}){
+                       for (@{$c->disp->commands->{$command}->help}){
+                               $c->reply($_);
+                       }
                }
        }
+};
 
-}
-
-sub help
-       : Help(Prints basic help)
-       : Type(help)
-{
-       my ($self, $c, $command) = @_;
+command help => {
+       help => q(Prints basic help),
+       type => 'help',
+}, class extends NDIRC::Command {
+       method execute ($c,$command) {
 
-       $c->reply("Use .commands <command> to show help about a specific command. "
-               . "Use .commands to list the diffenrent commands you have access to in this channel. "
-               . "Instead of . you can use ! to get reply in pm or ~ to get reply in channel.");
-}
+               $c->reply("Use .commands <command> to show help about a specific command. "
+                       . "Use .commands to list the diffenrent commands you have access to in this channel. "
+                       . "Instead of . you can use ! to get reply in pm or ~ to get reply in channel.");
+       }
+};
 
-sub say
-       : Help(.say target message | sends message to target)
-       : Type(pm)
-       : ACL(irc_say)
-{
-       my ($self, $c, $msg) = @_;
-       my ($target,$message) = $msg =~ /^(\S+)\s+(.+)$/ or die 'ARGS';
+command say => {
+       help => q(.say target message | sends message to target),
+       type => q(pm),
+       acl => q(irc_say),
+}, class extends NDIRC::Command {
+       method execute ($c,$msg) {
+               my ($target,$message) = $msg =~ /^(\S+)\s+(.+)$/ or die 'ARGS';
 
-       $c->message(privmsg => $target => $message );
-}
+               $c->message(privmsg => $target => $message );
+       }
+};
 
-sub cmd
-       : Help(.run command args | run a given command)
-       : Type(pm)
-       : ACL(irc_cmd)
-{
-       my ($self, $c, $msg) = @_;
+command cmd => {
+       help => q(.cmd command args | run a given irc command),
+       type => q(pm),
+       acl  => q(irc_cmd),
+}, class extends NDIRC::Command {
+       method execute ($c,$msg) {
 
-       $c->command(split /\s/, $msg);
-}
+               $c->command(split /\s/, $msg);
+       }
+};
 
 1;