-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
183 lines (148 loc) · 7.36 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env python
import config
import utility
import socket
import time
import re
import concurrent.futures
import main2
from secrets import secrets
from function_library import *
CHAT_MSG = re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
class IRCConn:
def __init__(self, channel):
try:
self.sock = socket.socket()
self.sock.settimeout(1.5)
self.sock.connect((config.HOST, config.PORT))
self.sock.send("PASS {}\r\n".format(secrets.PASS).encode("utf-8"))
self.sock.send("NICK {}\r\n".format(config.NICK).encode("utf-8"))
self.sock.send("JOIN {}\r\n".format(channel).encode("utf-8"))
self.connected = True #Socket succefully connected
except Exception as e:
print(str(e))
self.connected = False #Socket failed to connect
def bot_loop():
sockets = []
for chan in config.CHANNELS:
newsocket = IRCConn(chan)
sockets.append(newsocket)
if newsocket.connected is True:
connected = True
while connected:
for irc in sockets:
try:
response = irc.sock.recv(1024).decode("utf-8")
except Exception as e:
print(str(e))
response = ""
continue
functions_to_run = []
if response == "PING :tmi.twitch.tv\r\n":
irc.sock.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
print("Pong")
else:
username = re.search(r"\w+", response).group(0)
message = CHAT_MSG.sub("", response)
print(username + ": " + response)
for pattern in config.COMMANDS:
if re.match(pattern[0], message):
utility.chat(s, pattern[1])
for pattern in config.NEO:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop1)
for pattern in config.NEO2:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop2)
for pattern in config.NEO3:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop3)
for pattern in config.NEO4:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop4)
for pattern in config.NEO5:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop5)
for pattern in config.NEO6:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop6)
for pattern in config.NEO7:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop7)
for pattern in config.NEO8:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop8)
for pattern in config.NEO9:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop9)
for pattern in config.NEO10:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop10)
for pattern in config.NEO11:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop11)
for pattern in config.NEO12:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop12)
for pattern in config.NEO13:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop13)
for pattern in config.NEO14:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop14)
for pattern in config.NEO15:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop15)
for pattern in config.NEO16:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop16)
for pattern in config.NEO17:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_loop17)
for pattern in config.MATRIX01:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_progmem_run("BombJack"))
for pattern in config.MATRIX02:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_progmem_run("Qbert"))
for pattern in config.MATRIX03:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_progmem_run("DigDug"))
for pattern in config.MATRIX04:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_progmem_run("Link",5,0.2))
for pattern in config.MATRIX05:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_progmem_run("Mario",20,0.1))
for pattern in config.MATRIX06:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_progmem_run("Kirby",5,0.1))
for pattern in config.MATRIX07:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_progmem_run("Frog",5,0.1))
for pattern in config.MATRIX08:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_progmem_run("Vinyl",5,0.1))
for pattern in config.MATRIX09:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_progmem_run("Heartbeat",5,0.1))
for pattern in config.MATRIX10:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_progmem_run("Poo",5,0.1))
for pattern in config.MATRIX11:
if re.match(pattern[0], message):
functions_to_run.append(main2.neo_progmem_run("FireMush",10,0.1) )
for pattern in config.BLANK:
if re.match(pattern[0], message):
functions_to_run.append(main2.blank)
for pattern in config.BAN_PAT:
if re.match(pattern, message):
utility.ban(s, username)
break
with concurrent.futures.ProcessPoolExecutor(max_workers=5) as executor:
# Start the load operations and mark each future with its URL
for pattern in functions_to_run:
executor.submit(pattern)
time.sleep(1 / config.RATE)
if __name__ == "__main__":
bot_loop()