def _message_handler(self, data: bytes) -> None: if not self.joined: self.irc.join_channel(self.channel) self.joined = True message = data.decode("UTF-8").strip('\n\r') if message.find('PRIVMSG') >= 0: name = message.split('!', 1)[0][1:] message = message.split('PRIVMSG', 1)[1].split(':', 1)[1] self.on_next( chat.Message(channel=self.channel, sender=name, text=message, helix_api=self.helix))
def _message_handler(self, data: bytes) -> None: # First messages are server connection messages, # which should be handled by joining the chat room. if not self.joined: self.irc.join_channel(self.channel) self.joined = True text = data.decode("UTF-8").strip('\n\r') if text.find('PRIVMSG') >= 0: sender = text.split('!', 1)[0][1:] message = text.split('PRIVMSG', 1)[1].split(':', 1)[1] self.on_next( chat.Message(channel=self.channel, sender=sender, text=message, helix_api=self.helix, chat=self))
def _message_handler(self, data: bytes) -> None: # First messages are server connection messages, # which should be handled by joining the chat room. if not self.joined: if isinstance(self.channel, str): self.irc.join_channel(self.channel) self.joined = True elif isinstance(self.channel, list): for chan in self.channel: self.irc.join_channel(chan) self.joined = True text = data.decode("UTF-8").strip('\n\r') # Handler for normal chat messages, send via PRIVMSG if text.find('PRIVMSG') >= 0: c = text.split(' PRIVMSG ', 1)[1].split()[0].lstrip('#') s = text.split(' ', 1) tags = s[0][1:].split(';') msg = s[1] t = {} for tag in tags: i, d = tag.split('=') t[i] = d sender = msg.split('!', 1)[0][1:] message = msg.split('PRIVMSG', 1)[1].split(':', 1)[1] self.on_next( chat.Message(message_type=chat.MessageType.CHAT, channel=c, sender=sender, text=message, tags=t, helix_api=self.helix, chat=self, raw=text) ) # Handles chat commands if capture_commands is True elif self.capture_commands and ':tmi.twitch.tv' in text: tags, cmd = text.split(":tmi.twitch.tv", 1) args = cmd.strip().split(" ") cmd_type = None msg = None if args[0] == "CLEARCHAT": cmd_type = chat.CommandType.CLEARCHAT if len(args) >= 3: msg = args[2][1:] elif args[0] == "CLEARMSG": cmd_type = chat.CommandType.CLEARMSG if len(args) >= 3: msg = args[2][1:] elif args[0] == "HOSTTARGET": cmd_type = chat.CommandType.HOSTTARGET if len(args) >= 3: msg = " ".join(args[2])[1:] elif args[0] == "NOTICE": cmd_type = chat.CommandType.NOTICE msg = " ".join(args[2:])[1:] elif args[0] == "RECONNECT": cmd_type = chat.CommandType.RECONNECT elif args[0] == "ROOMSTATE": cmd_type = chat.CommandType.ROOMSTATE elif args[0] == "USERNOTICE": cmd_type = chat.CommandType.USERNOTICE if len(args) >= 3: msg = " ".join(args[2:])[1:] elif args[0] == "USERSTATE": cmd_type = chat.CommandType.USERSTATE else: # print("Command else", text) return c = args[1].lstrip('#') t = {} if ';' in tags: for tag in tags[1:].split(';'): i, d = tag.split('=') t[i] = d self.on_next( chat.Message(message_type=chat.MessageType.COMMAND, channel=c, sender=None, text=msg, tags=t, helix_api=self.helix, chat=self, command_type=cmd_type, raw=text) )