From cd7edf0f88241aff610f14a37f5772312df45923 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Tue, 7 Apr 2009 10:01:11 +0000 Subject: [PATCH] Use a more sofisticated regular expression for channel messages to ensure we only match messages that are intented for us (i.e. the lobby IRC bot) git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@6968 4a71c877-e1ca-e34f-864e-861f7616d084 --- tools/lobby/ircbot.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/lobby/ircbot.py b/tools/lobby/ircbot.py index f7f72fd05..c3edf79f0 100644 --- a/tools/lobby/ircbot.py +++ b/tools/lobby/ircbot.py @@ -117,10 +117,7 @@ class bot_connection: self.nick = nick def read(self): - while True: - line = self.connection.read() - if line.find(self.nick) >= 0: - return line.replace(self.nick, "").strip(" \t,:.?!") + return self.connection.read() def write(self, line): self.connection.write(line) @@ -128,7 +125,6 @@ class bot_connection: class irc_connection: s = None channel = None - channel_message = re.compile(r'^:(?P[^!]+)\S*\s+PRIVMSG (?P#[^:]+) :(?P.*)$') def __init__(self, server, port, channel, nick): self.s = line_socket(server, port) @@ -137,11 +133,13 @@ class irc_connection: self.s.write("USER %s 0 * :Warzone 2100 Lobby Bot ( http://wz2100.net/ )" % (nick)) self.s.write("JOIN "+channel) + self.private_channel_message = re.compile(r'^:(?P[^!]+)\S*\s+PRIVMSG (?P#[^:]+) :[ \t,:.?!]*%s[ \t,:.?!]*(?P.*?)[ \t,:.?!]*$' % (nick)) + def read(self): while True: line = self.s.read() - m = self.channel_message.match(line) + m = self.private_channel_message.match(line) if m: message = m.group('message') if m.group('channel') == self.channel: