Exemple #1
0
async def _(session: CommandSession):
    # 获取设置了名称的插件列表
    print(nonebot.get_loaded_plugins())
    plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))
    arg = session.current_arg_text.strip().lower()
    if not arg:
        # 如果用户没有发送参数,则发送功能列表
        await session.send('我现在支持的功能有:\n' + '\n'.join(p.name for p in plugins))
        return

    # 如果发了参数则发送相应命令的使用帮助
    for p in plugins:
        if p.name.lower() == arg:
            await session.send(p.usage)
Exemple #2
0
async def usage(session: CommandSession):
    plugins = list(filter(lambda p: p.name, get_loaded_plugins()))

    is_admin = session.event['user_id'] in session.bot.config.SUPERUSERS

    arg = session.current_arg_text.strip().lower()
    if not arg:
        plugins_list = ['    » ' + re.sub(r'\[.*]', '', p.name).replace('(', '  (')
                        for p in plugins
                        if ('[I]' not in p.name) and ('[H]' not in p.name) and
                        ('[A]' not in p.name or is_admin)]

        msg = f'DeltaBot version {__version__}\n'\
               + '\n插件列表:\n'\
               + '\n'.join(plugins_list)

        await session.send(msg +\
                           "\n\n⚠️注意:以上为插件列表,并非命令列表!"
                           "请发送【/help+空格+插件名称】获取该插件所支持的命令列表,例如: /help couplet\n\n"
                           "若在群聊中使用请先@本机器人再输入命令\n\n"
                           "在网页上查看更多帮助: https://delta_zero.gitee.io/DeltaBot/usage.html")
        return

    plugin_usage = [p.usage for p in plugins if arg == re.sub(r'\[.*]|\(.*\)', '', p.name).strip()]
    if plugin_usage:
        for p in plugin_usage:
            await session.send(f"「{arg}」插件使用说明:\n\n" + p)
    else:
        await session.send(f"插件'{arg}'不存在,请确认插件名称是否正确")
Exemple #3
0
async def handle_auth_id(bot: Bot, event: Event, state: T_State):
    auth_type = state["auth_type"]
    auth_id = state["auth_id"]
    if not re.match(r'^\d+$', auth_id):
        await omegaauth.finish('参数错误QAQ, qq或群号应为纯数字')

    if auth_type == 'user':
        user = DBUser(user_id=auth_id)
        if user.exist():
            await omegaauth.send(f'即将对用户: 【{user.nickname().result}】执行操作')
        else:
            logger.error(f'为 {auth_type}/{auth_id} 配置权限节点失败, 数据库中不存在该用户')
            await omegaauth.finish('数据库中不存在该用户QAQ')
    elif auth_type == 'group':
        group = DBGroup(group_id=auth_id)
        if group.exist():
            await omegaauth.send(f'即将对群组: 【{group.name().result}】执行操作')
        else:
            logger.error(f'为 {auth_type}/{auth_id} 配置权限节点失败, 数据库中不存在该群组')
            await omegaauth.finish('数据库中不存在该群组QAQ')
    else:
        await omegaauth.finish('参数错误QAQ')

    # 处理可用权限节点列表
    plugins = get_loaded_plugins()
    auth_node_plugin = []
    for plugin in plugins:
        if plugin.export.get('auth_node'):
            auth_node_plugin.append(plugin.name)

    state["auth_node_plugin"] = auth_node_plugin
    p_list = '\n'.join(auth_node_plugin)
    await omegaauth.send(f'可配置权限节点的插件有:\n\n{p_list}')
