Bug 134617: Let users tell the bot to shut up. Adds a 'getMessageQueue' function to the bot API. Also fixes some unrelated minor issues in the developer documentation and makes a tiny optimisation in drainmsgqueue.

This commit is contained in:
ian%hixie.ch 2003-10-03 15:08:42 +00:00
Родитель 630d52d0b9
Коммит 11f8578752
3 изменённых файлов: 72 добавлений и 2 удалений

Просмотреть файл

@ -26,6 +26,7 @@ sub Help {
return {
'' => 'The module that provides the bot-wide services.',
'help' => 'Gives information about modules and commands. Syntax: help [<topic>]',
'shutup' => 'Tells the bot to stop talking to you. Syntax: shut up',
};
}
@ -83,6 +84,35 @@ sub Told {
}
$self->directSay($event, 'For help on a particular topic, type \'help <topic>\'. Note that some commands may be disabled in certain channels.');
}
} elsif ($message =~ /^\s*shut\s*up\s*$/osi) {
my $queue = $self->getMessageQueue();
my @messages = @$queue;
@$queue = ();
my $count = 0;
if ($event->{'channel'}) {
foreach my $message (@messages) {
if ($message->[0] eq $event->{'channel'} and
ref $message->[1] eq 'SCALAR' and
$message->[1] =~ m/^\Q$event->{'from'}\E:/osi) {
++$count;
} else {
push(@$queue, $message);
}
}
} else {
foreach my $message (@messages) {
if (lc $message->[0] eq lc $event->{'from'}) {
++$count;
} else {
push(@$queue, $message);
}
}
}
if ($count) {
$self->say($event, "$event->{'from'}: Dropped $count messages.");
} else {
$self->say($event, "$event->{'from'}: I wasn't talking to you.");
}
} else {
return $self->SUPER::Told(@_);
}

Просмотреть файл

@ -638,6 +638,31 @@ recommended.
$self->ctcpReply($event, 'VERSION', "mozbot $VERSION (@modulenames)");
*** getMessageQueue()
Returns a reference to the message queue. Manipulating this is
probably not a good idea. In particular, don't add anything to this
array, use the say(), directSay(), channelSay(), announce(),
tellAdmin(), etc, methods defined below.
Each item in this array is an array ref, consisting of three
subitems. The first subitem is a scalar with the name of the channel
or nick targetted, the second is the message to send, and the third
is a scalar equal to one of: 'msg', 'me', 'notice', 'ctcpSend',
'ctcpReply'. The second subitem is a scalar, except in the case of
'ctcpSend' messages, in which case it's an array ref consisting of
first the type of the CTCP message, and then the data.
Note: Don't use 'delete' to remove items from this array, since that
leaves undefs in the array, which will later cause a crash.
Example:
my $queue = $self->getMessageQueue();
foreach my $message (@$queue) {
++$count if $message->[0] eq $event->{'from'};
}
*** getHelpLine()
Returns the bot's help line.
@ -849,6 +874,9 @@ recommended.
This is what the 'help' command uses to pretty print its output.
This is basically the same as wordWrap() but it can change the order
of the input.
Example:
my @result = $self->prettyPrint($linelength, undef, 'Info: ', ' -- ', @infoItems);
@ -863,6 +891,9 @@ recommended.
Returns the result of all that.
This is basically the same as prettyPrint() but it doesn't change the
order of the input.
Example:
my @result = $self->wordWrap($linelength, undef, 'Info: ', ' ', split(/\s+/os, @lines);
@ -885,7 +916,7 @@ recommended.
Example:
$pattern = $self->sanitizeRegexp($pattern);
$data =~ /$pattern//gosi;
$data =~ /$pattern//gsi;
-- end --

Просмотреть файл

@ -883,7 +883,7 @@ sub drainmsgqueue {
$self->ctcp($type, $who, @$msg);
# $type = 'XXX';
} elsif ($do eq 'ctcpReply') {
{ local $" = ' '; &debug("->$who CTCP NOTICE $msg"); }
&debug("->$who CTCP NOTICE $msg");
$self->ctcp_reply($who, $msg);
# $type = 'XXX';
} else {
@ -1545,6 +1545,15 @@ sub getModule {
return &::getModule(@_);
}
# returns a reference to @msgqueue
# manipulating this is probably not a good idea. In particular,
# don't add anything to this array (use the appropriate methods
# instead, those that use &::sendmsg, below).
sub getMessageQueue {
my $self = shift;
return \@msgqueue;
}
# returns the value of $helpline
sub getHelpLine {
return $helpline;