diff options
| author | jason | 2006-07-24 20:39:43 +0000 |
|---|---|---|
| committer | jason | 2006-07-24 20:39:43 +0000 |
| commit | c8a737e7e673db646a35819dab6aa560eea88a53 (patch) | |
| tree | 2ba03a74333ad890260dcac90b1bccf289e4f9d4 | |
| parent | 862840e980954fd86a4dd675a158ec03f52e5d7f (diff) | |
| download | warmachine-c8a737e7e673db646a35819dab6aa560eea88a53.tar.gz warmachine-c8a737e7e673db646a35819dab6aa560eea88a53.zip | |
steve's initial framework
git-svn-id: svn://svn.zzq.org/warmachine/trunk@2 3ede8657-8418-0410-873f-eb3fb5a66eab
| -rw-r--r-- | actions/ActionMap.py | 16 | ||||
| -rw-r--r-- | actions/__init__.py | 0 | ||||
| -rw-r--r-- | actions/coin.py | 17 | ||||
| -rw-r--r-- | actions/deop.py | 8 | ||||
| -rw-r--r-- | actions/devoice.py | 8 | ||||
| -rw-r--r-- | actions/join.py | 7 | ||||
| -rw-r--r-- | actions/kick.py | 9 | ||||
| -rw-r--r-- | actions/op.py | 8 | ||||
| -rw-r--r-- | actions/part.py | 7 | ||||
| -rw-r--r-- | actions/pythondoc.py | 22 | ||||
| -rw-r--r-- | actions/quit.py | 7 | ||||
| -rw-r--r-- | actions/say.py | 11 | ||||
| -rw-r--r-- | actions/settopic.py | 11 | ||||
| -rw-r--r-- | actions/voice.py | 8 | ||||
| -rw-r--r-- | conf/__init__.py | 0 | ||||
| -rw-r--r-- | conf/users.py | 4 | ||||
| -rw-r--r-- | passiveactions/PassiveActionMap.py | 8 | ||||
| -rw-r--r-- | passiveactions/__init__.py | 0 | ||||
| -rw-r--r-- | passiveactions/autoop.py | 15 | ||||
| -rw-r--r-- | passiveactions/logtoconsole.py | 11 | ||||
| -rw-r--r-- | passiveactions/pong.py | 13 | ||||
| -rw-r--r-- | passiveactions/rootcheck.py | 17 | ||||
| -rw-r--r-- | passiveactions/spy.py | 23 | ||||
| -rw-r--r-- | warmachine.py | 109 |
24 files changed, 339 insertions, 0 deletions
diff --git a/actions/ActionMap.py b/actions/ActionMap.py new file mode 100644 index 0000000..4c8431f --- /dev/null +++ b/actions/ActionMap.py | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | import say, op, deop, quit, part, voice, devoice | ||
| 2 | import join, kick, pythondoc, settopic, coin | ||
| 3 | |||
| 4 | actions = {} | ||
| 5 | actions['say'] = say.say() | ||
| 6 | actions['op'] = op.op() | ||
| 7 | actions['deop'] = deop.deop() | ||
| 8 | actions['quit'] = quit.quit() | ||
| 9 | actions['part'] = part.part() | ||
| 10 | actions['voice'] = voice.voice() | ||
| 11 | actions['devoice'] = devoice.devoice() | ||
| 12 | actions['kick'] = kick.kick() | ||
| 13 | actions['join'] = join.join() | ||
| 14 | actions['pythondoc'] = pythondoc.pythondoc() | ||
| 15 | actions['settopic'] = settopic.settopic() | ||
| 16 | actions['coin'] = coin.coin() | ||
diff --git a/actions/__init__.py b/actions/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/actions/__init__.py | |||
diff --git a/actions/coin.py b/actions/coin.py new file mode 100644 index 0000000..05dfbda --- /dev/null +++ b/actions/coin.py | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | import random | ||
| 2 | |||
| 3 | class coin: | ||
| 4 | |||
| 5 | def __init__(self): | ||
| 6 | self = [] | ||
| 7 | |||
| 8 | def getAction(self, data): | ||
| 9 | ret = int(random.random()*10) | ||
| 10 | print ret | ||
| 11 | thecoin = 'The coin lands on it\'s SIDE!!!' | ||
| 12 | if ret >= 6: | ||
| 13 | thecoin = "The coin lands on HEAD." | ||
| 14 | else: | ||
| 15 | thecoin = "The coin lands on TAILS." | ||
| 16 | input = data.split(' ') | ||
| 17 | return 'PRIVMSG ' + input[4] + ' :' + thecoin | ||
diff --git a/actions/deop.py b/actions/deop.py new file mode 100644 index 0000000..d9c61eb --- /dev/null +++ b/actions/deop.py | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | class deop: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data): | ||
| 7 | input = data.split(' ') | ||
| 8 | return 'MODE ' + input[5] + ' -o ' + input[6] | ||
diff --git a/actions/devoice.py b/actions/devoice.py new file mode 100644 index 0000000..9539634 --- /dev/null +++ b/actions/devoice.py | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | class devoice: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data): | ||
| 7 | input = data.split(' ') | ||
| 8 | return 'MODE ' + input[5] + ' -v ' + input[6] | ||
diff --git a/actions/join.py b/actions/join.py new file mode 100644 index 0000000..7a36947 --- /dev/null +++ b/actions/join.py | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | class join: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data): | ||
| 7 | return 'JOIN ' + data[data.index('join')+5:] | ||
diff --git a/actions/kick.py b/actions/kick.py new file mode 100644 index 0000000..86416fa --- /dev/null +++ b/actions/kick.py | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | class kick: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data): | ||
| 7 | input = data.split(' ') | ||
| 8 | return 'KICK ' + input[5] + ' ' + input[6] | ||
| 9 | |||
diff --git a/actions/op.py b/actions/op.py new file mode 100644 index 0000000..60102c4 --- /dev/null +++ b/actions/op.py | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | class op: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data): | ||
| 7 | input = data.split(' ') | ||
| 8 | return 'MODE ' + input[5] + ' +o ' + input[6] | ||
diff --git a/actions/part.py b/actions/part.py new file mode 100644 index 0000000..f55e63f --- /dev/null +++ b/actions/part.py | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | class part: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data): | ||
| 7 | return 'PART ' + data[data.index('part')+5:] | ||
diff --git a/actions/pythondoc.py b/actions/pythondoc.py new file mode 100644 index 0000000..e420723 --- /dev/null +++ b/actions/pythondoc.py | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | import os | ||
| 2 | |||
| 3 | class pythondoc: | ||
| 4 | |||
| 5 | def __init__(self): | ||
| 6 | self = [] | ||
| 7 | |||
| 8 | def getAction(self, data): | ||
| 9 | try: | ||
| 10 | input = data.split(' ') | ||
| 11 | module = input[5].replace(' ', '') | ||
| 12 | try: | ||
| 13 | module2 = input[6][0:-2] | ||
| 14 | execstring = "python -c \"from " + module + " import " + module2 + "\nprint " + module2 + ".__doc__\n\" > /tmp/wmpycmd" | ||
| 15 | except: | ||
| 16 | module = input[5][0:-2] | ||
| 17 | execstring = "python -c \"import " + module + "\nprint " + module + ".__doc__\n\" > /tmp/wmpycmd" | ||
| 18 | os.system(execstring) | ||
| 19 | doc = file('/tmp/wmpycmd').read().replace("\n", " ") | ||
| 20 | except: | ||
| 21 | doc = "I don't know nuthn about that." | ||
| 22 | return 'PRIVMSG ' + input[2] + ' :' + doc | ||
diff --git a/actions/quit.py b/actions/quit.py new file mode 100644 index 0000000..c945f5d --- /dev/null +++ b/actions/quit.py | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | class quit: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data): | ||
| 7 | return 'QUIT\r\n' | ||
diff --git a/actions/say.py b/actions/say.py new file mode 100644 index 0000000..7c7273f --- /dev/null +++ b/actions/say.py | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | class say: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data): | ||
| 7 | input = data.split(' ') | ||
| 8 | words = "" | ||
| 9 | for word in input[6:]: | ||
| 10 | words += ' ' + word | ||
| 11 | return 'PRIVMSG ' + input[5] + ' :' + words[1:] | ||
diff --git a/actions/settopic.py b/actions/settopic.py new file mode 100644 index 0000000..8fa574a --- /dev/null +++ b/actions/settopic.py | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | class settopic: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data): | ||
| 7 | input = data.split(' ') | ||
| 8 | words = "" | ||
| 9 | for word in input[6:]: | ||
| 10 | words += ' ' + word | ||
| 11 | return 'TOPIC ' + input[5] + ' :' + words[1:] | ||
diff --git a/actions/voice.py b/actions/voice.py new file mode 100644 index 0000000..fe42d05 --- /dev/null +++ b/actions/voice.py | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | class voice: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data): | ||
| 7 | input = data.split(' ') | ||
| 8 | return 'MODE ' + input[5] + ' +v ' + input[6] | ||
diff --git a/conf/__init__.py b/conf/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/conf/__init__.py | |||
diff --git a/conf/users.py b/conf/users.py new file mode 100644 index 0000000..1b7ffc7 --- /dev/null +++ b/conf/users.py | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | user = [] | ||
| 2 | user.append('ashcrow') | ||
| 3 | user.append('beav') | ||
| 4 | user.append('wes') | ||
diff --git a/passiveactions/PassiveActionMap.py b/passiveactions/PassiveActionMap.py new file mode 100644 index 0000000..087754c --- /dev/null +++ b/passiveactions/PassiveActionMap.py | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | import pong, spy, rootcheck, autoop, logtoconsole | ||
| 2 | |||
| 3 | passiveactions = {} | ||
| 4 | passiveactions['pong'] = pong.pong() | ||
| 5 | passiveactions['spy'] = spy.spy() | ||
| 6 | passiveactions['rootcheck'] = rootcheck.rootcheck() | ||
| 7 | passiveactions['autoop'] = autoop.autoop() | ||
| 8 | passiveactions['logtoconsole'] = logtoconsole.logtoconsole() | ||
diff --git a/passiveactions/__init__.py b/passiveactions/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/passiveactions/__init__.py | |||
diff --git a/passiveactions/autoop.py b/passiveactions/autoop.py new file mode 100644 index 0000000..45ae9e4 --- /dev/null +++ b/passiveactions/autoop.py | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | class autoop: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data, users): | ||
| 7 | try: | ||
| 8 | input = data.split() | ||
| 9 | if 'JOIN' in input[1]: | ||
| 10 | user = data[1:data.index('!')] | ||
| 11 | if user in users: | ||
| 12 | print "autoop" | ||
| 13 | return 'MODE ' + input[2][1:] + ' +o ' + user | ||
| 14 | except: | ||
| 15 | return False | ||
diff --git a/passiveactions/logtoconsole.py b/passiveactions/logtoconsole.py new file mode 100644 index 0000000..533e082 --- /dev/null +++ b/passiveactions/logtoconsole.py | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | class logtoconsole: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data, users): | ||
| 7 | try: | ||
| 8 | print data | ||
| 9 | return False | ||
| 10 | except: | ||
| 11 | return False | ||
diff --git a/passiveactions/pong.py b/passiveactions/pong.py new file mode 100644 index 0000000..04f663b --- /dev/null +++ b/passiveactions/pong.py | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | class pong: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data, users): | ||
| 7 | try: | ||
| 8 | if data.find ( 'PING' ) != -1: | ||
| 9 | print 'Ponged ' + data.split()[1] | ||
| 10 | return 'PONG ' + data.split()[1] | ||
| 11 | except: | ||
| 12 | return False | ||
| 13 | |||
diff --git a/passiveactions/rootcheck.py b/passiveactions/rootcheck.py new file mode 100644 index 0000000..c5cc7a7 --- /dev/null +++ b/passiveactions/rootcheck.py | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | class rootcheck: | ||
| 2 | |||
| 3 | def __init__(self): | ||
| 4 | self = [] | ||
| 5 | |||
| 6 | def getAction(self, data, users): | ||
| 7 | try: | ||
| 8 | user = data[1:data.index('!')] | ||
| 9 | input = data.split() | ||
| 10 | if 'JOIN' in input[1]: | ||
| 11 | if 'root' in input[0]: | ||
| 12 | cmd = "PRIVMSG " + input[2][1:] + " :" + user +": Root?!?!?!!??!" | ||
| 13 | cmd += "\r\nKICK " + input[2][1:] + " " + user + " :Root + irc = kick" | ||
| 14 | return cmd | ||
| 15 | except: | ||
| 16 | return False | ||
| 17 | |||
diff --git a/passiveactions/spy.py b/passiveactions/spy.py new file mode 100644 index 0000000..c1fc1f6 --- /dev/null +++ b/passiveactions/spy.py | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | spyusers = [] | ||
| 2 | spyusers.append('stevetest') | ||
| 3 | |||
| 4 | spymaster = "" | ||
| 5 | |||
| 6 | class spy: | ||
| 7 | |||
| 8 | def __init__(self): | ||
| 9 | self = [] | ||
| 10 | |||
| 11 | def getAction(self, data, users): | ||
| 12 | try: | ||
| 13 | user = data[1:data.index('!')] | ||
| 14 | if user in spyusers: | ||
| 15 | if user in data: | ||
| 16 | input = data.split() | ||
| 17 | words = "" | ||
| 18 | for word in input[3:]: | ||
| 19 | words += ' ' + word | ||
| 20 | return 'PRIVMSG ' + spymaster + ' :' + user + ' in ' + input[2] + ' said "' + words[2:] + '"' | ||
| 21 | except: | ||
| 22 | return False | ||
| 23 | |||
diff --git a/warmachine.py b/warmachine.py new file mode 100644 index 0000000..b5ab333 --- /dev/null +++ b/warmachine.py | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | import socket | ||
| 2 | import sys | ||
| 3 | from actions.ActionMap import * | ||
| 4 | from passiveactions.PassiveActionMap import * | ||
| 5 | from conf.users import * | ||
| 6 | |||
| 7 | class irc: | ||
| 8 | |||
| 9 | def __init__(self, server=None, nick=None, name=None, port=6667): | ||
| 10 | """ | ||
| 11 | IRC connection library that needs at least server, nick and name | ||
| 12 | """ | ||
| 13 | self.setServer(server) | ||
| 14 | self.setNick(nick) | ||
| 15 | self.setName(name) | ||
| 16 | self.setPort(port) | ||
| 17 | |||
| 18 | def setServer(self, server): | ||
| 19 | """ | ||
| 20 | Sets the servername. | ||
| 21 | """ | ||
| 22 | self.server = server | ||
| 23 | |||
| 24 | def setNick(self, nick): | ||
| 25 | """ | ||
| 26 | Sets the nickname. | ||
| 27 | """ | ||
| 28 | self.nick = nick | ||
| 29 | |||
| 30 | def setName(self, name): | ||
| 31 | """ | ||
| 32 | Sets the name. | ||
| 33 | """ | ||
| 34 | self.name = name | ||
| 35 | |||
| 36 | def setPort(self, port): | ||
| 37 | """ | ||
| 38 | Sets the port number to connect to. | ||
| 39 | """ | ||
| 40 | self.port = port | ||
| 41 | |||
| 42 | def locaActions(self): | ||
| 43 | """ | ||
| 44 | Loads the actions internally. | ||
| 45 | """ | ||
| 46 | |||
| 47 | |||
| 48 | def connect(self): | ||
| 49 | """ | ||
| 50 | Connects to the irc server. | ||
| 51 | """ | ||
| 52 | self.irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
| 53 | self.irc.connect((self.server, self.port)) | ||
| 54 | self.log(self.irc.recv(4096)) | ||
| 55 | self.irc.send('NICK ' + self.nick + '\r\n') | ||
| 56 | self.irc.send('USER ' + self.name + ' 8 * :Warmachine\r\n') | ||
| 57 | |||
| 58 | def join(self, chan): | ||
| 59 | """ | ||
| 60 | Joins a channel | ||
| 61 | """ | ||
| 62 | self.send('JOIN ' + chan) | ||
| 63 | |||
| 64 | def log(self, string): | ||
| 65 | """ | ||
| 66 | Takes care of log formating. | ||
| 67 | """ | ||
| 68 | print 'log: ' + string | ||
| 69 | |||
| 70 | def send(self, command): | ||
| 71 | """ | ||
| 72 | Sends commands straight to the irc server. | ||
| 73 | """ | ||
| 74 | self.irc.send(command + '\r\n') | ||
| 75 | |||
| 76 | def MainLoop(self): | ||
| 77 | """ | ||
| 78 | Main Event Loop that parses generic commands | ||
| 79 | """ | ||
| 80 | while True: | ||
| 81 | data = self.irc.recv(4096) | ||
| 82 | # Passive Actions | ||
| 83 | try: | ||
| 84 | for key in passiveactions.keys(): | ||
| 85 | pa = passiveactions[key].getAction(data, user) | ||
| 86 | if pa: | ||
| 87 | self.send(pa) | ||
| 88 | # Direct Actions | ||
| 89 | if data.find(self.nick + ':') != -1: | ||
| 90 | curuser = data[1:data.index('!')] | ||
| 91 | if curuser in user: | ||
| 92 | input = data.split() | ||
| 93 | for key in actions.keys(): | ||
| 94 | if data.find(key) != -1: | ||
| 95 | self.send(actions[key].getAction(data)) | ||
| 96 | break | ||
| 97 | else: | ||
| 98 | input = data.split() | ||
| 99 | self.send('PRIVMSG ' + input[2] + ' :' + curuser + ': stop bothering me jerk.') | ||
| 100 | except Exception,e: | ||
| 101 | print "Action failed" | ||
| 102 | print e | ||
| 103 | |||
| 104 | |||
| 105 | if __name__ == '__main__': | ||
| 106 | i = irc('SERVER', 'NICK', 'USER') | ||
| 107 | i.connect() | ||
| 108 | i.join('#CHANNEL') | ||
| 109 | i.MainLoop() | ||