1POE::Component::IRC::PlUusgeirn:C:oBnottrCiobmumtaePndOdE(P:3e:)rClomDpoocnuemnetn:t:aItRiCo:n:Plugin::BotCommand(3)
2
3
4

NAME

6       POE::Component::IRC::Plugin::BotCommand - A PoCo-IRC plugin which
7       handles commands issued to your bot
8

SYNOPSIS

10        use POE;
11        use POE::Component::Client::DNS;
12        use POE::Component::IRC;
13        use POE::Component::IRC::Plugin::BotCommand;
14
15        my @channels = ('#channel1', '#channel2');
16        my $dns = POE::Component::Client::DNS->spawn();
17        my $irc = POE::Component::IRC->spawn(
18            nick   => 'YourBot',
19            server => 'some.irc.server',
20        );
21
22        POE::Session->create(
23            package_states => [
24                main => [ qw(_start irc_001 irc_botcmd_slap irc_botcmd_lookup dns_response) ],
25            ],
26        );
27
28        $poe_kernel->run();
29
30        sub _start {
31            $irc->plugin_add('BotCommand', POE::Component::IRC::Plugin::BotCommand->new(
32                Commands => {
33                    slap   => 'Takes one argument: a nickname to slap.',
34                    lookup => 'Takes two arguments: a record type (optional), and a host.',
35                }
36            ));
37            $irc->yield(register => qw(001 botcmd_slap botcmd_lookup));
38            $irc->yield(connect => { });
39        }
40
41        # join some channels
42        sub irc_001 {
43            $irc->yield(join => $_) for @channels;
44            return;
45        }
46
47        # the good old slap
48        sub irc_botcmd_slap {
49            my $nick = (split /!/, $_[ARG0])[0];
50            my ($where, $arg) = @_[ARG1, ARG2];
51            $irc->yield(ctcp => $where, "ACTION slaps $arg");
52            return;
53        }
54
55        # non-blocking dns lookup
56        sub irc_botcmd_lookup {
57            my $nick = (split /!/, $_[ARG0])[0];
58            my ($where, $arg) = @_[ARG1, ARG2];
59            my ($type, $host) = $arg =~ /^(?:(\w+) )?(\S+)/;
60
61            my $res = $dns->resolve(
62                event => 'dns_response',
63                host => $host,
64                type => $type,
65                context => {
66                    where => $where,
67                    nick  => $nick,
68                },
69            );
70            $poe_kernel->yield(dns_response => $res) if $res;
71            return;
72        }
73
74        sub dns_response {
75            my $res = $_[ARG0];
76            my @answers = map { $_->rdatastr } $res->{response}->answer() if $res->{response};
77
78            $irc->yield(
79                'notice',
80                $res->{context}->{where},
81                $res->{context}->{nick} . (@answers
82                    ? ": @answers"
83                    : ': no answers for "' . $res->{host} . '"')
84            );
85
86            return;
87        }
88

DESCRIPTION

90       POE::Component::IRC::Plugin::BotCommand is a POE::Component::IRC
91       plugin. It provides you with a standard interface to define bot
92       commands and lets you know when they are issued. Commands are accepted
93       as channel or private messages.
94
95       The plugin will respond to the 'help' command by default, listing
96       available commands and information on how to use them. However, if you
97       add a help command yourself, that one will be used instead.
98

METHODS

100   "new"
101       'Commands', a hash reference, with your commands as keys, and usage
102       information as values. If the usage string contains newlines, the
103       component will send one message for each line.
104
105       Accepting commands
106
107       'In_channels', a boolean value indicating whether to accept commands in
108       channels. Default is true.
109
110       'In_private', a boolean value indicating whether to accept commands in
111       private. Default is true.
112
113       'Addressed', requires users to address the bot by name in order to
114       issue commands. Default is true.
115
116       'Prefix', a string which all commands must be prefixed with (except in
117       channels when 'Addressed' is true). Default is '!'. You can set it to
118       '' to allow bare commands.
119
120       Authorization
121
122       'Auth_sub', a subroutine reference which, if provided, will be called
123       for every command. The subroutine will be called in list context. If
124       the first value returned is true the command will be processed as
125       normal. If the value is false, then no events will be generated, and an
126       error message will possibly be sent back to the user. You can override
127       the default error message by returning an array reference of (zero or
128       more) strings. Each string will be sent as a message to the user.
129
130       The sub will get the following arguments:
131
132       1. The IRC component object
133       2. The nick!user@host of the user
134       3. The place where the command was issued (the nickname of the user if
135       it was in private)
136       4. The name of the command
137       5. The command argument string
138
139       'Ignore_unauthorized', if true, the plugin will ignore unauthorized
140       commands, rather than printing an error message upon receiving them.
141       This is only relevant if 'Auth_sub' is also supplied. Default is false.
142
143       Miscellaneous
144
145       'Ignore_unknown', if true, the plugin will ignore undefined commands,
146       rather than printing a help message upon receiving them. Default is
147       false.
148
149       'Method', how you want help messages to be delivered. Valid options are
150       'notice' (the default) and 'privmsg'.
151
152       'Eat', set to true to make the plugin hide "irc_public" events from
153       other plugins when they look like commands. Probably only useful when a
154       'Prefix' is defined. Default is false.
155
156       Returns a plugin object suitable for feeding to POE::Component::IRC's
157       "plugin_add" method.
158
159   "add"
160       Adds a new command. Takes two arguments, the name of the command, and a
161       string containing its usage information. Returns false if the command
162       has already been defined, true otherwise.
163
164   "remove"
165       Removes a command. Takes one argument, the name of the command. Returns
166       false if the command wasn't defined to begin with, true otherwise.
167
168   "list"
169       Takes no arguments. Returns a list of key/value pairs, the keys being
170       the command names and the values being the usage strings.
171

OUTPUT

173   "irc_botcmd_*"
174       You will receive an event like this for every valid command issued.
175       E.g. if 'slap' were a valid command, you would receive an
176       "irc_botcmd_slap" event every time someone issued that command. "ARG0"
177       is the nick!hostmask of the user who issued the command. "ARG1" is the
178       name of the channel in which the command was issued, or the sender's
179       nickname if this was a private message.  If the command was followed by
180       any arguments, "ARG2" will be a string containing them, otherwise it
181       will be undefined.
182

AUTHOR

184       Hinrik Oern Sigurd`sson, hinrik.sig@gmail.com
185
186
187
188perl v5.12.2                      201P0O-E1:1:-C0o5mponent::IRC::Plugin::BotCommand(3)
Impressum