forked from stephenangelico/twitchpixelpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
85 lines (69 loc) · 2.62 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
#!/usr/bin/env python
import config
import utility
import socket
import time
import re
import main2
from function_library import *
CHAT_MSG = re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
try:
s = socket.socket()
s.connect((config.HOST, config.PORT))
s.send("PASS {}\r\n".format(config.PASS).encode("utf-8"))
s.send("NICK {}\r\n".format(config.NICK).encode("utf-8"))
s.send("JOIN {}\r\n".format(config.CHAN).encode("utf-8"))
connected = True #Socket succefully connected
except Exception as e:
print(str(e))
connected = False #Socket failed to connect
def bot_loop():
while connected:
response = s.recv(1024).decode("utf-8")
if response == "PING :tmi.twitch.tv\r\n":
s.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):
main2.neo_loop1()
for pattern in config.NEO2:
if re.match(pattern[0], message):
main2.neo_loop2()
for pattern in config.NEO3:
if re.match(pattern[0], message):
main2.neo_loop3()
for pattern in config.NEO4:
if re.match(pattern[0], message):
main2.neo_loop4()
for pattern in config.NEO5:
if re.match(pattern[0], message):
main2.neo_loop5()
for pattern in config.NEO6:
if re.match(pattern[0], message):
main2.neo_loop6()
for pattern in config.NEO7:
if re.match(pattern[0], message):
main2.neo_loop7()
for pattern in config.NEO8:
if re.match(pattern[0], message):
main2.neo_loop8()
for pattern in config.NEO9:
if re.match(pattern[0], message):
main2.neo_loop9()
for pattern in config.BLANK:
if re.match(pattern[0], message):
main2.blank()
for pattern in config.BAN_PAT:
if re.match(pattern, message):
utility.ban(s, username)
break
time.sleep(1 / config.RATE)
if __name__ == "__main__":
bot_loop()