summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjason2006-07-27 00:06:52 +0000
committerjason2006-07-27 00:06:52 +0000
commita0b8a3a265547b5f61114d971d2a9c30dfcda74b (patch)
treeb0bf8df971525fe67456f0773159564ca49e3f84
parentc8a737e7e673db646a35819dab6aa560eea88a53 (diff)
downloadwarmachine-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
-rw-r--r--warmachine.py55
-rw-r--r--wmd/__init__.py0
-rw-r--r--wmd/parser.py30
3 files changed, 58 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
3from actions.ActionMap import * 3from actions.ActionMap import *
4from passiveactions.PassiveActionMap import * 4from passiveactions.PassiveActionMap import *
5from conf.users import * 5from conf.users import *
6 6from wmd import parser
7class irc: 7class 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
105if __name__ == '__main__': 106if __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()
diff --git a/wmd/__init__.py b/wmd/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/wmd/__init__.py
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 @@
1class ircparse(object):
2 #http://www.irchelp.org/irchelp/rfc/rfc.html
3
4 def __init__(self, data):
5 self.prefix =''
6 self.command = ''
7
8 self._rawdata = data
9
10 #print "x" * 80
11 #print data
12 #print "xo" * 40
13
14 self._process_data(data)
15
16 def _process_data(self, data):
17 data = data.strip()
18
19 # The presence of a prefix is indicated with a single leading ASCII
20 # colon character (':', 0x3b), which must be the first character of
21 # the message itself. There must be no gap (whitespace) between the
22 # colon and the prefix.
23 if data[0] == ':':
24 self.prefix = data[1:].split(' ')[0]
25 else:
26 # If the prefix is missing from the message, it is assumed to have
27 # originated from the connection from which it was received.
28 #
29 # TODO: Get the server name from the parent object.
30 pass