From c2c337d5f1a426aa04b352dc43f7d5b6e5e96f8b Mon Sep 17 00:00:00 2001 From: Andreas Scherbaum Date: Wed, 13 Jun 2012 18:19:23 +0200 Subject: [PATCH] - add "lost" command --- docbot.conf | 1 + docbot.pl | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/docbot.conf b/docbot.conf index 0a5c940..ed2adb3 100644 --- a/docbot.conf +++ b/docbot.conf @@ -95,6 +95,7 @@ translations: help_general_line_2: 'Starte eine Suche mit zwei Fragezeichen, danach der Suchbegriff' help_general_line_3: 'Die folgenden Befehle stehen außerdem zur Verfügung' help_general_line_say: 'Nutze: ?sage #channel Nachricht' + help_general_line_lost: 'Nutze: ?lost' search_bad_parameters: 'Falsche Parameter' search_no_new_keywords: 'Alle Schlüsselwörter existieren bereits in der Datenbank' search_add_1_keyword: '1 Schlüsselwort erfolgreich hinzugefügt' diff --git a/docbot.pl b/docbot.pl index 91f268d..2c3a3b1 100755 --- a/docbot.pl +++ b/docbot.pl @@ -314,6 +314,7 @@ sub init_statistics { $main::statistics{'command_counter_join'} = 0; $main::statistics{'command_counter_leave'} = 0; $main::statistics{'command_access_denied'} = 0; + $main::statistics{'command_access_lost'} = 0; $main::statistics{'database_connects'} = 0; $main::statistics{'database_queries'} = 0; @@ -1271,6 +1272,8 @@ sub is_valid_admin_command { return 1; } elsif ($command eq 'leave') { return 1; + } elsif ($command eq 'lost') { + return 1; } return 0; @@ -1820,6 +1823,10 @@ sub handle_command { case('leave') { return handle_command_leave($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); } + case('lost') { + $main::statistics{'command_counter_lost'}++; + return handle_command_lost($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel); + } } @@ -1904,6 +1911,105 @@ sub handle_command_status { } +# handle_command_lost() +# +# command handler for the 'lost' 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_lost { + 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; + + + # 'lost' goes to the command channel only + if (lc($channel) eq lc($irc->nick_name())) { + return 'The "lost" command is only allowed in the command channel'; + } + if (lc($channel) ne lc(config_get_key2('bot', 'commandchannel'))) { + return 'The "lost" command is only allowed in the command channel'; + } + + + my $query = "SELECT url FROM docbot_url WHERE id NOT IN (SELECT kurl FROM docbot_key) ORDER BY id"; + my $st = $main::db->query($query); + 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 = "No unconnected urls in database"; + 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'); + 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 unconnected urls in database:" ); + foreach my $line (@lines) { + $irc->yield( privmsg => $channel, $line ); + } + } + + + return ''; +} + + # handle_command_wallchan() # # command handler for the 'wallchan' command @@ -2463,6 +2569,13 @@ sub handle_command_help { $irc->yield( privmsg => $replyto, $answer ); } + if ($string eq 'lost') { + my $answer = "Use ?lost"; + # translate message + $answer = translate_text_for_channel($replyto, 'help_general_line_lost', $answer); + $irc->yield( privmsg => $replyto, $answer ); + } + return ''; } -- 2.39.5