def handleMessages(self, msg, status): """ Handle incoming messages """ if status == "RECEIVED" or status == "SENT": logger.debug("%s - %s - %s: %s" % (status, msg.Chat.FriendlyName, msg.FromHandle, msg.Body)) if status in ["RECEIVED", "SENT"] and msg.Body: words = msg.Body.split() if len(words) < 0: return keyword = words[0] if not keyword.startswith("!"): return keyword = keyword[1:] logger.debug("Trying to identify keyword: %s" % keyword) if keyword == "reload": commands = modules.load_modules() msg.Chat.SendMessage("Available commands: %s" % ", ".join(commands)) return if modules.is_module(keyword): # Execute module asynchronously def callback(output): msg.Chat.SendMessage(output) modules.run_module(keyword, words[1:], callback) return if msg.Body == "!loadModules": msg.Chat.SendMessage("Loading modules...") try: modules.load_modules() except Exception as e: msg.Chat.SendMessage(str(e)) return return elif msg.Body == "!loadChats": self.cacheChats() return
def handleMessages(self, msg, status): """ Handle incoming messages """ if status == "RECEIVED" or status == "SENT": logger.debug("%s - %s - %s: %s" % (status, msg.Chat.FriendlyName, msg.FromHandle, msg.Body)) if status in ["RECEIVED", "SENT"] and msg.Body: body = msg.Body.encode("utf-8") # shlex dies on unicode on OSX with null bytes all over the string words = shlex.split(body, comments=False, posix=True) if len(words) < 0: return keyword = words[0] if not keyword.startswith("!"): return keyword = keyword[1:] logger.debug("Trying to identify keyword: %s" % keyword) # reload must be built in if keyword == "reload": commands = modules.load_modules() msg.Chat.SendMessage("Available commands: %s" % ", ".join(commands)) return if modules.is_module(keyword): # Execute module asynchronously def callback(output): msg.Chat.SendMessage(output) modules.run_module(keyword, words[1:], callback) return else: msg.Chat.SendMessage("Don't know about command: !" + keyword) # XXX: Deprecated. See if we can rid of this if body == "!loadChats": self.cacheChats() return
def handle(self, msg, status): """Handle command messages. """ body = msg.Body.encode('utf-8') # shlex dies on unicode on OSX with null bytes all over the string words = shlex.split(body, comments=False, posix=True) words = [word.decode('utf-8') for word in words] if len(words) < 1: return command_name = words[0] command_args = words[1:] if not command_name.startswith('!'): return command_name = command_name[1:] if command_name in self.builtins: # Execute a built-in command logger.debug('Executing built-in command {}: {}'.format(command_name, command_args)) self.builtins[command_name](command_args, msg, status) elif modules.is_module(command_name): # Execute a module asynchronously def callback(output): msg.Chat.SendMessage(output) modules.run_module(command_name, command_args, callback) else: msg.Chat.SendMessage("Don't know about command: !" + command_name)