Exemple #4
0
async def test_load_plugin(app: App, load_plugin: Set["Plugin"]):
    import nonebot
    from nonebot.plugin import PluginManager

    loaded_plugins = {
        plugin for plugin in nonebot.get_loaded_plugins() if not plugin.parent_plugin
    }
    assert loaded_plugins == load_plugin

    # check simple plugin
    assert "plugins.export" in sys.modules

    # check sub plugin
    plugin = nonebot.get_plugin("nested_subplugin")
    assert plugin
    assert "plugins.nested.plugins.nested_subplugin" in sys.modules
    assert plugin.parent_plugin == nonebot.get_plugin("nested")

    # check load again
    with pytest.raises(RuntimeError):
        PluginManager(plugins=["plugins.export"]).load_all_plugins()
    with pytest.raises(RuntimeError):
        PluginManager(search_path=["plugins"]).load_all_plugins()

    # check not found
    assert nonebot.load_plugin("some_plugin_not_exist") is None
Exemple #5
0
async def _(session: CommandSession):
    # 获取设置了名称的插件列表
    plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))

    arg = session.current_arg_text.strip().lower()
    if not arg:
        # 如果用户没有发送参数,则发送功能列表
        await session.send(
            "我现在支持的功能有:\n" + "\n".join(get_description(p) for p in plugins)
        )
        await session.send("具体各功能帮助请查看:https://bot.artin.li/guide/")
        session.finish(
            '输入 "帮助+空格+功能名" 查看各功能使用指南以及命令。\n' + '如:"帮助 绑定教务处",不需要加上括号及括号内内容。'
        )

    found = False

    # 如果发了参数则发送相应命令的使用帮助
    for p in plugins:
        if fuzz.partial_ratio(p.name.lower(), arg) > 0.6:
            found = True
            session.finish(p.usage)

    if not found:
        session.finish(f"暂时没有 {arg} 这个功能呢")
Exemple #6
0
async def _(session: CommandSession):
    plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))
    arg = session.current_arg_text.strip().lower()
    if not arg:
        session.finish('我现在支持的功能有:\n\n' + '\n'.join(p.name for p in plugins))
    for p in plugins:
        if p.name.lower() == arg:
            await session.send(p.usage)
Exemple #7
0
def _get_module(module):
    plugins = nonebot.get_loaded_plugins()
    for plugin in plugins:
        m = str(plugin.module)
        m = m.replace('\\', '/').replace('//', '/')
        if module in m:
            return plugin.module
    return None
Exemple #8
0
 async def usage(self):
     # 获取设置了名称的插件列表
     plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))
     arg = self.stripped_msg.lower()
     plugin = next((p for p in plugins if p.name == arg), False)
     logger.info(plugin)
     await self.send(
         self.render_image('usage', plugins=plugins, plugin=plugin))
Exemple #9
0
def get_clanbattle_report_instance():
    plugins = nonebot.get_loaded_plugins()
    for plugin in plugins:
        m = str(plugin.module)
        m = m.replace('\\\\', '/')
        m = m.replace('\\', '/')
        if 'modules/clanbattle_report/report.py' in m:
            return plugin.module
    return None
Exemple #10
0
async def _(session: CommandSession):
    plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))
    print(plugins)
    arg = session.current_arg_text.strip().lower()
    if not arg:
        await session.send('现在有以下功能:\n' + '\n'.join(p.name for p in plugins))
        return

    for p in plugins:
        if p.name.lower() == arg:
            await session.send(p.usage)
Exemple #11
0
async def _(session: CommandSession):
    # get list of all plugins
    if session.ctx['user_id'] in get_bot().config.SUPERUSERS \
            and not session.ctx.get('group_id') \
            and not session.ctx.get('discuss_id'):
        plugins = [p for p in nonebot.get_loaded_plugins() if p.name]
    else:
        plugins = [p for p in nonebot.get_loaded_plugins() if p.name and not p.name.endswith('private)')]

    arg = session.current_arg_text.strip().lower()
    if not arg:
        text = '目前功能:\n\t' + \
               '\n\t'.join(p.name for p in plugins) + '\n' + \
               '对应功能说明(例):.help 复读机'
        await session.send(text)

    else:
        for p in plugins:
            if arg in p.name.lower():
                await session.send(p.usage.strip())
