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 },
);
# call the real maintenance function
maintenance();
},
+ execute_shutdown => \&execute_shutdown,
},
);
sub set_session_activity {
my $session = shift;
- $main::sessions{$session}{'last_activity'} = time();
+ if (defined($session)) {
+ $main::sessions{$session}{'last_activity'} = time();
+ }
}
return 1;
} elsif ($command eq 'lost') {
return 1;
+ } elsif ($command eq 'quit') {
+ return 1;
}
return 0;
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);
+ }
}
}
+# 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
# 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 );
}
$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 '';
}