Mercurial > repo
comparison a/d/DCPUToolBot-master/dcpubot.py @ 2768:730e97409041
<ThatOtherPerson> mv d a
author | HackBot |
---|---|
date | Mon, 22 Apr 2013 15:44:16 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2767:2aa9e7b74c84 | 2768:730e97409041 |
---|---|
1 #!/usr/bin/env python | |
2 import irc | |
3 import config | |
4 import subprocess | |
5 import dcpu | |
6 import random | |
7 | |
8 irc.connect(config.host, config.port, config.nick, config.password) | |
9 irc.join(config.chan) | |
10 | |
11 def onAssemble(nick, user, host, chan, matches): | |
12 print "Assembling" | |
13 print matches.group() | |
14 print matches.group(1) | |
15 binary, errors = dcpu.assemble(matches.group(1)) | |
16 | |
17 if binary: | |
18 irc.privmsg(nick, chan, ', '.join(binary)) | |
19 if errors: | |
20 irc.privmsg(nick, chan, errors) | |
21 | |
22 irc.onPrivmsg(">>>(.+)", onAssemble) | |
23 | |
24 def onDisassemble(nick, user, host, chan, matches): | |
25 print "Disassembling" | |
26 print matches.group() | |
27 print matches.group(1) | |
28 code = dcpu.disassemble(matches.group(1)) | |
29 | |
30 if code: | |
31 irc.privmsg(nick, chan, code) | |
32 | |
33 irc.onPrivmsg("<<<(.+)", onDisassemble) | |
34 | |
35 def onExecute(nick, user, host, chan, matches): | |
36 executed, errors = dcpu.execute(matches.group(1)) | |
37 | |
38 if executed: | |
39 irc.privmsg(nick, chan, executed) | |
40 if errors: | |
41 irc.privmsg(nick, chan, errors) | |
42 | |
43 irc.onPrivmsg(">>([^>].+)", onExecute) | |
44 | |
45 def onHex(nick, user, host, chan, matches): | |
46 converted = 0 | |
47 | |
48 if matches.group(1) == "0b": | |
49 converted = hex(int(matches.group(2), 2)) | |
50 else: | |
51 converted = hex(int(matches.group(2))) | |
52 | |
53 irc.privmsg(nick, chan, converted) | |
54 | |
55 irc.onPrivmsg(r"^hex\((0b)?(\d+)\)", onHex) | |
56 | |
57 def onDec(nick, user, host, chan, matches): | |
58 converted = 0 | |
59 | |
60 if matches.group(1) == "0b": | |
61 converted = str(int(matches.group(2), 2)) | |
62 elif matches.group(1) == "0x": | |
63 converted = str(int(matches.group(2), 16)) | |
64 else: | |
65 converted = str(int(matches.group(2))) | |
66 | |
67 irc.privmsg(nick, chan, converted) | |
68 | |
69 irc.onPrivmsg(r"^dec\((0b|0x)?([0-9a-fA-F]+)\)", onDec) | |
70 | |
71 def onBin(nick, user, host, chan, matches): | |
72 converted = 0 | |
73 | |
74 if matches.group(1) == "0x": | |
75 converted = bin(int(matches.group(2), 16)) | |
76 else: | |
77 converted = bin(int(matches.group(2), 16)) | |
78 | |
79 irc.privmsg(nick, chan, converted) | |
80 | |
81 irc.onPrivmsg(r"^bin\((0x)?([0-9a-fA-F]+)\)", onBin) | |
82 | |
83 def onStinks(nick, user, host, chan, matches): | |
84 messages = ["So do you!!!", "Shut up.", "You smell even worse.", "You really shouldn't be talking."] | |
85 irc.privmsg(nick, chan, choice(messages)) | |
86 | |
87 irc.onPrivmsg(".*" + config.nick + r":?( ?is| you)? stink(ing|s)?.*", onStinks) | |
88 | |
89 def onReload(nick, user, host, chan, matches): | |
90 if(host == "unaffiliated/thatotherpersony"): | |
91 subprocess.call(["git", "pull", "origin", "master"]); | |
92 irc.privmsg(nick, chan, "Pulled latest changes from GitHub. Restarting.") | |
93 exit() | |
94 elif(host == "unaffiliated/quu"): | |
95 irc.privmsg(nick, chan, "wat. Quu. derp.\nReally?\nInitializing spambot mode. >:D") | |
96 else: | |
97 irc.privmsg(nick, chan, "No. I don't wanna!") | |
98 | |
99 irc.onMsgToMe(".*reload.*", onReload) | |
100 | |
101 def onTest(nick, user, host, chan, matches): | |
102 irc.privmsg(nick, chan, "lolololol wat derp. ping Quu! ping mrout! Why not!") | |
103 | |
104 irc.onMsgToMe(".*test.*", onTest) | |
105 | |
106 def onRudeness(nick, user, host, chan, matches): | |
107 irc.privmsg(nick, chan, "Why don't you?") | |
108 | |
109 irc.onMsgToMe(".*stfu.*", onRudeness) | |
110 | |
111 def onHello(nick, user, host, chan, matches): | |
112 irc.privmsg(nick, chan, "Howdy!") | |
113 | |
114 irc.onMsgToMe(".*hello.*", onHello) | |
115 | |
116 def onSup(nick, user, host, chan, matches): | |
117 irc.privmsg(nick, chan, "I'm fine. How about you?") | |
118 | |
119 irc.onMsgToMe(".*(how.*you|sup|what.*up).*", onSup) |