]> git.somenet.org - irc/bugbot.git/blob - BotModules/Parrot.bm
some old base
[irc/bugbot.git] / BotModules / Parrot.bm
1 ################################
2 # Parrot Module                #
3 ################################
4
5 package BotModules::Parrot;
6 use vars qw(@ISA);
7 @ISA = qw(BotModules);
8 1;
9
10 sub Help {
11     my $self = shift;
12     my ($event) = @_;
13     if ($self->isAdmin($event)) {
14         return {
15             '' => 'This module allows you to make the bot do stuff.',
16             'say' => 'Makes the bot say something. The <target> can be a person or channel. Syntax: say <target> <text>',
17             'do' => 'Makes the bot do (/me) something. The <target> can be a person or channel. Syntax: do <target> <text>',
18             'invite' => 'Makes the bot invite (/invite) somebody to a channel. Syntax: invite <who> <channel>',
19             'announce' => 'Makes the bot announce something to every channel in which this module is enabled. Syntax: announce <text>',
20         };
21     } else { 
22         return $self->SUPER::Help($event);
23     }
24 }
25
26 sub Told {
27     my $self = shift;
28     my ($event, $message) = @_;
29     if ((($event->{'level'} == 1) and ($self->isAdmin($event))) or
30         (($event->{'level'} == 3) and ($event->{'God_channel_rights'}) and ($event->{'Parrot_channel'} eq $event->{'God_channel'}))) {
31         if ($message =~ /^\s*say\s+(\S+)\s+(.*)$/osi) {
32             local $event->{'target'} = $1;
33             $self->say($event, $2);
34         } elsif ($message =~ /^\s*do\s+(\S+)\s+(.*)$/osi) {
35             local $event->{'target'} = $1;
36             $self->emote($event, $2);
37         } elsif ($message =~ /^\s*announce\s+(.*)$/osi) {
38             $self->announce($event, $1);
39         } elsif ($message =~ /^\s* invite \s+
40                                     (\S+) \s+
41                        (?: (?:in|to|into) \s+
42                                (?:channel \s+)? )? 
43                                     (\S+) \s*$/osix) {
44             $self->invite($event, $1, $2);
45         } else {
46             return $self->SUPER::Told(@_);
47         }
48     } else {
49         if (($event->{'level'} == 1) and (($message =~ /^\s*say\s+(\S+)\s+(.*)$/osi) or ($message =~ /^\s*do\s+(\S+)\s+(.*)$/osi))) {
50             $event->{'God_channel'} = lc($1);
51             $event->{'Parrot_channel'} = lc($1);
52         }
53         my $result = $self->SUPER::Told(@_);
54         return $result < (3 * defined($event->{'Parrot_channel'})) ? 3 : $result;
55    
56         # Note: We go through some contortions here because if the parent
57         # returns 3 or more, some other module sets God_channel, and 
58         # the command is either not 'say' or 'do' (or the God_channel happens
59         # to be different to the channel we are looking at) then it is theoretically
60         # possible that God_channel_rights could be set, but not for the channel
61         # we care about. Or something..... ;-)
62
63     }
64     return 0; # we've dealt with it, no need to do anything else.
65 }
66