- let's not fool the bot into sending messages to itself
authorAndreas Scherbaum <andreas@scherbaum.biz>
Fri, 24 Aug 2012 18:42:43 +0000 (20:42 +0200)
committerAndreas Scherbaum <andreas@scherbaum.biz>
Fri, 24 Aug 2012 18:42:43 +0000 (20:42 +0200)
docbot.pl

index 197357f4d48f071cf9c5040fb09d33195135d130..fe39bf7ceefd49da7a795275062c836c7e78f02b 100755 (executable)
--- a/docbot.pl
+++ b/docbot.pl
@@ -1040,6 +1040,28 @@ sub session_for_channel {
 }
 
 
+# is_one_of_my_nicks()
+#
+# find out if a specific nick belongs to the bot
+#
+# parameter:
+#  - nick name
+# return:
+#  - 0/1
+sub is_one_of_my_nicks {
+    my $nick = shift;
+
+    foreach my $session (keys(%main::sessions)) {
+        my $irc = $main::sessions{$session}{'session'};
+        if (lc($irc->nick_name()) eq lc($nick)) {
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+
 # death()
 #
 # general shutdown procedure after all kind of errors
@@ -2834,10 +2856,16 @@ sub handle_command_search {
     my $replyto = $channel;
     if (lc($channel) eq lc($irc->nick_name())) {
         $replyto = $nick;
+        if (is_one_of_my_nicks($replyto)) {
+            return '';
+        }
     } elsif ($string =~ /^(.+)\s+>\s+(\w+)/i) {
         if (grep(/^$channel$/i, find_nick($heap, $2, $session))) {
             $string  = $1;
             $replyto = $2;
+            if (is_one_of_my_nicks($replyto)) {
+                return '';
+            }
         } else {
             return '';
         }