def create_clip(channel, channel_id, username): # if twitch.is_stream_live(channel_id): if True: clip_id = twitch.create_clip(channel_id) time.sleep(5) if clip_id and twitch.is_there_clip(clip_id): clip_proccess_thread = threading.Timer(0, proccess_clip, args=[clip_id, username, channel]) clip_proccess_thread.start() else: debug.output_debug("Second try") clip_id = twitch.create_clip(channel_id) time.sleep(10) if (clip_id): clip_proccess_thread = threading.Timer(0, proccess_clip, args=[clip_id, username, channel]) clip_proccess_thread.start() else: utility.chat(s, channel, "Sorry " + username + ", couldn't make your clip") else: utility.chat(s, channel, username + ", the stream is offline, clipping is disabled.")
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.COLOUR: if re.match(pattern[0], message): subprocess.call("tplight hex 192.168.0.21 '#6441a5'", shell=True) for pattern in config.BAN_PAT: if re.match(pattern, message): utility.ban(s, username) break print(config.RATE) time.sleep(1 / config.RATE)
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)
def proccess_clip(clip_id, username, channel_name): if twitch.is_there_clip(clip_id): clip_url = "https://clips.twitch.tv/" + clip_id utility.chat(s, channel_name, clip_url) utility.write_tofile(clip_url + "\n") else: utility.chat(s, channel_name, "Sorry " + username + ", Twitch couldn't make the clip.")
def bot_loop(): while connected: response = s.recv(1024).decode("utf-8") utility.chat(s,"I'm Joined") 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.BAN_PAT: if re.match(pattern, message): utility.ban(s, username) break time.sleep(1 / config.RATE)
def bot_loop(): bulb.stop_music() print("Music mode off.") bulb.start_music(0) print("Music mode on.") 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.search(pattern[0], message) and (username == "streamlabs" or username == "cr0sis"): utility.chat(s, pattern[1]) if (pattern[0] == '!default'): utility.default() if (pattern[0] == 'subscribed'): utility.sub() if (pattern[0] == 'following'): utility.flicker() if (pattern[0] == '!day'): utility.day() if (pattern[0] == '!nm'): utility.night() if (pattern[0] == '!warm'): utility.warm() if (pattern[0] == 'tipped'): utility.tipped() if (pattern[0] == 'cheered'): utility.flicker() if (pattern[0] == 'raided'): utility.sub() if (pattern[0] == 'gifted'): utility.tipped() if (pattern[0] == 'hosted'): utility.sub() break time.sleep(1 / config.RATE)
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 + ": " + message) # Ban pattern check for pat in pattern.BAN_PAT: if re.match(pat, message): utility.ban(s, username) utility.chat(s,"Tap, tap, tap. Nevermore. " + username + " banned") break # Time out pattern check for pat in pattern.TO_PAT: if re.match(pat, message): utility.timeout(s, username) utility.chat(s,"Caw caw! " + username + " silence! You know what you've done...") break # Command check if re.match(r'^(![A-Z,a-z])\w', message): # Check if command exists if message.strip() in command_list: utility.runCommand(s, message.strip(), command_list[message.strip()]) else: # New command check if re.match(r'^(![A-Z,a-z])\w+\s([A-Z,a-z])', message): command = message.split(" ", 1)[0] action = message.split(" ", 1)[1] utility.newCommand(s, command, action, command_list.keys()) command_list[command] = action print("A new command: " + command + " action: " + action) else: utility.chat(s, "Command doesn't exists") time.sleep(1 / config.RATE)
def bot_loop(): time.sleep(1) utility.print_toscreen("Starting Bot Loop") while connected: response = "" try: response = s.recv(1024).decode("utf-8") except Exception as e: debug.output_error(debug.lineno() + " - " + str(e)) utility.restart() # PING-PONG if re.search("PING :tmi.twitch.tv",response): try: s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8")) # utility.print_toscreen("Pong") # debug.output_debug ("PONG") utility.print_usertoscreen("server", "twitch", "ping") except IOError as e: debug.output_error(debug.lineno() + " - " + "PONG error " + str(e)) utility.restart() find_all_twitch = re.findall(TWITCH_MSG, response) for found in find_all_twitch: username = "" channel = "" message = "" try: message = response[response.find(found) + len(found):] start = re.search(TWITCH_MSG, message) if start: message = message[0:start.start()] else: message = message if re.search("PRIVMSG",found): channel = re.search(r"#\w+", found).group(0) username = re.search(r"\w+", found).group(0) utility.print_usertoscreen(channel, username, message.rstrip()) else: utility.print_usertoscreen("server", "twitch", message.strip()) message = message.lower().rstrip() except Exception as e: debug.output_error(debug.lineno() + " - " + str(e)) # clip | !clip if message == "!clip" or message == "clip" or message == "clip it": channel_id = CHAT_NAMES_TO_ID[channel] debug.output_debug(channel + " | " + username + ": " + message) clip_thread = threading.Timer(5, create_clip, args=[channel, channel_id, username]) clip_thread.start() # !Hey # if message == "!hey" or message == "hi" or message == "hey" or message == "hello" or message == "heyguys": # utility.chat(s, channel, "Hey " + username + ", Welcome to the stream!") # utility.print_toscreen(CHAT_NAMES_TO_ID[channel]) # !help if message == "!help": utility.chat(s, channel, "Hi, I'm the clipping bot. type \"clip\" or \"!clip\" in chat, I'll clip the last 25 sec and post the link.") if re.search(config.TWITCH_NICK, message): debug.output_debug(channel + " | " + username + ": " + message)
import utility import socket import time import re 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 utility.chat(s,"I'm Joined") 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") utility.chat(s,"I'm Joined") 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)