]> ruin.nu Git - NDIRC.git/blob - Commands/Basic.pm
672c7a9958c7a84940ca6bb420fb957260372f02
[NDIRC.git] / Commands / Basic.pm
1 #**************************************************************************
2 #   Copyright (C) 2009 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 use strict;
21 use warnings;
22
23 use MooseX::Declare;
24 use NDIRC::Dispatcher;
25
26 command commands => {
27         help => q(commands <command> | Gives help about all available commands or lists all commands available in the current channel),
28 }, class extends NDIRC::Command {
29         method execute ($c,$command) {
30                 unless($command){
31                         my @commands;
32                         for (sort keys %{$c->disp->commands}){
33                                 next unless $c->disp->has_command($_,$c->channel);
34                                 my $acl = $c->disp->commands->{$_}->acl;
35                                 next if $acl && !$c->check_user_roles($acl);
36
37                                 push @commands,$_;
38                         }
39                         $c->reply(join ', ', @commands);
40                 }elsif (exists $c->disp->commands->{$command}){
41                         $c->reply($c->disp->commands->{$command}->help);
42                 }
43         }
44 };
45
46 command help => {
47         help => q(Prints basic help),
48         type => 'help',
49 }, class extends NDIRC::Command {
50         method execute ($c,$command) {
51
52                 $c->reply("Use .commands <command> to show help about a specific command. "
53                         . "Use .commands to list the diffenrent commands you have access to in this channel. "
54                         . "Instead of . you can use ! to get reply in pm or ~ to get reply in channel.");
55         }
56 };
57
58 command say => {
59         help => q(.say target message | sends message to target),
60         type => q(pm),
61         acl => q(irc_say),
62 }, class extends NDIRC::Command {
63         method execute ($c,$msg) {
64                 my ($target,$message) = $msg =~ /^(\S+)\s+(.+)$/ or die 'ARGS';
65
66                 $c->message(privmsg => $target => $message );
67         }
68 };
69
70 command cmd => {
71         help => q(.cmd command args | run a given irc command),
72         type => q(pm),
73         acl  => q(irc_cmd),
74 }, class extends NDIRC::Command {
75         method execute ($c,$msg) {
76
77                 $c->command(split /\s/, $msg);
78         }
79 };
80
81 command anon => {
82         help => q(syntax: .anon nick message),
83         type => q(anon),
84         acl => q(irc_anon),
85 }, class extends NDIRC::Command {
86         method execute($c,$msg) {
87                 my ($target,$mess) = $msg =~ /^(\S+) (.*)$/ or die 'ARGS';
88
89                 $c->message(privmsg => $target, "<b>$mess</b> <c04>(reply with /msg "
90                         .$c->channel.")</c>");
91                 $c->message(privmsg => $c->channel, "<c03>$target << $mess</c>");
92         }
93 };
94
95
96 1;
97