I created a twitch chat bot and added some simple commands, but everytime someone uses an emoji like :flushed:
or :speak_no_evil:
the bot simply crashes. I guess it understands it as a word and crashes because of that.
My main code is like this:
import cfg
import utils
import socket
import re
import time, thread
from time import sleep
import os
def main():
s = socket.socket()
s.connect((cfg.HOST, cfg.PORT))
s.send("PASS {}\r\n".format(cfg.PASS).encode("utf-8"))
s.send("NICK {}\r\n".format(cfg.NICK).encode("utf-8"))
s.send("JOIN #{}\r\n".format(cfg.CHAN).encode("utf-8"))
CHAT_MSG = re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
utils.chat(s, "HeyGuys")
thread.start_new_thread(utils.threadFillOpList, ())
while True:
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"))
else:
username = re.search(r"\w+", response).group(0)
message = CHAT_MSG.sub("", response)
print(response)
if message.strip() == "!time":
utils.chat(s, "It currently " + time.strftime("%I:%M %p %Z"))
if "Kappa" in message and not "PogChamp" in message:
utils.chat(s, "Kappa")
if "PogChamp" in message and not "Kappa" in message:
utils.chat(s, "PogChamp")
if message.strip() == "!kb":
utils.chat(s, "Razer Blackwidow Tournament Edition.")
if message.strip() == "!skin":
utils.chat(s, "https://puu.sh/sjE7I/58820f8c10.osk")
if message.strip() == "!tablet":
utils.chat(s, "Wacom CTH490AK")
if message.strip() == "!area":
utils.chat(s, "https://puu.sh/sfr9E/1abc132c23.png")
if message.strip() == "!oldskin":
utils.chat(s, "https://puu.sh/sjEOD/5923cfabc0.osk")
if message.strip() == "!profile":
utils.chat(s, "https://osu.ppy.sh/u/3892208")
if message.strip() == "!np":
f = open("C:/Users/Grellheist/Desktop/osu stream/Files/np_playing_DL.txt", "r")
if(os.stat("C:/Users/Grellheist/Desktop/osu stream/Files/np_playing_DL.txt").st_size == 0):
utils.chat(s, "There is no map being played right now!")
else:
f = open("C:/Users/Grellheist/Desktop/osu stream/Files/np_playing_DL.txt", "r")
utils.chat(s, f.read())
if message.strip() == "!bot":
utils.chat(s, "I was created by Grellheist and was coded using Python 3.")
sleep(1)
if __name__ == "__main__":
main()
How do I get the bot to ignore these types of emoji?