def run_commands(self,command_name,command_args,msg,status,output_enabled): script_module = modules.get_script_module(command_name) 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 script_module: if output_enabled == 'true': # Execute a module asynchronously def callback(output): msg.Chat.SendMessage(output) else: def callback(output): someVar = 'whatevs' script_module.run(msg, command_args, callback) else: phrases = ["I don't think I understand what you are asking for...","Is there a typo in that command? I don't know what you want. ","I didn't watch the show, i don't know what that means."] phrasenum = randint(0,2) msg.Chat.SendMessage(phrases[phrasenum])
def handle(self, msg, status): """Handle command messages. """ # If you are talking to yourself when testing # Ignore non-sent messages (you get both SENDING and SENT events) if status == "SENDING": return # Some Skype clients (iPad?) # double reply to the chat messages with some sort of ACK by # echoing them back # and we need to ignore them as they are not real chat messages # and not even displayed in chat UI if status == "READ": return # Check all stateful handlers for handler in modules.get_message_handlers(): processed = handler(msg, status) if processed: # Handler processed the message return # We need utf-8 for shlex body = ensure_unicode(msg.Body).encode('utf-8') logger.debug(u"Processing message, body %s" % msg.Body) # shlex dies on unicode on OSX with null bytes all over the string try: words = shlex.split(body, comments=False, posix=True) except ValueError: # ValueError: No closing quotation return words = [word.decode('utf-8') for word in words] if len(words) < 1: return command_name = words[0] command_args = words[1:] # Beyond this point we process script commands only if not command_name.startswith('!'): return command_name = command_name[1:] script_module = modules.get_script_module(command_name) 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 script_module: # Execute a module asynchronously def callback(output): if len(output) != 0: msg.Chat.SendMessage(output) script_module.run(msg, command_args, callback) else: msg.Chat.SendMessage("Don't know about command: !" + command_name)
def handle(self, msg, status): logger.info('Handle') """Handle command messages. """ # If you are talking to yourself when testing # Ignore non-sent messages (you get both SENDING and SENT events) if status == "SENDING": return # Some Skype clients (iPad?) # double reply to the chat messages with some sort of ACK by # echoing them back # and we need to ignore them as they are not real chat messages # and not even displayed in chat UI if status == "READ": return # Check all stateful handlers for handler in modules.get_message_handlers(): logger.info(str(handler)) processed = handler(msg, status) if processed: # Handler processed the message return # We need utf-8 for shlex body = ensure_unicode(msg.Body).encode('utf-8') # shlex dies on unicode on OSX with null bytes all over the string try: words = shlex.split(body, comments=False, posix=True) except ValueError: # ValueError: No closing quotation return words = [word.decode('utf-8') for word in words] if len(words) < 1: return command_name = words[0] command_args = words[1:] # Beyond this point we process script commands only if not command_name.startswith('!'): return command_name = command_name[1:] script_module = modules.get_script_module(command_name) 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 script_module: # Execute a module asynchronously def callback(output): msg.Chat.SendMessage(output) script_module.run(msg, command_args, callback) else: msg.Chat.SendMessage("Don't know about command: !" + command_name)
def handle(self, msg, status): """Handle command messages. """ # If you are talking to yourself when testing # Ignore non-sent messages (you get both SENDING and SENT events) if status == "SENDING": return # Some Skype clients (iPad?) # double reply to the chat messages with some sort of ACK by # echoing them back # and we need to ignore them as they are not real chat messages # and not even displayed in chat UI if status == "READ": return # Check all stateful handlers for handler in modules.get_message_handlers(): processed = handler(msg, status) if processed: # Handler processed the message return # We need utf-8 for shlex body = ensure_unicode(msg.Body).encode('utf-8') logger.debug(u"Processing message, body %s" % msg.Body) # shlex dies on unicode on OSX with null bytes all over the string try: words = shlex.split(body, comments=False, posix=True) except ValueError: # ValueError: No closing quotation return words = [word.decode('utf-8') for word in words] if len(words) < 1: return command_name = words[0] command_args = words[1:] ### Gong Li special power! (will not execute normal command) for word in words: gong_list = ["gong", "宮力", "宮博", "fish", "魚"] for gong in gong_list: if gong in word.lower(): command_name = "!gong" paris_list = ["巴黎", "paris", "法國", "france"] sf_list = ["舊金山", "sf", "san francisco"] bj_list = ["北京", "beijing", "中國", "china"] taipei_list = ["台北", "taipei", "台灣", "taiwan"] court_list = ["上訴", "法庭", "法律", "law"] news_list = ["新聞", "news"] yearend_list = ["尾牙", "year-end", "yearend"] for paris in paris_list: if paris in word.lower(): command_name = "!gong" command_args.append("paris") for sf in sf_list: if sf in word.lower(): command_name = "!gong" command_args.append("sf") for bj in bj_list: if bj in word.lower(): command_name = "!gong" command_args.append("bj") for tp in taipei_list: if tp in word.lower(): command_name = "!gong" command_args.append("tp") for court in court_list: if court in word.lower(): command_name = "!gong" command_args.append("court") for news in news_list: if news in word.lower(): command_name = "!gong" command_args.append("news") for yearend in yearend_list: if yearend in word.lower(): command_name = "!gong" command_args.append("yearend") # Only 3% of possibility to trigger POWER OF GONG if command_name == "!gong": if random.randint(1, 100) < 97: return ### End of Gong Li special power! # Beyond this point we process script commands only if not command_name.startswith('!'): return command_name = command_name[1:] script_module = modules.get_script_module(command_name) 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 script_module: # Execute a module asynchronously def callback(output): msg.Chat.SendMessage(output) script_module.run(msg, command_args, callback) else: #msg.Chat.SendMessage("Don't know about command: !" + command_name) pass