From: Andreas Scherbaum Date: Fri, 24 Aug 2012 18:42:43 +0000 (+0200) Subject: - let's not fool the bot into sending messages to itself X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=39e83fa3084752080c40b29823e67cd842539a90;p=docbot.git - let's not fool the bot into sending messages to itself --- diff --git a/docbot.pl b/docbot.pl index 197357f..fe39bf7 100755 --- 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 ''; }