def commands(**options): from pajbot.models.command import CommandManager from pajbot.models.module import ModuleManager bot_commands = CommandManager(socket_manager=None, module_manager=ModuleManager(None).load(), bot=None).load(enabled=None) bot_commands_list = bot_commands.parse_for_web() custom_commands = [] point_commands = [] moderator_commands = [] for command in bot_commands_list: if command.id is None: continue if command.level > 100 or command.mod_only: moderator_commands.append(command) elif command.cost > 0: point_commands.append(command) else: custom_commands.append(command) return render_template('admin/commands.html', custom_commands=sorted(custom_commands, key=lambda f: f.command), point_commands=sorted(point_commands, key=lambda a: (a.cost, a.command)), moderator_commands=sorted( moderator_commands, key=lambda c: (c.level if c.mod_only is False else 500, c.command)), created=session.pop('command_created_id', None), edited=session.pop('command_edited_id', None))
def commands(**options): from pajbot.models.command import CommandManager from pajbot.models.module import ModuleManager bot_commands = CommandManager( socket_manager=None, module_manager=ModuleManager(None).load(), bot=None).load(enabled=None) bot_commands_list = bot_commands.parse_for_web() custom_commands = [] point_commands = [] moderator_commands = [] for command in bot_commands_list: if command.id is None: continue if command.level > 100 or command.mod_only: moderator_commands.append(command) elif command.cost > 0: point_commands.append(command) else: custom_commands.append(command) with DBManager.create_session_scope() as db_session: commands_data = db_session.query(CommandData).options(joinedload(CommandData.user), joinedload(CommandData.user2)).all() return render_template( 'admin/commands.html', commands_data=commands_data, custom_commands=sorted(custom_commands, key=lambda f: f.command), point_commands=sorted(point_commands, key=lambda a: (a.cost, a.command)), moderator_commands=sorted(moderator_commands, key=lambda c: (c.level if c.mod_only is False else 500, c.command)), created=session.pop('command_created_id', None), edited=session.pop('command_edited_id', None))
def update_commands(signal_id): global bot_commands_list from pajbot.models.command import CommandManager bot_commands = CommandManager( socket_manager=None, module_manager=ModuleManager(None).load(), bot=None).load(load_examples=True) bot_commands_list = bot_commands.parse_for_web() bot_commands_list = sorted(bot_commands_list, key=lambda x: (x.id or -1, x.main_alias)) del bot_commands
def update_commands(signal_id): log.debug('Updating commands...') from pajbot.models.command import CommandManager bot_commands = CommandManager( socket_manager=None, module_manager=ModuleManager(None).load(), bot=None).load(load_examples=True) app.bot_commands_list = bot_commands.parse_for_web() app.bot_commands_list.sort(key=lambda x: (x.id or -1, x.main_alias)) del bot_commands
def get_cached_commands(): CACHE_TIME = 30 # seconds redis = RedisManager.get() commands_key = '{streamer}:cache:commands'.format(streamer=StreamHelper.get_streamer()) commands = redis.get(commands_key) if commands is None: log.debug('Updating commands...') bot_commands = CommandManager( socket_manager=None, module_manager=ModuleManager(None).load(), bot=None).load(load_examples=True) bot_commands_list = bot_commands.parse_for_web() bot_commands_list.sort(key=lambda x: (x.id or -1, x.main_alias)) bot_commands_list = [c.jsonify() for c in bot_commands_list] redis.setex(commands_key, json.dumps(bot_commands_list, separators=(',', ':')), CACHE_TIME) else: bot_commands_list = json.loads(commands) return bot_commands_list