]> ruin.nu Git - NDIRC.git/blob - Commands/Basic.pm
say and cmd commands for better bot control
[NDIRC.git] / Commands / Basic.pm
1 #**************************************************************************
2 #   Copyright (C) 2008 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
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.                                   *
8 #                                                                         *
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.                          *
13 #                                                                         *
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 #**************************************************************************/
19
20 package NDIRC::Commands::Basic;
21
22 use strict;
23 use warnings;
24
25 use Moose;
26 use MooseX::MethodAttributes;
27
28 sub commands
29         : Help(commands <command> | Gives help about all available commands or lists all commands available in the current channel)
30 {
31         my ($self, $c, $command) = @_;
32
33         unless($command){
34                 my @commands;
35                 for (sort keys %{$c->disp->commands}){
36                         next unless $c->disp->has_command($_,$c->channel);
37                         my $acl = $c->disp->commands->{$_}->acl;
38                         next if $acl && !$c->check_user_roles(@$acl);
39         
40                         push @commands,$_;
41                 }
42                 $c->reply(join ', ', @commands);
43         }elsif (exists $c->disp->commands->{$command}){
44                 for (@{$c->disp->commands->{$command}->help}){
45                         $c->reply($_);
46                 }
47         }
48
49 }
50
51 sub help
52         : Help(Prints basic help)
53         : Type(help)
54 {
55         my ($self, $c, $command) = @_;
56
57         $c->reply("Use .commands <command> to show help about a specific command. "
58                 . "Use .commands to list the diffenrent commands you have access to in this channel. "
59                 . "Instead of . you can use ! to get reply in pm or ~ to get reply in channel.");
60 }
61
62 sub say
63         : Help(.say target message | sends message to target)
64         : Type(pm)
65         : ACL(irc_say)
66 {
67         my ($self, $c, $msg) = @_;
68         my ($target,$message) = $msg =~ /^(\S+)\s+(.+)$/ or die 'ARGS';
69
70         $c->message(privmsg => $target => $message );
71 }
72
73 sub cmd
74         : Help(.run command args | run a given command)
75         : Type(pm)
76         : ACL(irc_cmd)
77 {
78         my ($self, $c, $msg) = @_;
79
80         $c->command(split /\s/, $msg);
81 }
82
83 1;
84