$main::statistics{'command_counter_leave'} = 0;
$main::statistics{'command_access_denied'} = 0;
$main::statistics{'command_access_lost'} = 0;
+ $main::statistics{'command_access_url'} = 0;
+ $main::statistics{'command_access_key'} = 0;
$main::statistics{'database_connects'} = 0;
$main::statistics{'database_queries'} = 0;
return 1;
} elsif ($command eq 'forget') {
return 1;
+ } elsif ($command eq 'url') {
+ return 1;
+ } elsif ($command eq 'key') {
+ return 1;
}
return 0;
$main::statistics{'command_counter_lost'}++;
return handle_command_lost($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel);
}
+ case('url') {
+ return handle_command_url($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel);
+ }
+ case('key') {
+ return handle_command_key($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel);
+ }
}
push(@commands, 'leave: ' . $main::statistics{'command_counter_leave'});
push(@commands, 'status: ' . $main::statistics{'command_counter_status'});
push(@commands, 'lost: ' . $main::statistics{'command_counter_lost'});
+ push(@commands, 'url: ' . $main::statistics{'command_counter_url'});
+ push(@commands, 'key: ' . $main::statistics{'command_counter_key'});
$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_url()
+#
+# command handler for the 'url' 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_url {
+ 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;
+
+
+ # 'url' goes to the command channel only
+ if (lc($channel) eq lc($irc->nick_name())) {
+ my $answer = 'The "url" command is only allowed in the command channel';
+ # translate error message
+ $answer = translate_text_for_channel($channel, 'url_only_in_commandchannel', $answer);
+ return $answer;
+ }
+ if (lc($channel) ne lc(config_get_key2('bot', 'commandchannel'))) {
+ my $answer = 'The "url" command is only allowed in the command channel';
+ # translate error message
+ $answer = translate_text_for_channel($channel, 'url_only_in_commandchannel', $answer);
+ return $answer;
+ }
+
+
+ if (length($string) < 1) {
+ my $answer = 'The "url" command requires a parameter';
+ $answer = translate_text_for_channel($channel, 'error_url_command_parameter', $answer);
+ return $answer;
+ }
+
+ print_msg("url: '$string', by $nick", DEBUG);
+ send_to_commandchannel("url: '$string', by $nick");
+ $main::statistics{'command_counter_url'}++;
+
+
+ my $query = "SELECT key FROM docbot_key WHERE kurl IN (SELECT id FROM docbot_url WHERE url = ?::TEXT) ORDER BY key";
+ my $st = $main::db->query($query, $string);
+ if (!defined($st)) {
+ my $answer = "Database error";
+ # translate error message
+ $answer = translate_text_for_channel($channel, 'database_error', $answer);
+ return $answer;
+ }
+ my $rows = $st->rows;
+ if ($rows == 0) {
+ my $answer = "URL not in database or no keys connected";
+ return $answer;
+ }
+
+
+ # fetch the result
+ my @rows = ();
+ while (my @row = $st->fetchrow_array) {
+ push(@rows, $row[0]);
+ }
+
+
+ my @lines = ();
+ my $maxresults = config_get_key2('search', 'maxresults');
+ if ($maxresults == 0) {
+ # set a reasonable high default
+ $maxresults = 50;
+ }
+ if ($maxresults < 20) {
+ $maxresults = 20;
+ }
+ my $maxwrap = config_get_key2('search', 'maxwrap');
+ if ($maxwrap > 1 and $maxwrap < 5) {
+ # set a more reasonable default for number of keys
+ $maxwrap = 5;
+ }
+ for (my $a = 1; $a <= int($maxresults / $maxwrap); $a++) {
+ my @line = ();
+ for (my $b = 1; $b <= $maxwrap; $b++) {
+ if (defined($rows[0])) {
+ push(@line, shift(@rows));
+ }
+ }
+ if (scalar(@line) > 0) {
+ push(@lines, join(" :: ", @line));
+ }
+ }
+
+ if (scalar(@lines) > 0) {
+ $irc->yield( privmsg => $channel, "$rows keys in database for url '$string':" );
+ foreach my $line (@lines) {
+ $irc->yield( privmsg => $channel, $line );
+ }
+ }
+
+
+ return '';
+}
+
+
+# handle_command_key()
+#
+# command handler for the 'key' 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_key {
+ 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;
+
+
+ # 'key' goes to the command channel only
+ if (lc($channel) eq lc($irc->nick_name())) {
+ my $answer = 'The "key" command is only allowed in the command channel';
+ # translate error message
+ $answer = translate_text_for_channel($channel, 'key_only_in_commandchannel', $answer);
+ return $answer;
+ }
+ if (lc($channel) ne lc(config_get_key2('bot', 'commandchannel'))) {
+ my $answer = 'The "key" command is only allowed in the command channel';
+ # translate error message
+ $answer = translate_text_for_channel($channel, 'key_only_in_commandchannel', $answer);
+ return $answer;
+ }
+
+
+ if (length($string) < 1) {
+ my $answer = 'The "key" command requires a parameter';
+ $answer = translate_text_for_channel($channel, 'error_key_command_parameter', $answer);
+ return $answer;
+ }
+
+ print_msg("key: '$string', by $nick", DEBUG);
+ send_to_commandchannel("key: '$string', by $nick");
+ $main::statistics{'command_counter_key'}++;
+
+
+ my $query = "SELECT url FROM docbot_url WHERE id IN (SELECT kurl FROM docbot_key WHERE key = ?::TEXT) ORDER BY url";
+ my $st = $main::db->query($query, $string);
+ if (!defined($st)) {
+ my $answer = "Database error";
+ # translate error message
+ $answer = translate_text_for_channel($channel, 'database_error', $answer);
+ return $answer;
+ }
+ my $rows = $st->rows;
+ if ($rows == 0) {
+ my $answer = "Key not in database or no urls connected";
+ return $answer;
+ }
+
+
+ # fetch the result
+ my @rows = ();
+ while (my @row = $st->fetchrow_array) {
+ push(@rows, $row[0]);
+ }
+
+
+ my @lines = ();
+ my $maxresults = config_get_key2('search', 'maxresults');
+ if ($maxresults == 0) {
+ # set a reasonable high default
+ $maxresults = 50;
+ }
+ if ($maxresults < 20) {
+ $maxresults = 20;
+ }
+ my $maxwrap = config_get_key2('search', 'maxwrap');
+ if ($maxwrap > 1 and $maxwrap < 5) {
+ # set a more reasonable default for number of keys
+ $maxwrap = 5;
+ }
+ for (my $a = 1; $a <= int($maxresults / $maxwrap); $a++) {
+ my @line = ();
+ for (my $b = 1; $b <= $maxwrap; $b++) {
+ if (defined($rows[0])) {
+ push(@line, shift(@rows));
+ }
+ }
+ if (scalar(@line) > 0) {
+ push(@lines, join(" :: ", @line));
+ }
+ }
+
+ if (scalar(@lines) > 0) {
+ $irc->yield( privmsg => $channel, "$rows urls in database for key '$string':" );
+ foreach my $line (@lines) {
+ $irc->yield( privmsg => $channel, $line );
+ }
+ }
+
+
+ return '';
+}
+
+
# handle_command_wallchan()
#
# command handler for the 'wallchan' command
$irc->yield( privmsg => $replyto, $answer );
}
+ if ($string eq 'url') {
+ my $answer = "Use ?url <url>";
+ # translate message
+ $answer = translate_text_for_channel($replyto, 'help_general_line_url', $answer);
+ $irc->yield( privmsg => $replyto, $answer );
+ }
+
+ if ($string eq 'url') {
+ my $answer = "Use ?key <key>";
+ # translate message
+ $answer = translate_text_for_channel($replyto, 'help_general_line_key', $answer);
+ $irc->yield( privmsg => $replyto, $answer );
+ }
+
return '';
}