From a0b8a3a265547b5f61114d971d2a9c30dfcda74b Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 27 Jul 2006 00:06:52 +0000 Subject: Started working on a parser. git-svn-id: svn://svn.zzq.org/warmachine/trunk@3 3ede8657-8418-0410-873f-eb3fb5a66eab --- warmachine.py | 55 ++++++++++++++++++++++++++++--------------------------- wmd/__init__.py | 0 wmd/parser.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 27 deletions(-) create mode 100644 wmd/__init__.py create mode 100644 wmd/parser.py diff --git a/warmachine.py b/warmachine.py index b5ab333..0a358fc 100644 --- a/warmachine.py +++ b/warmachine.py @@ -3,7 +3,7 @@ import sys from actions.ActionMap import * from passiveactions.PassiveActionMap import * from conf.users import * - +from wmd import parser class irc: def __init__(self, server=None, nick=None, name=None, port=6667): @@ -20,7 +20,6 @@ class irc: Sets the servername. """ self.server = server - def setNick(self, nick): """ Sets the nickname. @@ -43,7 +42,7 @@ class irc: """ Loads the actions internally. """ - + pass def connect(self): """ @@ -78,32 +77,34 @@ class irc: Main Event Loop that parses generic commands """ while True: - data = self.irc.recv(4096) - # Passive Actions - try: - for key in passiveactions.keys(): - pa = passiveactions[key].getAction(data, user) - if pa: - self.send(pa) - # Direct Actions - if data.find(self.nick + ':') != -1: - curuser = data[1:data.index('!')] - if curuser in user: - input = data.split() - for key in actions.keys(): - if data.find(key) != -1: - self.send(actions[key].getAction(data)) - break - else: - input = data.split() - self.send('PRIVMSG ' + input[2] + ' :' + curuser + ': stop bothering me jerk.') - except Exception,e: - print "Action failed" - print e + data = self.irc.recv(4096) + #obj_data = parser.ircparse(data) + + # Passive Actions + try: + for key in passiveactions.keys(): + pa = passiveactions[key].getAction(data, user) + if pa: + self.send(pa) + # Direct Actions + if data.find(self.nick + ':') != -1: + curuser = data[1:data.index('!')] + if curuser in user: + input = data.split() + for key in actions.keys(): + if data.find(key) != -1: + self.send(actions[key].getAction(data)) + break + else: + input = data.split() + self.send('PRIVMSG ' + input[2] + ' :' + curuser + ': stop bothering me jerk.') + except Exception,e: + print "Action failed" + print e if __name__ == '__main__': - i = irc('SERVER', 'NICK', 'USER') + i = irc('irc.efnet.org', 'warmachine', 'omgident') i.connect() - i.join('#CHANNEL') + i.join('#zzq') i.MainLoop() diff --git a/wmd/__init__.py b/wmd/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/wmd/parser.py b/wmd/parser.py new file mode 100644 index 0000000..ecb2e55 --- /dev/null +++ b/wmd/parser.py @@ -0,0 +1,30 @@ +class ircparse(object): + #http://www.irchelp.org/irchelp/rfc/rfc.html + + def __init__(self, data): + self.prefix ='' + self.command = '' + + self._rawdata = data + + #print "x" * 80 + #print data + #print "xo" * 40 + + self._process_data(data) + + def _process_data(self, data): + data = data.strip() + + # The presence of a prefix is indicated with a single leading ASCII + # colon character (':', 0x3b), which must be the first character of + # the message itself. There must be no gap (whitespace) between the + # colon and the prefix. + if data[0] == ':': + self.prefix = data[1:].split(' ')[0] + else: + # If the prefix is missing from the message, it is assumed to have + # originated from the connection from which it was received. + # + # TODO: Get the server name from the parent object. + pass -- cgit v1.2.1