From: Andreas Scherbaum Date: Sun, 12 Aug 2012 16:49:46 +0000 (+0200) Subject: - join channels which are in the configuration but not yet joined X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=176e52cc637e746319be5d890f25133ba01c8988;p=docbot.git - join channels which are in the configuration but not yet joined --- diff --git a/docbot.pl b/docbot.pl index 3f38c16..4bea67f 100755 --- a/docbot.pl +++ b/docbot.pl @@ -895,6 +895,59 @@ BEGIN { # none sub maintenance_1m { + # see if channels from configuration are not joined + if ((time() - $main::statistics{'docbot_start'}) > 60) { + foreach my $session (keys(%main::sessions)) { + my $irc = $main::sessions{$session}{'session'}; + if ($irc->connected and $main::sessions{$session}{'past_motd'} == 1 and $main::sessions{$session}{'logged_in'} == 1) { + + my @channels = config_get_keys1('channels'); + my @join_channels = (); + foreach my $channel (@channels) { + my $channel_session = config_get_key3('channels', $channel, 'session'); + my $channel_autojoin = config_get_key3('channels', $channel, 'autojoin'); + if (!defined($channel_autojoin)) { + $channel_autojoin = ''; + } + # autojoin is the default + my $channel_autojoin_result = 1; + given ($channel_autojoin) { + when(/^0$/) {$channel_autojoin_result = 0;} + when(/^n$/) {$channel_autojoin_result = 0;} + when(/^no$/) {$channel_autojoin_result = 0;} + when(/^1$/) {$channel_autojoin_result = 1;} + when(/^y$/) {$channel_autojoin_result = 1;} + when(/^yes$/) {$channel_autojoin_result = 1;} + } + if ($channel_session == $session and $channel_autojoin_result == 1) { + if (!session_for_channel($channel)) { + push(@join_channels, $channel); + } + } + } + if (scalar(@join_channels) > 0) { + print_msg("Channel list for session $session: " . join(", ", @join_channels), DEBUG); + # get stored heap pointer + my $heap = $main::sessions{$session}{'heap'}; + $heap = $$heap; + set_session_activity($session); + my %chan_data = %{$heap->{'chan_data_' . $session}}; + + foreach my $channel (@join_channels) { + my $channel_password = config_get_key3('channels', $channel, 'password'); + if (defined($channel_password) and length($channel_password) > 0) { + $irc->yield( join => $channel, $channel_password ); + } else { + $irc->yield( join => $channel ); + } + $chan_data{$channel} = {}; + } + $heap->{'chan_data_' . $session} = \%chan_data; + } + } + } + } + } @@ -3414,6 +3467,9 @@ sub on_connect { $main::sessions{$session}{'last_nick_change_attempt'} = time(); $main::sessions{$session}{'last_connect_time'} = time(); $main::sessions{$session}{'logged_in'} = 1; + # might need this pointers in the maintenance routines + $main::sessions{$session}{'kernel'} = \$kernel; + $main::sessions{$session}{'heap'} = \$heap; # get all channels for this session from config my @channels = config_get_keys1('channels'); diff --git a/todo.txt b/todo.txt index 6c59b6f..0e7fec9 100644 --- a/todo.txt +++ b/todo.txt @@ -7,7 +7,6 @@ - track each channel message and see, if the bot was mentioned - Log::Log4perl? - nickserv handling (passwords) -- verify channel list from time to time, autojoin missing channels @@ -29,3 +28,4 @@ - channel passwords OK - predefine channels in the configuration which are not autojoined OK - allow a password for the ?join command OK +- verify channel list from time to time, autojoin missing channels OK