示例#1
0
async def set_commands(sec, modules):
    commands = [
        BotCommand(
            name,
            ("/help " + getattr(getattr(func, "__self__", None), "name", "")))
        for name, func in modules.commands.items()
        if sec.get_flags(func) & security.PUBLIC_PERMISSIONS
    ]
    await modules.client(SetBotCommandsRequest(commands))
示例#2
0
文件: utils.py 项目: artxia/backup
async def set_bot_commands(scope: Union[types.BotCommandScopeDefault,
                                        types.BotCommandScopePeer,
                                        types.BotCommandScopePeerAdmins,
                                        types.BotCommandScopeUsers,
                                        types.BotCommandScopeChats,
                                        types.BotCommandScopePeerUser,
                                        types.BotCommandScopeChatAdmins],
                           lang_code: str,
                           commands: list[types.BotCommand]):
    await env.bot(
        SetBotCommandsRequest(scope=scope, lang_code=lang_code, commands=commands)
    )
示例#3
0
    async def _register_commands(self):
        admin_input_peer = None  # make IDE happy!
        try:
            admin_input_peer = await self.bot.get_input_entity(self._cfg.admin)
        except ValueError as e:
            self._logger.critical(
                f'Admin ID {self._cfg.admin} is invalid, or you have not had any conversation with '
                f'the bot yet. Please send a "/start" to the bot and retry. Exiting...',
                exc_info=e)
            exit(-1)

        admin_commands = [
            BotCommand(command="download_chat",
                       description='[--min=MIN] [--max=MAX] [CHAT...] '
                       '下载并索引会话的历史消息,并将其加入监听列表'),
            BotCommand(command="monitor_chat",
                       description='CHAT... 将会话加入监听列表'),
            BotCommand(command="stat", description='查询后端索引状态'),
            BotCommand(command="clear", description='[CHAT...] 清除索引'),
            BotCommand(command="find_chat_id",
                       description='KEYWORD 根据关键词获取聊天 id'),
            BotCommand(command="refresh_chat_names", description='刷新对话名称缓存'),
        ]
        commands = [
            BotCommand(command="random", description='随机返回一条已索引消息'),
            BotCommand(command="chats", description='选择对话'),
            BotCommand(command="search", description='搜索消息'),
        ]
        await self.bot(
            SetBotCommandsRequest(scope=BotCommandScopePeer(admin_input_peer),
                                  lang_code='',
                                  commands=admin_commands + commands))
        await self.bot(
            SetBotCommandsRequest(scope=BotCommandScopeDefault(),
                                  lang_code='',
                                  commands=commands))