- implement "say" command
authorAndreas Scherbaum <andreas@scherbaum.biz>
Wed, 13 Jun 2012 10:24:36 +0000 (12:24 +0200)
committerAndreas Scherbaum <andreas@scherbaum.biz>
Wed, 13 Jun 2012 10:24:36 +0000 (12:24 +0200)
docbot.conf
docbot.pl

index 88e3eafee5aa0f5c5de27d0d7f78f6c21244e860..304c532deb3c1d22b7f34891bc857c6db1ca9bb2 100644 (file)
@@ -61,6 +61,7 @@ translations:
     config: 'konfiguriere'
     help: 'hilfe'
     search: 'suche'
+    say: 'sage'
     successfully_added_1_keyword: 'Ein Schlüsselwort hinzugefügt'
     successfully_added_1_url: 'Eine URL hinzugefügt'
     successfully_added_x_keyword: '% Schlüsselwörter hinzugefügt'
@@ -84,9 +85,11 @@ translations:
     more_results: 'weitere Ergebnisse'
     error_wallchan_command_parameter: 'Der "wallchan" Befehl erfordert einen Parameter'
     wallchan_command_message: 'Nachricht vom Operator'
+    error_say_command_parameter: 'Der "say" Befehl erfordert zwei Parameter'
     help_general_line_1: 'Allgemeine Hilfe'
     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'
     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'
index 539914b0813fa0d933696c160231a7c57f50f389..41ea9f3201862452d59b146057d10bd50221da3c 100755 (executable)
--- a/docbot.pl
+++ b/docbot.pl
@@ -310,6 +310,7 @@ sub init_statistics {
     $main::statistics{'command_counter_config'} = 0;
     $main::statistics{'command_counter_status'} = 0;
     $main::statistics{'command_counter_wallchan'} = 0;
+    $main::statistics{'command_counter_say'} = 0;
     $main::statistics{'command_access_denied'} = 0;
 
     $main::statistics{'database_connects'} = 0;
@@ -1262,6 +1263,8 @@ sub is_valid_admin_command {
         return 1;
     } elsif ($command eq 'wallchan') {
         return 1;
+    } elsif ($command eq 'say') {
+        return 1;
     }
 
     return 0;
@@ -1802,6 +1805,10 @@ sub handle_command {
             $main::statistics{'command_counter_wallchan'}++;
             return handle_command_wallchan($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel);
         }
+        case('say') {
+            $main::statistics{'command_counter_say'}++;
+            return handle_command_say($command, $string, $mode, $kernel, $heap, $who, $nick, $where, $msg, $sender, $irc, $channel);
+        }
     }
 
 
@@ -1871,6 +1878,7 @@ sub handle_command_status {
     push(@commands, 'forget: ' . $main::statistics{'command_counter_forget'});
     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, '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'} );
@@ -1942,6 +1950,79 @@ sub handle_command_wallchan {
 }
 
 
+# handle_command_say()
+#
+# command handler for the 'say' 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_say {
+    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 "say" command requires two parameter';
+        $answer = translate_text_for_channel($channel, 'error_say_command_parameter', $answer);
+        return $answer;
+    }
+
+
+    # remove spaces at beginning and end
+    $string =~ s/^[\s\t]+//gs;
+    $string =~ s/[\s\t]+$//gs;
+
+
+    my ($msg_channel, $message);
+    if ($string =~ /^([^\s]+)\s+(.+)$/) {
+        $msg_channel = $1;
+        $message = $2;
+    } else {
+        my $answer = 'The "say" command requires two parameter';
+        $answer = translate_text_for_channel($channel, 'error_say_command_parameter', $answer);
+        return $answer;
+    }
+
+    if (!is_a_channel($msg_channel)) {
+        my $answer = 'The "say" command requires two parameter';
+        $answer = translate_text_for_channel($channel, 'error_say_command_parameter', $answer);
+        return $answer;
+    }
+
+    print_msg("say: '$message' in '$msg_channel', by $nick", DEBUG);
+    send_to_commandchannel("say: '$message' in '$msg_channel', by $nick");
+
+
+    send_to_channel($msg_channel, $message);
+
+
+    return '';
+}
+
+
 # handle_command_search()
 #
 # command handler for the 'search' command
@@ -2171,7 +2252,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, wallchan';
+        $answer .= 'search, help, info, learn, forget, config, status, say, wallchan';
         $irc->yield( privmsg => $replyto, $answer );
     }
 
@@ -2183,6 +2264,13 @@ sub handle_command_help {
         $irc->yield( privmsg => $replyto, $answer );
     }
 
+    if ($string eq 'say') {
+        my $answer = "Use ?say #channel message";
+        # translate message
+        $answer = translate_text_for_channel($replyto, 'help_general_line_say', $answer);
+        $irc->yield( privmsg => $replyto, $answer );
+    }
+
     return '';
 }