Basic NickServ support. Tested with Q@cserve.quakenet.org, let me know if you have problems on other networks.

This commit is contained in:
ian%hixie.ch 2003-10-04 13:03:50 +00:00
parent 51a9513d72
commit 77e86a9bf0
2 changed files with 90 additions and 1 deletions

View File

@ -22,4 +22,5 @@ Contributor(s): Harrison Page <harrison@netscape.com>
Ian Hickson <mozbot@hixie.ch>
Zach Lipton <zach@zachlipton.com>
Jake Steenhagen <jake@acutex.net>
mental <xor@ivwnet.com>
mental <xor@ivwnet.com>
Mohamed Elzakzoki <mhtawfiq@yifan.net>

View File

@ -0,0 +1,88 @@
################################
# Services Login Module #
################################
package BotModules::ServicesLogin;
use vars qw(@ISA);
@ISA = qw(BotModules);
1;
# This module allows your mozbot to login to Network Services such as
# Nickserv, K9, Q on Quakenet, or X on Undernet.
#
# It works in two ways:
# * it logs in when the bot connects to IRC
# * it reauthenticates at regular intervals, to assure that mozbot is
# logged in at all times
#
# This module was originally written by Mohamed Elzakzoki
# <mhtawfiq@earthlink.net>.
sub RegisterConfig {
my $self = shift;
$self->SUPER::RegisterConfig(@_);
$self->registerVariables(
# [ name, save?, settable? ]
['loginCommand', 1, 1, undef],
['servicesNick', 1, 1, undef],
['delay', 1, 1, 900], # defaults to every 15 minutes
);
}
sub Schedule {
my $self = shift;
my ($event) = @_;
unless ($self->login($event)) {
$self->tellAdmin($event, 'To make me log in to a particular service, use the \'setupServicesLogin\' command, as in \'setupServicesLogin x@services.undernet.org login foobot p455w0rd\'. Type \'help setupServicesLogin\' for more information.');
}
$self->schedule($event, \$self->{'delay'}, -1, 'login');
$self->SUPER::Schedule($event);
}
sub Help {
my $self = shift;
my ($event) = @_;
return {
'' => 'The ServicesLogin module logs mozbot into services such as X on Undernet, Q on Quakenet, or NickServ or K9 on other networks. To setup the ServicesLogin command, use the setupServicesLogin command. Type \'help setupServicesLogin\' for more information.',
'setupServicesLogin' => 'The syntax of this command is \'setupServicesLogin <servicesNick> <loginCommand>\'. If the services nick is \'q@cserve.quakenet.org\', and the login command is \'auth mozbot mypass\', then you would type \'setupServicesLogin q@cserve.quakenet.org auth mozbot mypass\'. This will then cause mozbot to do: /msg q@cserve.quakenet.org auth mozbot mypass',
} if $self->isAdmin($event);
return {};
}
sub Scheduled {
my $self = shift;
my ($event, @data) = @_;
if ($data[0] eq 'login') {
$self->login($event);
} else {
$self->SUPER::Scheduled($event, @data);
}
}
sub Told {
my $self = shift;
my ($event, $message) = @_;
if ($message =~ /^\s*setup\s*services\s*login\s+(\S+)\s+(.+?)\s*$/osi) {
$self->{'servicesNick'} = $1;
$self->{'loginCommand'} = $2;
$self->saveConfig();
$self->say($event, "Ok, I'll contact $self->{'servicesNick'} regularly from now on.");
$self->login($event);
} else {
return $self->SUPER::Told(@_);
}
return 0; # we've dealt with it, no need to do anything else.
}
sub login {
my $self = shift;
my ($event) = @_;
if (defined $self->{'servicesNick'} and
defined $self->{'loginCommand'}) {
local $event->{'target'} = $self->{'servicesNick'};
$self->say($event, $self->{'loginCommand'});
return 1;
}
return 0;
}