def handle_command(self, event): """Handle command messages""" # verify user is an admin admins_list = self.bot.get_config_suboption(event.conv_id, 'admins') initiator_is_admin = False if event.user_id.chat_id in admins_list: initiator_is_admin = True # Test if command handling is enabled # note: admins always bypass this check if not initiator_is_admin: if not self.bot.get_config_suboption(event.conv_id, 'commands_enabled'): return if not isinstance(self.bot_command, list): # always a list self.bot_command = [self.bot_command] 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: print("EXCEPTION in {}: {}".format("handle_command", e)) self.bot.send_message_parsed( event.conv, _("{}: {}").format(event.user.full_name, str(e))) logger.exception(e) return # Test if command length is sufficient if len(line_args) < 2: self.bot.send_message_parsed( event.conv, _('{}: Missing parameter(s)').format(event.user.full_name)) return # only admins can run admin commands commands_admin_list = command.get_admin_commands( self.bot, event.conv_id) if commands_admin_list and line_args[1].lower() in commands_admin_list: if not initiator_is_admin: self.bot.send_message_parsed( event.conv, _('{}: Can\'t do that.').format(event.user.full_name)) return # Run command yield from command.run(self.bot, event, *line_args[1:])
def handle_command(self, event): """Handle command messages""" # verify user is an admin admins_list = self.bot.get_config_suboption(event.conv_id, 'admins') initiator_is_admin = False if event.user_id.chat_id in admins_list: initiator_is_admin = True # Test if command handling is enabled # note: admins always bypass this check if not initiator_is_admin: if not self.bot.get_config_suboption(event.conv_id, 'commands_enabled'): return if not isinstance(self.bot_command, list): # always a list self.bot_command = [self.bot_command] 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: print("EXCEPTION in {}: {}".format("handle_command", e)) self.bot.send_message_parsed(event.conv, _("{}: {}").format( event.user.full_name, str(e))) logger.exception(e) return # Test if command length is sufficient if len(line_args) < 2: self.bot.send_message_parsed(event.conv, _('{}: Missing parameter(s)').format( event.user.full_name)) return # only admins can run admin commands commands_admin_list = command.get_admin_commands(self.bot, event.conv_id) if commands_admin_list and line_args[1].lower() in commands_admin_list: if not initiator_is_admin: self.bot.send_message_parsed(event.conv, _('{}: Can\'t do that.').format( event.user.full_name)) return # Run command yield from command.run(self.bot, event, *line_args[1:])
def get_admin_commands(self, conversation_id): logger.debug("[LEGACY] command.get_admin_commands()" " instead of handlers.get_admin_commands()") return command.get_admin_commands(self.bot, conversation_id)
def get_admin_commands(self, conversation_id): logger.debug( "[LEGACY] command.get_admin_commands()" " instead of handlers.get_admin_commands()") return command.get_admin_commands(self.bot, conversation_id)
def get_admin_commands(self, conversation_id): print("LEGACY handlers.get_admin_commands(): use command.get_admin_commands") return command.get_admin_commands(self.bot, conversation_id)
def get_admin_commands(self, conversation_id): print( "LEGACY handlers.get_admin_commands(): use command.get_admin_commands" ) return command.get_admin_commands(self.bot, conversation_id)