def handle_command(self, event): """Handle command messages""" # is commands_enabled? config_commands_enabled = self.bot.get_config_suboption(event.conv_id, 'commands_enabled') tagged_ignore = "ignore" in self.bot.tags.useractive(event.user_id.chat_id, event.conv_id) if not config_commands_enabled or tagged_ignore: admins_list = self.bot.get_config_suboption(event.conv_id, 'admins') or [] # admins always have commands enabled if event.user_id.chat_id not in admins_list: return # ensure bot alias is always a list if not isinstance(self.bot_command, list): self.bot_command = [self.bot_command] # check that a bot alias is used e.g. /syrupbot if not event.text.split()[0].lower() in self.bot_command: return # Parse message event.text = event.text.replace(u'\xa0', u' ') # convert non-breaking space in Latin1 (ISO 8859-1) try: line_args = shlex.split(event.text, posix=False) except Exception as e: logger.exception(e) yield from self.bot.coro_send_message(event.conv, _("{}: {}").format( event.user.full_name, str(e))) return # Test if command length is sufficient if len(line_args) < 2: yield from self.bot.coro_send_message(event.conv, _('{}: Missing parameter(s)').format( event.user.full_name)) return commands = command.get_available_commands(self.bot, event.user.id_.chat_id, event.conv_id) supplied_command = line_args[1].lower() if supplied_command in commands["user"]: pass elif supplied_command in commands["admin"]: pass elif supplied_command in command.commands: yield from command.blocked_command(self.bot, event, *line_args[1:]) return else: yield from command.unknown_command(self.bot, event, *line_args[1:]) return # Run command results = yield from command.run(self.bot, event, *line_args[1:]) if "acknowledge" in dir(event): for id in event.acknowledge: yield from self.run_reprocessor(id, event, results)
def handle_command(self, event): """Handle command messages""" # is commands_enabled? if not self.bot.get_config_suboption(event.conv_id, 'commands_enabled'): admins_list = self.bot.get_config_suboption( event.conv_id, 'admins') or [] # admins always have commands enabled if event.user_id.chat_id not in admins_list: return # ensure bot alias is always a list if not isinstance(self.bot_command, list): self.bot_command = [self.bot_command] # check that a bot alias is used e.g. /bot if not event.text.split()[0].lower() in self.bot_command: return # Parse message event.text = event.text.replace( u'\xa0', u' ') # convert non-breaking space in Latin1 (ISO 8859-1) try: line_args = shlex.split(event.text, posix=False) except Exception as e: logger.exception(e) yield from self.bot.coro_send_message( event.conv, _("{}: {}").format(event.user.full_name, str(e))) return # Test if command length is sufficient if len(line_args) < 2: yield from self.bot.coro_send_message( event.conv, _('{}: Missing parameter(s)').format(event.user.full_name)) return commands = command.get_available_commands(self.bot, event.user.id_.chat_id, event.conv_id) supplied_command = line_args[1].lower() if supplied_command in commands["user"]: pass elif supplied_command in commands["admin"]: pass elif supplied_command in command.commands: yield from command.blocked_command(self.bot, event, *line_args[1:]) return else: yield from command.unknown_command(self.bot, event, *line_args[1:]) return # Run command results = yield from command.run(self.bot, event, *line_args[1:]) if "acknowledge" in dir(event): for id in event.acknowledge: yield from self.run_reprocessor(id, event, results)
def handle_command(self, event): """Handle command messages""" # is commands_enabled? config_commands_enabled = self.bot.get_config_suboption( event.conv_id, 'commands_enabled') tagged_ignore = "ignore" in self.bot.tags.useractive( event.user_id.chat_id, event.conv_id) if not config_commands_enabled or tagged_ignore: admins_list = self.bot.get_config_suboption( event.conv_id, 'admins') or [] # admins always have commands enabled if event.user_id.chat_id not in admins_list: return # ensure bot alias is always a list if not isinstance(self.bot_command, list): self.bot_command = [self.bot_command] # check that a bot alias is used e.g. /bot if not event.text.split()[0].lower() in self.bot_command: if self.bot.conversations.catalog[event.conv_id][ "type"] == "ONE_TO_ONE" and self.bot.get_config_option( 'auto_alias_one_to_one'): event.text = u" ".join(( self.bot_command[0], event.text)) # Insert default alias if not already present else: return # Parse message event.text = event.text.replace( u'\xa0', u' ') # convert non-breaking space in Latin1 (ISO 8859-1) try: line_args = shlex.split(event.text, posix=False) except Exception as e: logger.exception(e) yield from self.bot.coro_send_message( event.conv, _("{}: {}").format(event.user.full_name, str(e))) return # Test if command length is sufficient if len(line_args) < 2: config_silent = bot.get_config_suboption(event.conv.id_, 'silentmode') tagged_silent = "silent" in bot.tags.useractive( event.user_id.chat_id, event.conv.id_) if not (config_silent or tagged_silent): yield from self.bot.coro_send_message( event.conv, _('{}: Missing parameter(s)').format(event.user.full_name)) return commands = command.get_available_commands(self.bot, event.user.id_.chat_id, event.conv_id) supplied_command = line_args[1].lower() if supplied_command in commands["user"]: pass elif supplied_command in commands["admin"]: pass elif supplied_command in command.commands: yield from command.blocked_command(self.bot, event, *line_args[1:]) return else: yield from command.unknown_command(self.bot, event, *line_args[1:]) return # Run command results = yield from command.run(self.bot, event, *line_args[1:]) if "acknowledge" in dir(event): for id in event.acknowledge: yield from self.run_reprocessor(id, event, results)