Exemple #12
0
async def help(session: CommandSession):
    plugins = list(filter(lambda p: p.name, get_loaded_plugins()))
    arg = session.current_arg_text.strip().lower()
    if not arg:
        await session.send('KirinBot\nお持ちなさい、あなたが望んだその星を\n\n'
                           '指令列表:\n' + '\n'.join(p.name for p in plugins))
    else:
        for p in plugins:
            if p.name.lower() == arg:
                await session.send(p.usage)
                return
        await session.send('无此指令')
Exemple #13
0
async def _(session: CommandSession):
	plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))

	arg = session.current_arg_text.strip().lower()
	if not arg:
		await session.send(
			'一个兴趣使然的Bot By Kray@771689599\n我现在支持的功能有:\n' + '\n'.join(p.name for p in plugins) + '\n使用:@我 帮助 [功能名称]\n以获取更多信息,私聊无需@\n范例:@我 帮助 jita')
		return

	for p in plugins:
		if p.name.lower() == arg:
			await session.send(p.usage)
Exemple #14
0
async def _(session: CommandSession):
    plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))

    arg = session.current_arg_text.strip().upper()
    if not arg:
        await session.send("发送“帮助 功能名”可查看详细信息,注意空格\n目前支持的功能有:\n\n" +
                           '\n'.join(p.name for p in plugins))
        return

    for p in plugins:
        if p.name == arg:
            await session.send(p.usage)
Exemple #15
0
async def usage(session: CommandSession):
    plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))

    arg = session.current_arg_text.strip().lower()
    if not arg:
        # 如果没有参数 发送列表
        await session.send('现在支持的功能有:\n' + '\n'.join(p.name for p in plugins) +
                           '\n\n可以发送 “帮助 + 选项” 来查看使用示例哦~')
        return

    for p in plugins:
        if p.name.lower() == arg:
            await session.send(p.usage)
Exemple #16
0
async def help(session: CommandSession):
    plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))

    arg = session.current_arg_text.strip().lower()
    if not arg:
        await session.send('现在支持的功能有:\n' + '\n'.join(p.name for p in plugins) +
                           '\n使用 !help <功能> 查看详细信息')
    else:
        for p in plugins:
            if p.name.lower() == arg:
                await session.send(p.usage)
                return
        await session.send('未找到该插件')
Exemple #17
0
async def help(session: CommandSession):
    plugins = list(filter(lambda p: p.name, get_loaded_plugins()))

    arg = session.current_arg_text.strip().lower()
    if not arg:
        await session.send('我现在支持的功能有:\n\n' + '\n'.join(p.name for p in plugins))
        return
    
    check = set(filter(lambda p: p.name.lower() == arg, plugins))
    if check:
        for p in check:
            await session.send(p.usage)
    else: await session.send("功能不存在:)")
Exemple #18
0
async def _(session: CommandSession):
    # 获取设置了名称的插件列表
    plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))

    arg = session.current_arg_text.strip().lower()
    if not arg:
        # 如果用户没有发送参数,则发送功能列表
        session.finish('亲亲这边支持得功能有下面这几个呢\n\n' +
                       '\n\n'.join(p.name + '\n' + p.usage for p in plugins))
        return

    # 如果发了参数则发送相应命令的使用帮助
    for p in plugins:
        if p.name.lower() == arg:
            session.finish(p.name + '\n' + p.usage)
Exemple #19
0
async def _(session: CommandSession):
    # 获取设置了名称的插件列表
    plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))

    arg = session.current_arg_text.strip().lower()
    if not arg:
        # 如果用户没有发送参数,则发送功能列表
        await session.send(
            '我的名字是Saiki,你也可以叫我齐木\n我现在支持的功能有:\n[CQ:emoji,id=127775]' + '\n[CQ:emoji,id=127775]'.join(p.name for p in plugins)+'\n'+\
            "查看具体操作发送:使用方法/帮助 [功能]\n在群聊与我对话请加上我的名字。")
        return

    # 如果发了参数则发送相应命令的使用帮助
    for p in plugins:
        if p.name.lower() == arg:
            await session.send(p.usage)
