From: Andreas Scherbaum Date: Thu, 2 Aug 2012 21:02:55 +0000 (+0200) Subject: - add "quit" command X-Git-Url: http://git.postgresql.org/gitweb/static/developers.postgresql.org?a=commitdiff_plain;h=a8680a9ef155f98f840ac73de18d113351d8adde;p=docbot.git - add "quit" command --- diff --git a/docbot.conf b/docbot.conf index ed25758..0d684d3 100644 --- a/docbot.conf +++ b/docbot.conf @@ -101,6 +101,7 @@ translations: help_general_line_lost: 'Nutze: ?lost' help_general_line_url: 'Nutze: ?url ' help_general_line_key: 'Nutze: ?key ' + help_general_line_quit: 'Nutze: ?quit' lost_only_in_commandchannel: 'Der "lost" Befehl ist nur im Adminchannel erlaubt' url_only_in_commandchannel: 'Der "url" Befehl ist nur im Adminchannel erlaubt' key_only_in_commandchannel: 'Der "key" Befehl ist nur im Adminchannel erlaubt' diff --git a/docbot.pl b/docbot.pl index e63dd57..33f1e7a 100755 --- a/docbot.pl +++ b/docbot.pl @@ -206,6 +206,7 @@ foreach my $session (keys(%main::sessions)) { irc_plugin_add => \&on_irc_plugin_add, irc_raw => \&on_irc_raw, irc_raw_out => \&on_irc_raw_out, + execute_shutdown => \&execute_shutdown, }, heap => { irc => $irc }, ); @@ -282,6 +283,7 @@ POE::Session->create( # call the real maintenance function maintenance(); }, + execute_shutdown => \&execute_shutdown, }, ); @@ -1172,7 +1174,9 @@ sub execute_shutdown { sub set_session_activity { my $session = shift; - $main::sessions{$session}{'last_activity'} = time(); + if (defined($session)) { + $main::sessions{$session}{'last_activity'} = time(); + } } @@ -1359,6 +1363,8 @@ sub is_valid_admin_command { return 1; } elsif ($command eq 'lost') { return 1; + } elsif ($command eq 'quit') { + return 1; } return 0; @@ -1918,6 +1924,9 @@ sub handle_command { when('key') { return handle_command_key($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } + when('quit') { + return handle_command_quit($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); + } } @@ -1925,6 +1934,71 @@ sub handle_command { } +# handle_command_quit() +# +# command handler for the 'quit' command +# +# parameter: +# - the command (lower case) +# - the parameter string (may be empty) +# - the command mode (admin/operator/user) +# - POE kernel +# - POE heap +# - the full who of the message sender, including the nick name +# - the nick name of the message sender +# - the full origin of the message +# - the message itself +# - POE sender +# - session irc handle +# - the channel name +# return: +# - text to send back to the sender +sub handle_command_quit { + my $command = shift; + my $string = shift; + my $mode = shift; + my $kernel = shift; + my $heap = shift; + my $who = shift; + my $nick = shift; + my $where = shift; + my $msg = shift; + my $sender = shift; + my $irc = shift; + my $channel = shift; + + + # 'quit' goes to the command channel only + if (lc($channel) eq lc($irc->nick_name())) { + return 'The "quit" command is only allowed in the command channel'; + } + if (lc($channel) ne lc(config_get_key2('bot', 'commandchannel'))) { + return 'The "quit" command is only allowed in the command channel'; + } + + + send_to_commandchannel('Received "quit" command from: ' . $nick); + print_msg('Received "quit" command from: ' . $nick, INFO); + + + # loop through all sessions and send a QUIT to the irc server + foreach my $tmp_session (keys(%main::sessions)) { + my $tmp_irc = $main::sessions{$tmp_session}{'session'}; + if ($tmp_irc->connected) { + # this forces the current session to quit from irc, resulting in an "on_error" event + $tmp_irc->yield( quit => "Quit" ); + } + } + + # have to shutdown here, else Component::IRC Component::IRC::Plugin::Connector will reconnect + $poe_kernel->delay_add( execute_shutdown => 5 ); + $shutdown = 1; + + + return ''; +} + + # handle_command_status() # # command handler for the 'status' command @@ -2901,7 +2975,7 @@ sub handle_command_help { # translate message $answer = translate_text_for_channel($replyto, 'help_general_line_3', $answer); $answer .= ': '; - $answer .= 'search, help, info, learn, forget, config, status, say, wallchan, lost, url, key, join, leave'; + $answer .= 'search, help, info, learn, forget, config, status, say, wallchan, lost, url, key, join, leave, quit'; $irc->yield( privmsg => $replyto, $answer ); } @@ -2941,6 +3015,13 @@ sub handle_command_help { $irc->yield( privmsg => $replyto, $answer ); } + if ($string eq 'quit') { + my $answer = "Use ?quit"; + # translate message + $answer = translate_text_for_channel($replyto, 'help_general_line_quit', $answer); + $irc->yield( privmsg => $replyto, $answer ); + } + return ''; }