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
master
Giel van Schijndel 2009-04-07 10:01:11 +00:00 committed by Git SVN Gateway
parent 74c3180bc3
commit cd7edf0f88
1 changed files with 4 additions and 6 deletions

View File

@ -117,10 +117,7 @@ class bot_connection:
self.nick = nick self.nick = nick
def read(self): def read(self):
while True: return self.connection.read()
line = self.connection.read()
if line.find(self.nick) >= 0:
return line.replace(self.nick, "").strip(" \t,:.?!")
def write(self, line): def write(self, line):
self.connection.write(line) self.connection.write(line)
@ -128,7 +125,6 @@ class bot_connection:
class irc_connection: class irc_connection:
s = None s = None
channel = None channel = None
channel_message = re.compile(r'^:(?P<nick>[^!]+)\S*\s+PRIVMSG (?P<channel>#[^:]+) :(?P<message>.*)$')
def __init__(self, server, port, channel, nick): def __init__(self, server, port, channel, nick):
self.s = line_socket(server, port) 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("USER %s 0 * :Warzone 2100 Lobby Bot ( http://wz2100.net/ )" % (nick))
self.s.write("JOIN "+channel) self.s.write("JOIN "+channel)
self.private_channel_message = re.compile(r'^:(?P<nick>[^!]+)\S*\s+PRIVMSG (?P<channel>#[^:]+) :[ \t,:.?!]*%s[ \t,:.?!]*(?P<message>.*?)[ \t,:.?!]*$' % (nick))
def read(self): def read(self):
while True: while True:
line = self.s.read() line = self.s.read()
m = self.channel_message.match(line) m = self.private_channel_message.match(line)
if m: if m:
message = m.group('message') message = m.group('message')
if m.group('channel') == self.channel: if m.group('channel') == self.channel: