gecko-dev/webtools/mozbot/BotModules/KeepAlive.bm

52 строки
1.4 KiB
Plaintext

################################
# KeepAlive Module #
################################
package BotModules::KeepAlive;
use vars qw(@ISA);
@ISA = qw(BotModules);
1;
# RegisterConfig - Called when initialised, should call registerVariables
sub RegisterConfig {
my $self = shift;
$self->SUPER::RegisterConfig(@_);
$self->registerVariables(
# [ name, save?, settable? ]
['delay', 1, 1, 20],
['string', 1, 1, 'ping'],
['target', 1, 1, '#spam'],
);
}
# Schedule - called when bot connects to a server, to install any schedulers
# use $self->schedule($event, $delay, $times, $data)
# where $times is 1 for a single event, -1 for recurring events,
# and a +ve number for an event that occurs that many times.
sub Schedule {
my $self = shift;
my ($event) = @_;
$self->schedule($event, \$self->{'delay'}, -1, 'keepalive');
$self->SUPER::Schedule($event);
}
sub Help {
my $self = shift;
my ($event) = @_;
return {
'' => 'This is a simple keep-alive module, it regularly sends text out. This has been known to help with network lag.',
} if $self->isAdmin($event);
return {};
}
sub Scheduled {
my $self = shift;
my ($event, @data) = @_;
if ($data[0] eq 'keepalive') {
local $event->{'target'} = $self->{'target'};
$self->say($event, $self->{'string'});
} else {
$self->SUPER::Scheduled($event, @data);
}
}