def Execute(self, msg): tokens = msg.message.lower().split() if tokens[0] in self.customCommandList: util.LogReceived(msg.type, msg.user, msg.message, msg.tags, True) response = self.customCommandList[tokens[0]] if isinstance(response, dict): if msg.user in response: response = response[msg.user] else: response = response["other"] if isinstance(response, list): return random.choice(response) return response elif len(tokens) > 1 and (tokens[0] + " [ARG]") in self.customCommandList: util.LogReceived(msg.type, msg.user, msg.message, msg.tags, True) response = self.customCommandList[(tokens[0] + " [ARG]")].replace("[ARG]", tokens[1]) return response return None
def message_handler(self, m): # Check for proper message type if (m.type != "PRIVMSG" and m.type != "WHISPER"): return # Check for valid message with prefix and valid rewards validReward = "custom-reward-id" in m.tags validCommand = m.message != None and len( m.message) > 1 and m.message[0] in self.prefixes if (not validReward and not validCommand): return try: if validReward: util.LogReceived(m.type, m.user, m.message, m.tags) util.SendMessage(self.redeem[m.tags["custom-reward-id"]](m), m.type, m.user) if validCommand: # Retrieve first word without prefix m.message = m.message[1:] token = m.message.lower().split()[0] if (token in self.execute): util.LogReceived(m.type, m.user, m.message, m.tags, True) util.SendMessage(self.execute[token](m), m.type, m.user) return # Simple response commands # Note that we don't get this far unless the message does not match other commands response = self.commands["CustomCommands"].Execute(m) if response != None: util.SendMessage(response, m.type, m.user) return except Exception as e: ptf(f"Error: {e}", time=True)