diff options
| author | jason | 2006-08-08 02:12:09 +0000 |
|---|---|---|
| committer | jason | 2006-08-08 02:12:09 +0000 |
| commit | 52db8e8ff348f8e9c51ed894015e36458c7c040c (patch) | |
| tree | e97e14190c53f70b5204bbe1fe8543457aadca63 | |
| parent | a0b8a3a265547b5f61114d971d2a9c30dfcda74b (diff) | |
| download | warmachine-52db8e8ff348f8e9c51ed894015e36458c7c040c.tar.gz warmachine-52db8e8ff348f8e9c51ed894015e36458c7c040c.zip | |
Added irc command parsing in wmd/parser.py
git-svn-id: svn://svn.zzq.org/warmachine/trunk@4 3ede8657-8418-0410-873f-eb3fb5a66eab
| -rw-r--r-- | conf/users.py | 1 | ||||
| -rw-r--r-- | passiveactions/logtoconsole.py | 2 | ||||
| -rw-r--r-- | warmachine.py | 17 | ||||
| -rw-r--r-- | wmd/parser.py | 13 |
4 files changed, 28 insertions, 5 deletions
diff --git a/conf/users.py b/conf/users.py index 1b7ffc7..174380c 100644 --- a/conf/users.py +++ b/conf/users.py | |||
| @@ -2,3 +2,4 @@ user = [] | |||
| 2 | user.append('ashcrow') | 2 | user.append('ashcrow') |
| 3 | user.append('beav') | 3 | user.append('beav') |
| 4 | user.append('wes') | 4 | user.append('wes') |
| 5 | user.append('com4') | ||
diff --git a/passiveactions/logtoconsole.py b/passiveactions/logtoconsole.py index 533e082..952bded 100644 --- a/passiveactions/logtoconsole.py +++ b/passiveactions/logtoconsole.py | |||
| @@ -5,7 +5,7 @@ class logtoconsole: | |||
| 5 | 5 | ||
| 6 | def getAction(self, data, users): | 6 | def getAction(self, data, users): |
| 7 | try: | 7 | try: |
| 8 | print data | 8 | # print data |
| 9 | return False | 9 | return False |
| 10 | except: | 10 | except: |
| 11 | return False | 11 | return False |
diff --git a/warmachine.py b/warmachine.py index 0a358fc..769e7b6 100644 --- a/warmachine.py +++ b/warmachine.py | |||
| @@ -78,7 +78,17 @@ class irc: | |||
| 78 | """ | 78 | """ |
| 79 | while True: | 79 | while True: |
| 80 | data = self.irc.recv(4096) | 80 | data = self.irc.recv(4096) |
| 81 | #obj_data = parser.ircparse(data) | 81 | |
| 82 | if data == '': | ||
| 83 | continue | ||
| 84 | |||
| 85 | # Buffering for MOTD. | ||
| 86 | if data[-1] != '\n': | ||
| 87 | data = data + self.irc.recv(4096) | ||
| 88 | |||
| 89 | for line in data.split('\r\n'): | ||
| 90 | obj_data = parser.ircparse(line) | ||
| 91 | #pass to action handlers here... | ||
| 82 | 92 | ||
| 83 | # Passive Actions | 93 | # Passive Actions |
| 84 | try: | 94 | try: |
| @@ -97,14 +107,15 @@ class irc: | |||
| 97 | break | 107 | break |
| 98 | else: | 108 | else: |
| 99 | input = data.split() | 109 | input = data.split() |
| 100 | self.send('PRIVMSG ' + input[2] + ' :' + curuser + ': stop bothering me jerk.') | 110 | self.send('PRIVMSG ' + input[2] + ' :' + curuser + |
| 111 | ': stop bothering me jerk.') | ||
| 101 | except Exception,e: | 112 | except Exception,e: |
| 102 | print "Action failed" | 113 | print "Action failed" |
| 103 | print e | 114 | print e |
| 104 | 115 | ||
| 105 | 116 | ||
| 106 | if __name__ == '__main__': | 117 | if __name__ == '__main__': |
| 107 | i = irc('irc.efnet.org', 'warmachine', 'omgident') | 118 | i = irc('localhost', 'warmachine', 'omgident') |
| 108 | i.connect() | 119 | i.connect() |
| 109 | i.join('#zzq') | 120 | i.join('#zzq') |
| 110 | i.MainLoop() | 121 | i.MainLoop() |
diff --git a/wmd/parser.py b/wmd/parser.py index ecb2e55..52a0e9a 100644 --- a/wmd/parser.py +++ b/wmd/parser.py | |||
| @@ -4,6 +4,7 @@ class ircparse(object): | |||
| 4 | def __init__(self, data): | 4 | def __init__(self, data): |
| 5 | self.prefix ='' | 5 | self.prefix ='' |
| 6 | self.command = '' | 6 | self.command = '' |
| 7 | self.params = '' | ||
| 7 | 8 | ||
| 8 | self._rawdata = data | 9 | self._rawdata = data |
| 9 | 10 | ||
| @@ -11,7 +12,8 @@ class ircparse(object): | |||
| 11 | #print data | 12 | #print data |
| 12 | #print "xo" * 40 | 13 | #print "xo" * 40 |
| 13 | 14 | ||
| 14 | self._process_data(data) | 15 | if data != '': |
| 16 | self._process_data(data) | ||
| 15 | 17 | ||
| 16 | def _process_data(self, data): | 18 | def _process_data(self, data): |
| 17 | data = data.strip() | 19 | data = data.strip() |
| @@ -28,3 +30,12 @@ class ircparse(object): | |||
| 28 | # | 30 | # |
| 29 | # TODO: Get the server name from the parent object. | 31 | # TODO: Get the server name from the parent object. |
| 30 | pass | 32 | pass |
| 33 | |||
| 34 | # Command comes 2nd (Or first if the prefix is missing) | ||
| 35 | self.command = data.split(' ')[1] | ||
| 36 | |||
| 37 | # Finally we reconstruct the parameters. We'll let the plugins figure out | ||
| 38 | # what they mean since they could potentially be very different. | ||
| 39 | for param in data.split(' ')[2:]: | ||
| 40 | self.params += param + " " | ||
| 41 | self.params.strip() | ||