$main::statistics{'command_counter_status'} = 0;
$main::statistics{'command_counter_wallchan'} = 0;
$main::statistics{'command_counter_say'} = 0;
+ $main::statistics{'command_counter_join'} = 0;
+ $main::statistics{'command_counter_leave'} = 0;
$main::statistics{'command_access_denied'} = 0;
$main::statistics{'database_connects'} = 0;
return 1;
} elsif ($command eq 'say') {
return 1;
+ } elsif ($command eq 'join') {
+ return 1;
+ } elsif ($command eq 'leave') {
+ return 1;
}
return 0;
$main::statistics{'command_counter_say'}++;
return handle_command_say($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel);
}
+ case('join') {
+ return handle_command_join($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel);
+ }
+ case('leave') {
+ return handle_command_leave($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel);
+ }
}
push(@commands, 'config: ' . $main::statistics{'command_counter_config'});
push(@commands, 'wallchan: ' . $main::statistics{'command_counter_wallchan'});
push(@commands, 'say: ' . $main::statistics{'command_counter_say'});
+ push(@commands, 'join: ' . $main::statistics{'command_counter_join'});
+ push(@commands, 'leave: ' . $main::statistics{'command_counter_leave'});
push(@commands, 'status: ' . $main::statistics{'command_counter_status'});
$irc->yield( privmsg => $channel, 'Number of executed IRC commands: ' . join(", ", @commands) );
$irc->yield( privmsg => $channel, 'Number of denied IRC requests: ' . $main::statistics{'command_access_denied'} );
}
+# handle_command_join()
+#
+# command handler for the 'join' 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_join {
+ 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;
+
+
+ if (length($string) < 1) {
+ my $answer = 'The "join" command requires two parameters';
+ $answer = translate_text_for_channel($channel, 'error_join_command_parameter', $answer);
+ return $answer;
+ }
+
+
+ # remove spaces at beginning and end
+ $string =~ s/^[\s\t]+//gs;
+ $string =~ s/[\s\t]+$//gs;
+
+
+ my ($join_channel, $join_session);
+ if ($string =~ /^([^\s]+)\s+(\d+)$/) {
+ $join_channel = $1;
+ $join_session = $2;
+ } else {
+ my $answer = 'The "join" command requires two parameters';
+ $answer = translate_text_for_channel($channel, 'error_join_command_parameter', $answer);
+ return $answer;
+ }
+
+ if (!is_a_channel($join_channel)) {
+ my $answer = 'The "join" command requires two parameters';
+ $answer = translate_text_for_channel($channel, 'error_join_command_parameter', $answer);
+ return $answer;
+ }
+
+ if (!defined($main::sessions{$join_session})) {
+ my $answer = 'The "join" command requires two parameters';
+ $answer = translate_text_for_channel($channel, 'error_join_command_parameter', $answer);
+ return $answer;
+ }
+ my $join_irc = $main::sessions{$join_session}{'session'};
+
+
+ if (session_for_channel($join_channel)) {
+ my $answer = 'The bot already joined this channel';
+ $answer = translate_text_for_channel($channel, 'error_join_already_joined', $answer);
+ return $answer;
+ }
+
+
+ print_msg("join: '$join_channel' in session '$join_session', by $nick", DEBUG);
+ send_to_commandchannel("join: '$join_channel' in session '$join_session', by $nick");
+
+ $join_irc->yield( join => $join_channel );
+ $main::statistics{'command_counter_join'}++;
+
+
+ return '';
+}
+
+
+# handle_command_leave()
+#
+# command handler for the 'leave' 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_leave {
+ 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;
+
+
+ if (length($string) < 1) {
+ my $answer = 'The "leave" command requires one parameter';
+ $answer = translate_text_for_channel($channel, 'error_leave_command_parameter', $answer);
+ return $answer;
+ }
+
+
+ # remove spaces at beginning and end
+ $string =~ s/^[\s\t]+//gs;
+ $string =~ s/[\s\t]+$//gs;
+
+
+ my ($leave_channel);
+ if ($string =~ /^([^\s]+)/) {
+ $leave_channel = $1;
+ } else {
+ my $answer = 'The "leave" command requires one parameter';
+ $answer = translate_text_for_channel($channel, 'error_leave_command_parameter', $answer);
+ return $answer;
+ }
+
+ if (!is_a_channel($leave_channel)) {
+ my $answer = 'The "leave" command requires one parameter';
+ $answer = translate_text_for_channel($channel, 'error_leave_command_parameter', $answer);
+ return $answer;
+ }
+ my $leave_session = session_for_channel($leave_channel);
+
+ if (!$leave_session) {
+ my $answer = 'The bot is not in this channel';
+ $answer = translate_text_for_channel($channel, 'error_leave_not_joined', $answer);
+ return $answer;
+ }
+ my $leave_irc = $main::sessions{$leave_session}{'session'};
+
+
+ print_msg("leave: '$leave_channel' in session '$leave_session', by $nick", DEBUG);
+ send_to_commandchannel("leave: '$leave_channel' in session '$leave_session', by $nick");
+
+ $leave_irc->yield( part => $leave_channel );
+ $main::statistics{'command_counter_leave'}++;
+
+
+ return '';
+}
+
+
# handle_command_search()
#
# command handler for the 'search' command