diff options
| author | jason | 2006-07-27 00:06:52 +0000 |
|---|---|---|
| committer | jason | 2006-07-27 00:06:52 +0000 |
| commit | a0b8a3a265547b5f61114d971d2a9c30dfcda74b (patch) | |
| tree | b0bf8df971525fe67456f0773159564ca49e3f84 /warmachine.py | |
| parent | c8a737e7e673db646a35819dab6aa560eea88a53 (diff) | |
| download | warmachine-a0b8a3a265547b5f61114d971d2a9c30dfcda74b.tar.gz warmachine-a0b8a3a265547b5f61114d971d2a9c30dfcda74b.zip | |
Started working on a parser.
git-svn-id: svn://svn.zzq.org/warmachine/trunk@3 3ede8657-8418-0410-873f-eb3fb5a66eab
Diffstat (limited to 'warmachine.py')
| -rw-r--r-- | warmachine.py | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/warmachine.py b/warmachine.py index b5ab333..0a358fc 100644 --- a/warmachine.py +++ b/warmachine.py | |||
| @@ -3,7 +3,7 @@ import sys | |||
| 3 | from actions.ActionMap import * | 3 | from actions.ActionMap import * |
| 4 | from passiveactions.PassiveActionMap import * | 4 | from passiveactions.PassiveActionMap import * |
| 5 | from conf.users import * | 5 | from conf.users import * |
| 6 | 6 | from wmd import parser | |
| 7 | class irc: | 7 | class irc: |
| 8 | 8 | ||
| 9 | def __init__(self, server=None, nick=None, name=None, port=6667): | 9 | def __init__(self, server=None, nick=None, name=None, port=6667): |
| @@ -20,7 +20,6 @@ class irc: | |||
| 20 | Sets the servername. | 20 | Sets the servername. |
| 21 | """ | 21 | """ |
| 22 | self.server = server | 22 | self.server = server |
| 23 | |||
| 24 | def setNick(self, nick): | 23 | def setNick(self, nick): |
| 25 | """ | 24 | """ |
| 26 | Sets the nickname. | 25 | Sets the nickname. |
| @@ -43,7 +42,7 @@ class irc: | |||
| 43 | """ | 42 | """ |
| 44 | Loads the actions internally. | 43 | Loads the actions internally. |
| 45 | """ | 44 | """ |
| 46 | 45 | pass | |
| 47 | 46 | ||
| 48 | def connect(self): | 47 | def connect(self): |
| 49 | """ | 48 | """ |
| @@ -78,32 +77,34 @@ class irc: | |||
| 78 | Main Event Loop that parses generic commands | 77 | Main Event Loop that parses generic commands |
| 79 | """ | 78 | """ |
| 80 | while True: | 79 | while True: |
| 81 | data = self.irc.recv(4096) | 80 | data = self.irc.recv(4096) |
| 82 | # Passive Actions | 81 | #obj_data = parser.ircparse(data) |
| 83 | try: | 82 | |
| 84 | for key in passiveactions.keys(): | 83 | # Passive Actions |
| 85 | pa = passiveactions[key].getAction(data, user) | 84 | try: |
| 86 | if pa: | 85 | for key in passiveactions.keys(): |
| 87 | self.send(pa) | 86 | pa = passiveactions[key].getAction(data, user) |
| 88 | # Direct Actions | 87 | if pa: |
| 89 | if data.find(self.nick + ':') != -1: | 88 | self.send(pa) |
| 90 | curuser = data[1:data.index('!')] | 89 | # Direct Actions |
| 91 | if curuser in user: | 90 | if data.find(self.nick + ':') != -1: |
| 92 | input = data.split() | 91 | curuser = data[1:data.index('!')] |
| 93 | for key in actions.keys(): | 92 | if curuser in user: |
| 94 | if data.find(key) != -1: | 93 | input = data.split() |
| 95 | self.send(actions[key].getAction(data)) | 94 | for key in actions.keys(): |
| 96 | break | 95 | if data.find(key) != -1: |
| 97 | else: | 96 | self.send(actions[key].getAction(data)) |
| 98 | input = data.split() | 97 | break |
| 99 | self.send('PRIVMSG ' + input[2] + ' :' + curuser + ': stop bothering me jerk.') | 98 | else: |
| 100 | except Exception,e: | 99 | input = data.split() |
| 101 | print "Action failed" | 100 | self.send('PRIVMSG ' + input[2] + ' :' + curuser + ': stop bothering me jerk.') |
| 102 | print e | 101 | except Exception,e: |
| 102 | print "Action failed" | ||
| 103 | print e | ||
| 103 | 104 | ||
| 104 | 105 | ||
| 105 | if __name__ == '__main__': | 106 | if __name__ == '__main__': |
| 106 | i = irc('SERVER', 'NICK', 'USER') | 107 | i = irc('irc.efnet.org', 'warmachine', 'omgident') |
| 107 | i.connect() | 108 | i.connect() |
| 108 | i.join('#CHANNEL') | 109 | i.join('#zzq') |
| 109 | i.MainLoop() | 110 | i.MainLoop() |