From 56ac917476400e1c643cff802ccb2a0d8f59f76a Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 9 Aug 2006 01:08:12 +0000 Subject: more error checking fixes in parser.py pong.py is in the new format git-svn-id: svn://svn.zzq.org/warmachine/trunk@7 3ede8657-8418-0410-873f-eb3fb5a66eab --- passiveactions/autoop.py | 4 ++-- passiveactions/logtoconsole.py | 2 +- passiveactions/pong.py | 11 +++++++---- warmachine.py | 11 ++++++----- wmd/parser.py | 18 +++++++++++++----- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/passiveactions/autoop.py b/passiveactions/autoop.py index 5724df5..7492c28 100644 --- a/passiveactions/autoop.py +++ b/passiveactions/autoop.py @@ -6,12 +6,12 @@ class autoop: def getAction(self, data, users): try: if data.command == 'JOIN': - user = data.prefix[0:data.prefix.index('!')] + user = data.getUsername() if user in users: print "autoop" if data.params[0] == ':': data.params = data.params[1:] return 'MODE ' + data.params + ' +o ' + user - except: + except Exception,e: return False diff --git a/passiveactions/logtoconsole.py b/passiveactions/logtoconsole.py index 952bded..d3a0bc0 100644 --- a/passiveactions/logtoconsole.py +++ b/passiveactions/logtoconsole.py @@ -5,7 +5,7 @@ class logtoconsole: def getAction(self, data, users): try: -# print data + #print data return False except: return False diff --git a/passiveactions/pong.py b/passiveactions/pong.py index 04f663b..3e6def6 100644 --- a/passiveactions/pong.py +++ b/passiveactions/pong.py @@ -5,9 +5,12 @@ class pong: def getAction(self, data, users): try: - if data.find ( 'PING' ) != -1: - print 'Ponged ' + data.split()[1] - return 'PONG ' + data.split()[1] + if data.command == 'PING': + if data.params[0] == ':': + server = data.params[1:] + else: + server = data.params + print 'Ponged ' + server + return 'PONG ' + server except: return False - diff --git a/warmachine.py b/warmachine.py index ed4fcda..426904f 100644 --- a/warmachine.py +++ b/warmachine.py @@ -101,15 +101,16 @@ class irc: # Passive Actions try: - # for key in passiveactions.keys(): - # pa = passiveactions[key].getAction(data, user) - # if pa: - # self.send(pa) + #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() + print "$$ " + input for key in actions.keys(): if data.find(key) != -1: self.send(actions[key].getAction(data)) @@ -124,7 +125,7 @@ class irc: if __name__ == '__main__': - i = irc('irc.servercentral.net', 'warmachine', 'omgident') + i = irc('irc.inter.net.il', 'warmachine', 'omgident') i.connect() i.join('#zzq') i.MainLoop() diff --git a/wmd/parser.py b/wmd/parser.py index 99173be..cf88f75 100644 --- a/wmd/parser.py +++ b/wmd/parser.py @@ -11,6 +11,13 @@ class ircparse(object): if data != '': self._process_data(data) + def getUsername(self): + # Usernames are from 0 to the !... extract it out of we can. + if self.prefix.find('!') > -1: + return self.prefix[0:self.prefix.index('!')] + else: + return False + def _process_data(self, data): data = data.strip() @@ -20,21 +27,22 @@ class ircparse(object): # colon and the prefix. if data[0] == ':': self.prefix = data[1:].split(' ')[0] + start_at = 1 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 + start_at = 0 # Command comes 2nd (Or first if the prefix is missing) - if len(data.split(' ')) > 1: - self.command = data.split(' ')[1] + if len(data.split(' ')) > start_at: + self.command = data.split(' ')[start_at] # Finally we reconstruct the parameters. We'll let the plugins figure out # what they mean since they could potentially be very different. - if len(data.split(' ')) > 2: - for param in data.split(' ')[2:]: + if len(data.split(' ')) > (start_at + 1): + for param in data.split(' ')[(start_at+1):]: self.params += param + " " self.params.strip() -- cgit v1.2.1