]> git.somenet.org - irc/bugbot.git/blob - BotModules/ServicesLogin.bm
some old base
[irc/bugbot.git] / BotModules / ServicesLogin.bm
1 ################################
2 # Services Login Module        #
3 ################################
4
5 package BotModules::ServicesLogin;
6 use vars qw(@ISA);
7 @ISA = qw(BotModules);
8 1;
9
10 # This module allows your mozbot to login to Network Services such as
11 # Nickserv, K9, Q on Quakenet, or X on Undernet.
12 #
13 # It works in two ways:
14 #  * it logs in when the bot connects to IRC
15 #  * it reauthenticates at regular intervals, to assure that mozbot is
16 #    logged in at all times
17 #    
18 # This module was originally written by Mohamed Elzakzoki
19 # <mhtawfiq@earthlink.net>.
20
21
22 sub RegisterConfig {
23     my $self = shift;
24     $self->SUPER::RegisterConfig(@_);
25     $self->registerVariables(
26       # [ name, save?, settable? ]
27         ['loginCommand', 1, 1, undef],
28         ['servicesNick', 1, 1, undef],
29         ['delay', 1, 1, 900], # defaults to every 15 minutes
30     );
31 }
32
33 sub Schedule {
34     my $self = shift;
35     my ($event) = @_;
36     unless ($self->login($event)) {
37         $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.');
38     }
39     $self->schedule($event, \$self->{'delay'}, -1, 'login');
40     $self->SUPER::Schedule($event);
41 }
42
43 sub Help {
44     my $self = shift;
45     my ($event) = @_;
46     return {
47         '' => '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. See \'help setupServicesLogin\'.',
48         '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',
49     } if $self->isAdmin($event);
50     return {};
51 }
52
53 sub Scheduled {
54     my $self = shift;
55     my ($event, @data) = @_;
56     if ($data[0] eq 'login') {
57         $self->login($event);
58     } else {
59         $self->SUPER::Scheduled($event, @data);
60     }
61 }
62
63 sub Told {
64     my $self = shift;
65     my ($event, $message) = @_;
66     if ($message =~ /^\s*setup\s*services\s*login\s+(\S+)\s+(.+?)\s*$/osi) {
67         $self->{'servicesNick'} = $1;
68         $self->{'loginCommand'} = $2;
69                 $self->saveConfig();
70                 $self->say($event, "Ok, I'll contact $self->{'servicesNick'} regularly from now on.");
71                 $self->login($event);
72     } else {
73         return $self->SUPER::Told(@_);
74     }
75     return 0; # we've dealt with it, no need to do anything else.
76 }
77
78 sub login {
79     my $self = shift;
80     my ($event) = @_;
81     if (defined $self->{'servicesNick'} and
82         defined $self->{'loginCommand'}) {
83         local $event->{'target'} = $self->{'servicesNick'};
84         $self->privsay($event, $self->{'loginCommand'});
85         return 1;
86     }
87     return 0;
88 }