diff options
| -rw-r--r-- | passiveactions/autoop.py | 4 | ||||
| -rw-r--r-- | passiveactions/logtoconsole.py | 2 | ||||
| -rw-r--r-- | passiveactions/pong.py | 11 | ||||
| -rw-r--r-- | warmachine.py | 11 | ||||
| -rw-r--r-- | 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: | |||
| 6 | def getAction(self, data, users): | 6 | def getAction(self, data, users): |
| 7 | try: | 7 | try: |
| 8 | if data.command == 'JOIN': | 8 | if data.command == 'JOIN': |
| 9 | user = data.prefix[0:data.prefix.index('!')] | 9 | user = data.getUsername() |
| 10 | if user in users: | 10 | if user in users: |
| 11 | print "autoop" | 11 | print "autoop" |
| 12 | 12 | ||
| 13 | if data.params[0] == ':': | 13 | if data.params[0] == ':': |
| 14 | data.params = data.params[1:] | 14 | data.params = data.params[1:] |
| 15 | return 'MODE ' + data.params + ' +o ' + user | 15 | return 'MODE ' + data.params + ' +o ' + user |
| 16 | except: | 16 | except Exception,e: |
| 17 | return False | 17 | 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: | |||
| 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/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: | |||
| 5 | 5 | ||
| 6 | def getAction(self, data, users): | 6 | def getAction(self, data, users): |
| 7 | try: | 7 | try: |
| 8 | if data.find ( 'PING' ) != -1: | 8 | if data.command == 'PING': |
| 9 | print 'Ponged ' + data.split()[1] | 9 | if data.params[0] == ':': |
| 10 | return 'PONG ' + data.split()[1] | 10 | server = data.params[1:] |
| 11 | else: | ||
| 12 | server = data.params | ||
| 13 | print 'Ponged ' + server | ||
| 14 | return 'PONG ' + server | ||
| 11 | except: | 15 | except: |
| 12 | return False | 16 | return False |
| 13 | |||
diff --git a/warmachine.py b/warmachine.py index ed4fcda..426904f 100644 --- a/warmachine.py +++ b/warmachine.py | |||
| @@ -101,15 +101,16 @@ class irc: | |||
| 101 | 101 | ||
| 102 | # Passive Actions | 102 | # Passive Actions |
| 103 | try: | 103 | try: |
| 104 | # for key in passiveactions.keys(): | 104 | #for key in passiveactions.keys(): |
| 105 | # pa = passiveactions[key].getAction(data, user) | 105 | # pa = passiveactions[key].getAction(data, user) |
| 106 | # if pa: | 106 | # if pa: |
| 107 | # self.send(pa) | 107 | # self.send(pa) |
| 108 | # Direct Actions | 108 | # Direct Actions |
| 109 | if data.find(self.nick + ':') != -1: | 109 | if data.find(self.nick + ':') != -1: |
| 110 | curuser = data[1:data.index('!')] | 110 | curuser = data[1:data.index('!')] |
| 111 | if curuser in user: | 111 | if curuser in user: |
| 112 | input = data.split() | 112 | input = data.split() |
| 113 | print "$$ " + input | ||
| 113 | for key in actions.keys(): | 114 | for key in actions.keys(): |
| 114 | if data.find(key) != -1: | 115 | if data.find(key) != -1: |
| 115 | self.send(actions[key].getAction(data)) | 116 | self.send(actions[key].getAction(data)) |
| @@ -124,7 +125,7 @@ class irc: | |||
| 124 | 125 | ||
| 125 | 126 | ||
| 126 | if __name__ == '__main__': | 127 | if __name__ == '__main__': |
| 127 | i = irc('irc.servercentral.net', 'warmachine', 'omgident') | 128 | i = irc('irc.inter.net.il', 'warmachine', 'omgident') |
| 128 | i.connect() | 129 | i.connect() |
| 129 | i.join('#zzq') | 130 | i.join('#zzq') |
| 130 | i.MainLoop() | 131 | 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): | |||
| 11 | if data != '': | 11 | if data != '': |
| 12 | self._process_data(data) | 12 | self._process_data(data) |
| 13 | 13 | ||
| 14 | def getUsername(self): | ||
| 15 | # Usernames are from 0 to the !... extract it out of we can. | ||
| 16 | if self.prefix.find('!') > -1: | ||
| 17 | return self.prefix[0:self.prefix.index('!')] | ||
| 18 | else: | ||
| 19 | return False | ||
| 20 | |||
| 14 | def _process_data(self, data): | 21 | def _process_data(self, data): |
| 15 | data = data.strip() | 22 | data = data.strip() |
| 16 | 23 | ||
| @@ -20,21 +27,22 @@ class ircparse(object): | |||
| 20 | # colon and the prefix. | 27 | # colon and the prefix. |
| 21 | if data[0] == ':': | 28 | if data[0] == ':': |
| 22 | self.prefix = data[1:].split(' ')[0] | 29 | self.prefix = data[1:].split(' ')[0] |
| 30 | start_at = 1 | ||
| 23 | else: | 31 | else: |
| 24 | # If the prefix is missing from the message, it is assumed to have | 32 | # If the prefix is missing from the message, it is assumed to have |
| 25 | # originated from the connection from which it was received. | 33 | # originated from the connection from which it was received. |
| 26 | # | 34 | # |
| 27 | # TODO: Get the server name from the parent object. | 35 | # TODO: Get the server name from the parent object. |
| 28 | pass | 36 | start_at = 0 |
| 29 | 37 | ||
| 30 | # Command comes 2nd (Or first if the prefix is missing) | 38 | # Command comes 2nd (Or first if the prefix is missing) |
| 31 | if len(data.split(' ')) > 1: | 39 | if len(data.split(' ')) > start_at: |
| 32 | self.command = data.split(' ')[1] | 40 | self.command = data.split(' ')[start_at] |
| 33 | 41 | ||
| 34 | # Finally we reconstruct the parameters. We'll let the plugins figure out | 42 | # Finally we reconstruct the parameters. We'll let the plugins figure out |
| 35 | # what they mean since they could potentially be very different. | 43 | # what they mean since they could potentially be very different. |
| 36 | if len(data.split(' ')) > 2: | 44 | if len(data.split(' ')) > (start_at + 1): |
| 37 | for param in data.split(' ')[2:]: | 45 | for param in data.split(' ')[(start_at+1):]: |
| 38 | self.params += param + " " | 46 | self.params += param + " " |
| 39 | self.params.strip() | 47 | self.params.strip() |
| 40 | 48 | ||