-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTwitchPI
193 lines (163 loc) · 6.6 KB
/
TwitchPI
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
184
185
186
187
188
189
190
191
192
193
# Config portion
import socket
import time
import re
import pyttsx3
import PImp3
HOST = "irc.chat.twitch.tv" # the twitch irc server
PORT = 6667 # always use port 6667
NICK = "" # twitch bot username, lowercase
PASS = "" # your twitch OAuth token
CHAN = " " # YOUR twitch user name/channel
CHAN2 = "#" # the same as above but needed for some reason to get bot to also print chat (# is needed before the name)
# Message Rate
RATE = (20 / 30) # messages per second
#BANN HAMMER
PATT = [
r"swear",
# ...
r"some_pattern"
]
# bot.py portion
# Network functions go here
s = socket.socket()
s.connect((HOST, PORT))
s.send("PASS {}\r\n".format(PASS).encode("utf-8"))
s.send("NICK {}\r\n".format(NICK).encode("utf-8"))
s.send("JOIN {}\r\n".format(CHAN).encode("utf-8"))
s.send("JOIN {}\r\n".format(CHAN2).encode("utf-8")) #same reason as above for CHAN2
def chat(sock, msg):
'''
Send a chat message to the server.
sock -- the socket over which to send the message
msg -- the message to be sent
'''
sock.send("PRIVMSG #{} :{}\r\n".format(CHAN, msg).encode("utf-8"))
sock.send("PRIVMSG #{} : {}\r\n".format(CHAN2, msg).encode("utf-8")) #same reason as above for CHAN2
def ban(sock, user):
'''
Ban a user from the current channel.
sock -- the socket over which to send the ban command
user -- the user to be banned
'''
chat(sock, ".ban {}".format(user))
def timeout(sock, user, secs=10):
'''
Time out a user for a set period of time
sock -- the socket over which to send the timeout command
user -- the user to be timed out
secs -- the length of the timeout in seconds (default 600)
'''
chat(sock, ".timeout {}".format(user, secs))
# Make sure you prefix the quotes with an 'r'
CHAT_MSG = re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
chat(s,"CHANGE ME TO A NEW MESSAGE ON LINE 73")
while True:
response = s.recv(1024).decode("utf-8")
print(response)
if response == "PING :tmi.twitch.tv\r\n":
s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
else:
username = re.search(r"\w+", response).group(0) # return the entire match
message = CHAT_MSG.sub("", response)
print(username + " : " + message)
if message == response: #Keeps bot from posting a message in chat during PING/PONG
pass
##################### MP3 Effects ###################################
# checks for '!--' and plays associated effect in PImp3 module
'''' Commented out unless you decide to use the PImp3 module.
if '!wasted' in message:
PImp3.sounds0(message)
elif '!wrong' in message:
PImp3.sounds1(message)
elif '!toot' in message:
PImp3.sounds2(message)
elif '!pcfail' in message:
PImp3.sounds3(message)
elif '!surprise' in message:
PImp3.sounds4(message)
elif '!chewy' in message:
PImp3.sounds5(message)
elif '!lao' in message:
PImp3.sounds6(message)
elif '!scared' in message:
PImp3.sounds7(message)
elif '!focus' in message:
PImp3.sounds8(message)
elif '!gameover' in message:
PImp3.sounds9(message)
''''
#####################################################################
if '!' in message: # ignore reading song request
pass
elif 'http' in message: # ignore reading http links (which really is solved by streamelements below)
pass
elif ':tmi' in message: # ignore initial loading text (trust me, remove it and see how annoying it is)
pass
elif ':fuzzybottgaming' in message: # same as above
pass
elif 'fuzzybottgaming' in username: # ignores your bot if it posts anything
pass
elif 'streamelements' in username: # ignores your bot if it posts anything
pass
elif ':fuzzybuttgaming' in username: # ignores your username for testing
pass
elif 'fuzzy' in message:
chat(s, '(⊃─.─)⊃ Fight me @'+ username)
elif 'cute' in message:
chat(s,'(⊃0ω0)⊃♥ ')
elif 'old' in message:
chat(s,"(⊃┓⌐■_■)⊃ I'm too old for this sht")
elif 'lil man' in message:
chat(s,'(▪.▪)⊃† be gone Satan')
elif 'sup' in message:
chat(s,'(⌐■_■) sup')
#####################StreamElements Alerts###########################
elif 'Meow Meow Mother Fluffer' in message: # Part of Follower Alert from StreamElements
engine = pyttsx3.init()
sound = engine.getProperty('voices')
engine.setProperty('voice', sound[1].id) # 0= male 1=female
engine.say(username + " joined you in the litter box")
# engine.setProperty('rate', 120) # 120 words per minute
engine.setProperty('volume', 0.9)
engine.runAndWait()
elif 'just hosted the stream for' in message: # Alert to Hosts
engine = pyttsx3.init()
sound = engine.getProperty('voices')
engine.setProperty('voice', sound[1].id) # 0= male 1=female
engine.say(message)
engine.setProperty('rate', 120) # 120 words per minute
engine.setProperty('volume', 0.9)
engine.runAndWait()
elif 'just raided the channel with' in message: # Alert to Raids
engine = pyttsx3.init()
sound = engine.getProperty('voices')
engine.setProperty('voice', sound[1].id) # 0= male 1=female
engine.say(message)
engine.setProperty('rate', 120) # 120 words per minute
engine.setProperty('volume', 0.9)
engine.runAndWait()
###################################################################
elif '@FuzzyButtGaming' in message: # Alert to mentions only
engine = pyttsx3.init()
sound = engine.getProperty('voices')
engine.setProperty('voice', sound[1].id) # 0= male 1=female
message = message.replace('@FuzzyButtGaming', 'fuzzy', 2)
engine.say(username + " says " + message)
engine.setProperty('rate', 120) # 120 words per minute
engine.setProperty('volume', 0.9)
engine.runAndWait()
elif '@' in message: # Reads anything with @
engine = pyttsx3.init()
sound = engine.getProperty('voices')
engine.setProperty('voice', sound[1].id) # 0= male 1=female
engine.say(username + " says " + message)
engine.setProperty('rate', 120) # 120 words per minute
engine.setProperty('volume', 0.9)
engine.runAndWait()
# End TTS Bot
for pattern in PATT:
if re.match(pattern, message):
ban(s, username)
break
time.sleep(.1)