def loop(self): # Alert loop while True: resp = sock.recv(2048).decode('utf-8') if resp.startswith('PING'): sock.send("PONG\n".encode('utf-8')) elif len(resp) > 0: self.parsechat(resp) global lastAlert if not window.foreground() and time.time() - lastAlert > DELAY: if ALERT_SOUND: sound.alert() if ALERT_RUMBLE: rumble.alert() lastAlert = time.time()
def loop(): while True: global lastAlert resp = sock.recv(2048).decode('utf-8') if resp.startswith('PING'): sock.send("PONG\n".encode('utf-8')) elif len(resp) > 0: parseChat(resp) if not window.foreground() and time.time() - lastAlert > DELAY: if ALERT_SOUND == "True": sound.alert(SOUND_FILE) if ALERT_RUMBLE == "True": rumble.alert() lastAlert = time.time()
def run(self): # Forever loop that monitors chat. Hopefully stable? while True: global Image if Image[1] == True: print("ech") resp = sock.recv(2048).decode('utf-8') if resp.startswith('PING'): sock.send("PONG\n".encode('utf-8')) elif len(resp) > 0: parsechat(resp) global lastAlert if not window.foreground() and time.time() - lastAlert > DELAY: if ALERT_SOUND: sound.alert() if ALERT_RUMBLE: rumble.alert() lastAlert = time.time()
sock = socket.socket() sock.connect(('irc.chat.twitch.tv', 6667)) sock.send(f"NICK justinfan0\n".encode('utf-8')) sock.send(f"JOIN {CHANNEL}\n".encode('utf-8')) lastAlert = 0 def parseChat(resp): resp = resp.rstrip().split('\r\n') for line in resp: if "PRIVMSG" in line: user = line.split(':')[1].split('!')[0] msg = line.split(':', maxsplit=2)[2] line = user + ": " + msg print(line) while True: resp = sock.recv(2048).decode('utf-8') if resp.startswith('PING'): sock.send("PONG\n".encode('utf-8')) elif len(resp) > 0: parseChat(resp) if not window.foreground() and time.time() - lastAlert > DELAY: if ALERT_SOUND: sound.alert() if ALERT_RUMBLE: rumble.alert() lastAlert = time.time()