Exemple #20
0
async def _(session: CommandSession):
    # 获取加载的插件,注意名字以 [Hidden] 结尾的不应该被展示!
    plugins = (p for p in get_loaded_plugins() if p.name and not p.name.endswith('[Hidden]'))

    arg = session.current_arg_text.strip()
    # 没有参数:展示功能列表
    if not arg:
        await session.send(
            '我的功能有:\n  ' + '\n  '.join(p.name for p in plugins) +
            '\n对我说 “帮助 功能名” 获取对应详细帮助'
        )
    # 有参数:展示对应 usage
    else:
        for p in plugins:
            if arg.lower() in p.name.lower():
                await session.send(p.usage)
Exemple #21
0
def get_embedded_yobot_ClanBattle_instance():
    plugins = nonebot.get_loaded_plugins()
    for plugin in plugins:
        m = str(plugin.module)
        m = m.replace('\\\\', '/')
        m = m.replace('\\', '/')
        if 'modules/yobot/yobot/__init__.py' in m:
            passive_list = []
            try:
                passive_list = plugin.module.src.client.nonebot_plugin.bot.plug_passive
            except:
                continue
            for module in passive_list:
                if type(module).__name__ == 'ClanBattle':
                    return module
    return None
Exemple #22
0
async def test_load_plugin(load_plugin: Set["Plugin"]):
    import nonebot

    loaded_plugins = set(plugin for plugin in nonebot.get_loaded_plugins()
                         if not plugin.parent_plugin)
    assert loaded_plugins == load_plugin
    plugin = nonebot.get_plugin("export")
    assert plugin
    assert plugin.module_name == "plugins.export"
    assert "plugins.export" in sys.modules

    try:
        nonebot.load_plugin("plugins.export")
        assert False
    except RuntimeError:
        assert True
Exemple #23
0
def get_commands() -> list[CommandInfo]:
    """获取所有命令的信息

    并保存,方便下次使用
    """
    global _commands
    if _commands is None:
        plugins = get_loaded_plugins()
        matchers = reduce(lambda x, y: x.union(y.matcher), plugins, set())
        commands = []
        for matcher in matchers:
            command = extract_command_info(matcher)
            if command:
                commands.append(command)
        _commands = commands
    return _commands
Exemple #24
0
def get_commands() -> List[CommandInfo]:
    """ 获取所有命令的信息

    并保存,方便下次使用
    """
    global _commands
    if _commands is None:
        plugins = get_loaded_plugins()
        matchers = reduce(lambda x, y: x.union(y.matcher), plugins, set())
        matcher_docs = list(
            map(
                lambda x: inspect.cleandoc(x.__doc__),
                filter(lambda x: x.__doc__, matchers)
            )
        )
        _commands = list(map(extract_command_info, matcher_docs))
    return _commands
Exemple #25
0
async def _(session: CommandSession):
    plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))

    arg = session.current_arg_text.strip().lower()
    if not arg:
        await session.send("这里是不知不觉的 bot 不休不眠,现在支持的功能有:\n" +
                           "\n".join(p.name for p in plugins) +
                           "\n输入 help [功能名] 查询具体用法")
        return

    flag = 0
    for p in plugins:
        if p.name.lower() == arg:
            flag = 1
            await session.send(p.usage)
    if flag == 0:
        await session.send("未能识别插件名")
