-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadchat
executable file
·193 lines (160 loc) · 5.54 KB
/
readchat
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
#!/usr/bin/python3
# reads chat without a browser
# shows colors on messages
# can also use espeak to read the messages to you and say who said them
# pip3 install python-socketio colorama
# https://python-socketio.readthedocs.io/en/latest/client.html#installation
# blue with white background (((them)))
# rainbow ==text==
# add ignore channel option
# add tts support
import socketio
import colorama
import json
import re
import html
import pyttsx3
listen_channel = 'markpugner'
readAllAlerts = True
def check_ignore_users(user):
# opens the users file and checks if they are ignored
try:
with open('users') as f:
for uname in f:
if uname.strip('\n').lower() == user.lower():
return True
return False
except:
return False
def check_ignore_channel(channel):
# opens the channels file and checks if they are ignored
try:
with open('channels') as f:
for uname in f:
if uname.strip('\n').lower() == channel.lower():
return True
return False
except:
return False
def check_tts_on():
try:
with open('tts') as f:
return True
return False
except:
return False
def clean_emotes(message):
# data-emote-tooltip="SIR" title="SIR" alt="SIR"
# just search for the alt that we want...
# so the regex works if there is text before and after the emote
imagetags = re.findall(r'<img\/?[^>]*>', message)
#print(imagetags)
for img in imagetags:
#print('image tag matched:',img)
matches = re.findall(r'\salt="([^"]+)"', img)
for match in matches:
print('Found matches:', match)
#re.sub("<\/?[^>]*>", ':'+match+':',message);
# should check if the match has colons in it or not already
if ':' in match:
message = message.replace(img, ' '+match+'', 1)
else:
message = message.replace(img, ' :'+match+':', 1)
#print('message:', message)
return message
def unescape(s):
return html.unescape(s)
def getChannel(message):
msg = ''
try:
msg = message["channel"]
msg = clean_emotes(msg)
msg = re.sub("<\/?[^>]*>", '',msg);
#msg = re.sub("((https?:\/\/)|(www\.))[^\s]+", '',msg);
except:
msg = ''
return msg
def getMessage(message):
msg = ''
try:
msg = message["message"]
msg = clean_emotes(msg)
msg = re.sub("<\/?[^>]*>", '',msg);
#msg = re.sub("((https?:\/\/)|(www\.))[^\s]+", '',msg);
except:
msg = ''
return msg
def getFrom(message):
msg = ''
try:
msg = message["username"]
msg = clean_emotes(msg)
msg = re.sub("<\/?[^>]*>", '',msg);
msg = re.sub("((https?:\/\/)|(www\.))[^\s]+", '',msg);
except:
msg = ''
return msg
sio = socketio.Client()
tts = pyttsx3.init()
messages = []
saying = False
def say(user,message):
try:
if False:
messages.append(message)
else:
if check_tts_on():
#saying = True
tts.say(user + " says " + message)
tts.runAndWait()
#saying = False
except:
pass
saying = False
def myread(message,uname):
if not check_ignore_users(uname):
if len(message) > 0 and message[0] == '>':
print(colorama.Fore.RED + uname + " says:\n" + colorama.Fore.GREEN + message)
elif len(message) > 0 and message[0] == '<':
print(colorama.Fore.RED + uname + " says:\n" + colorama.Fore.RED + message)
else:
#print(colorama.Fore.RED + uname + " says:\n" + colorama.Fore.BLUE + message)
print(colorama.Fore.RED + uname + " says:\n" + colorama.Fore.WHITE + message)
say(uname,message)
@sio.event
def connect():
print('connection established')
# user profile:nulling recaptcha:null, page 'global', token: null
@sio.event
def bulkmessage(data):
#print('message received with ', data)
#logmessages(data)
#sio.emit('my response', {'response': 'my response'})
# should look at if the message was at the bot then parse the message to get the command
for message in data:
# Get a response to an input statement
if not check_ignore_channel(getChannel(message)):
#print("msg: ", getMessage(message))
myread(unescape(getMessage(message)),getFrom(message))
#print("resp: ", chatbot.get_response(getMessage(message)))
@sio.on('alert')
def process_channel_alerts(data):
global listen_channel
global readAllAlerts
if data['channel'].lower() == listen_channel or readAllAlerts:
if data['color'] == 'red':
say("Pay Pig Red",data['message'])
print(colorama.Back.RED + "Red Alert:",data['message'] + colorama.Back.BLACK)
if data['color'] == 'blue':
say("Pay Pig Blue",data['message'])
print(colorama.Back.BLUE + "Blue Alert:",data['message']+ colorama.Back.BLACK)
if data['color'] == 'grey':
say("Pay Pig Grey",data['message'])
print(colorama.Back.LIGHTBLACK_EX + "Grey Alert:",data['message']+ colorama.Back.BLACK)
if data['color'] == 'yellow':
say("Pay Pig Yellow",data['message'])
print(colorama.Back.YELLOW + "Yellow Alert:",data['message']+ colorama.Back.BLACK)
print("should connect...")
sio.connect('https://chat.bitwave.tv',transports='websocket')
print("wainting for events...")
sio.wait()