- implement passwords for ?join command
authorAndreas Scherbaum <andreas@scherbaum.biz>
Sat, 11 Aug 2012 23:46:38 +0000 (01:46 +0200)
committerAndreas Scherbaum <andreas@scherbaum.biz>
Sat, 11 Aug 2012 23:46:38 +0000 (01:46 +0200)
- make parameter list for ?join more flexible

docbot.pl
docbot.translations
todo.txt

index 33787f6a681081ff7caa0c36a13030037d801d09..2db6f2285bc67360c1ad1fb352ee709ed21f97c7 100755 (executable)
--- a/docbot.pl
+++ b/docbot.pl
@@ -203,6 +203,7 @@ foreach my $session (keys(%main::sessions)) {
             irc_quit         => \&on_quit,
             irc_kick         => \&on_kick,
             irc_353          => \&on_names,
+            irc_475          => \&on_cannot_join_channel,
             irc_notice       => \&on_irc_notice,
             irc_ping         => \&on_ping,
             autoping         => \&do_autoping,
@@ -2665,21 +2666,27 @@ sub handle_command_join {
     $string =~ s/[\s\t]+$//gs;
 
 
-    my ($join_channel, $join_session, $join_language);
+    my ($join_channel, $join_session, $join_language, $join_password, $join_parameter1, $join_parameter2);
     if ($string =~ /^([^\s]+)\s+(\d+)$/) {
         $join_channel = $1;
         $join_session = $2;
-        $join_language = 'en';
     } elsif ($string =~ /^([^\s]+)\s+(\d+)\s+([a-z]+)$/) {
         $join_channel = $1;
         $join_session = $2;
-        $join_language = $3;
+        $join_parameter1 = $3;
+        $join_parameter2 = '';
+    } elsif ($string =~ /^([^\s]+)\s+(\d+)\s+([a-z:A-Z0-9]+)\s+([a-z:A-Z0-9]+)$/) {
+        $join_channel = $1;
+        $join_session = $2;
+        $join_parameter1 = $3;
+        $join_parameter2 = $4;
     } 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);
@@ -2694,6 +2701,41 @@ sub handle_command_join {
     my $join_irc = $main::sessions{$join_session}{'session'};
 
 
+    $join_language = 'en';
+    if ($join_parameter1 =~ /^lang:([a-z]+)$/) {
+        $join_language = $1;
+        $join_parameter1 = '';
+    }
+    if ($join_parameter2 =~ /^lang:([a-z])$/) {
+        $join_language = $1;
+        $join_parameter2 = '';
+    }
+
+    $join_password = '';
+    if ($join_parameter1 =~ /^pass:(.+)$/) {
+        $join_password = $1;
+        $join_parameter1 = '';
+    }
+    if ($join_parameter1 =~ /^password:(.+)$/) {
+        $join_password = $1;
+        $join_parameter1 = '';
+    }
+    if ($join_parameter2 =~ /^pass:(.+)$/) {
+        $join_password = $1;
+        $join_parameter2 = '';
+    }
+    if ($join_parameter2 =~ /^password:(.+)$/) {
+        $join_password = $1;
+        $join_parameter2 = '';
+    }
+
+    if (length($join_parameter1) > 0 or length($join_parameter2) > 0) {
+        my $answer = 'Invalid parameter';
+        $answer = translate_text_for_channel($channel, 'invalid_parameter', $answer);
+        return $answer;
+    }
+
+
     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);
@@ -2704,7 +2746,11 @@ sub handle_command_join {
     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 );
+    if (length($join_password) > 0) {
+        $join_irc->yield( join => $join_channel, $join_password );
+    } else {
+        $join_irc->yield( join => $join_channel );
+    }
     $main::statistics{'command_counter_join'}++;
 
 
@@ -4141,6 +4187,23 @@ sub on_kick {
 }
 
 
+# on_cannot_join_channel()
+#
+# handle "cannot join channel" events
+#
+sub on_cannot_join_channel {
+    my ($sender, $kernel, $heap, $arg0, $arg1, $arg2) = @_[SENDER, KERNEL, HEAP, ARG0, ARG1, ARG2];
+
+    my $irc = $sender->get_heap();
+    my $session = find_irc_session($irc);
+    print_msg("on_cannot_join_channel(session: $session): $arg1", DEBUG);
+
+    send_to_commandchannel($arg1);
+
+    set_session_activity($session);
+}
+
+
 # on_irc_raw()
 #
 # set session activity (incoming traffic)
index 57f7b4165362193142883b954cb1ea953882ffe9..226fe85bd6219f3d34638238d3a65c21775c42c7 100644 (file)
@@ -25,6 +25,7 @@ translations:
     you_are_not_authorized: 'Sie sind nicht authorisiert'
     access_denied: 'Zugriff verweigert'
     invalid_search: 'Ungültige Suche'
+    invalid_parameter: 'Ungültiger Parameter'
     database_error: 'Datenbankfehler'
     more_results_at: 'Mehr Ergebnisse unter'
     more_result: 'weiteres Ergebnis'
index 536baa4a8c2e2f9941806118acd37cae19a7ac8c..6c59b6fa64b185f5382bb4b0bd8a54742f22c64b 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -8,7 +8,6 @@
 - Log::Log4perl?
 - nickserv handling (passwords)
 - verify channel list from time to time, autojoin missing channels
-- allow a password for the ?join command
 
 
 
@@ -29,3 +28,4 @@
 - move translations to a separate file OK
 - channel passwords OK
 - predefine channels in the configuration which are not autojoined OK
+- allow a password for the ?join command OK