1 #**************************************************************************
2 # Copyright (C) 2009 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
20 package NDIRC::Dispatcher;
31 Moose::Exporter->setup_import_methods(
32 as_is => [ 'command' ]
39 isa => 'HashRef[Object]',
45 isa => 'HashRef[ArrayRef[Str]]',
51 isa => 'HashRef[Str]',
63 my $file = "NDIRC/Commands/$_.pm";
65 unless (my $return = do $file){
66 warn "couldn't parse $file: $@" if $@;
67 warn "couldn't do $file: $!" if $!;
68 warn "couldn't run $file" unless $return;
74 my ($c,$a,$class) = @_;
77 if (exists $c{alias}){
78 @aliases = @{$c{alias}} if ref $c{alias} eq 'ARRAY';
79 push @aliases, $c{alias} if ref $c{alias} eq '';
82 say "Command: (@aliases)";
85 my $co = $class->new_object(\%c);
86 $DISP->commands->{$a} = $co;
91 my ($self,$channel,$types) = @_;
93 $types = Set::Object->new(@{$types});
94 $self->channels->{lc $channel} = $types;
98 my ($self,$command,$channel) = @_;
99 $channel = lc $channel;
101 return 0 unless exists $self->commands->{$command};
102 return 0 unless exists $self->channels->{$channel};
104 $command = $self->commands->{$command};
105 return $self->channels->{$channel}->has($command->type);
109 my ($self,$label,$target) = @_;
110 $self->targets->{$label} = $target;
114 my ($self,$c,$command,$args) = @_;
116 return 0 unless exists $self->commands->{$command};
117 my $acl = $self->commands->{$command}->acl;
118 return 0 if $acl && !$c->check_user_roles($acl);
123 $self->commands->{$command}->execute($c,$args)
128 $c->reply($c->disp->commands->{$command}->help);
131 $c->reply("Something went wrong. If it is not temporary, please report it. '$_'");