Exemple #26
0
async def reload(session: CommandSession):
    plugindir_path = os.path.abspath(os.path.dirname(
        os.path.dirname(__file__)))
    plugin_list = []
    for p in get_loaded_plugins():
        plugin_list.append(p.module.__name__)
    for f in os.listdir(plugindir_path):
        if f != '__pycache__':
            plugin_path = 'plugins.' + os.path.splitext(f)[0]
            plugin_list.append(plugin_path)
    for plugin_path in plugin_list:
        ret = reload_plugin(plugin_path)
        if not ret:
            ret = load_plugin(plugin_path)
        if not ret:
            await session.send("[WARNING] Failed to reload '%s' plugin!" %
                               plugin_path)
    await session.send("Plugins reloaded.")
Exemple #27
0
async def _(session: CommandSession):
    plugin_name = session.current_arg_text.strip()
    plugins = list(filter(lambda p: p.name, get_loaded_plugins()))

    if not plugin_name:
        await send_manual_image(session, 'index')
        return

    found = False
    for plugin in filter(lambda x: x.name.lower() == plugin_name.lower(),
                         plugins):
        found = True
        if plugin.usage:
            await session.send(plugin.usage)
        else:
            await send_manual_image(session, plugin.name)

    if not found:
        await session.send(f'暂时没有 {plugin_name} 这个功能呢')
Exemple #28
0
async def _(session: CommandSession):
    if check_blacklist(session.ctx.get('user_id')):
        return None
    plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))
    arg = session.current_arg_text.strip().lower()
    if not check_whitelist(session.ctx.get('group_id')):
        temp_plugins = ["离散对数", "抽象话", "知乎热榜", "打断复读", "素性测试"]
        await session.send('我现在支持的功能有:\n' +
                           '\n'.join(p for p in temp_plugins) + '\n\n' +
                           '另外,此bot还缝合了跑团掷骰功能。请输入.dicehelp以查看该功能的使用说明。')
        return
    if not arg:
        await session.send('我现在支持的功能有:\n' + '\n'.join(p.name
                                                      for p in plugins) +
                           '\n\n' + '输入help [功能名] 可以查看具体使用方法。\n' +
                           '另外,此bot还缝合了跑团掷骰功能。请输入.dicehelp以查看该功能的使用说明。')
        return
    for p in plugins:
        if p.name.lower() == arg:
            await session.send(p.usage)
Exemple #29
0
async def _(session: CommandSession):
    # 获取设置了名称的插件列表
    SenderGroupNumber = session.ctx['group_id']
    if str(SenderGroupNumber) in config.SendGroup:
        pass
    else:
        plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))
        arg = session.current_arg_text.strip().lower()
        user_id = session.ctx['user_id']
        if not arg:
            # 如果用户没有发送参数,则发送功能列表
            await session.send(
                unescape('[CQ:at,qq=%s]我现在支持的功能有:\n-------\n' % user_id +
                         '\n'.join(p.name for p in plugins)))
            await session.send('发送#help 功能 即可获取到详细用法')
            return
        # 如果发了参数则发送相应命令的使用帮助
        for p in plugins:
            if p.name.lower() == arg:
                await session.send(
                    unescape('[CQ:at,qq=%s]' % user_id + p.usage))
Exemple #30
0
async def usage(session: CommandSession):
    plugins = list(filter(lambda p: p.name, (nonebot.get_loaded_plugins())))
    arg = session.current_arg_text.strip().lower()
    if not arg:
        await session.send("BOT目前支持的功能\n=====\n" + "\n".join(p.name
                                                             for p in plugins))
        return
    else:
        for p in plugins:
            if p.name.lower() == arg:
                await session.send(p.usage)


# @on_command("off",aliases=("关闭功能"),permission = permission.SUPERUSER,only_to_me=True)
# async def offfunction(session):
#     plugins = list(nonebot.get_loaded_plugins)
#     arg = session.current_arg_text.strip().lower()
#     if not arg:
#         await session.send("要关闭哪个功能鸭~\n请按照!off <功能名>的格式进行操作\n功能名列表可以使用usage命令查看QuQ")
#     else:
#         for p in plugins:
#             if p.name.lower() == arg:
#                 #await
#                 pass