예제 #1
0
async def enable_service(bot: Bot, event: CQEvent):
    if isinstance(event, GroupMessageEvent):
        names = event.get_plaintext().split()
        uid = event.user_id
        user_info = await bot.get_stranger_info(user_id=uid)
        nickname = user_info.get('nickname', '未知用户')
        if not names:
            await enable.finish(f'>{nickname}\n请在空格后接要启用的服务名')
        group_id = event.group_id
        svs = Service.get_loaded_services()
        succ, notfound = [], []
        for name in names:
            if name in svs:
                sv = svs[name]
                u_priv = priv.get_user_priv(event)
                if u_priv >= sv.manage_priv:
                    sv.set_enable(group_id)
                    succ.append(name)
                else:
                    await enable.finish(
                        f'>{nickname}\n权限不足!启用[{name}]需要权限:{sv.manage_priv},您的权限:{u_priv}\n{PRIV_TIP}'
                    )
            else:
                notfound.append(name)
        msg = [f'>{nickname}']
        if succ:
            msg.append('已启用服务:' + '、'.join(succ))
        if notfound:
            msg.append('未找到服务:' + '、'.join(notfound))
        if msg:
            await enable.finish('\n'.join(msg))
    elif isinstance(event, PrivateMessageEvent):
        if event.user_id not in salmon.configs.SUPERUSERS:
            await enable.finish('请在群聊中启用服务')
        args = event.get_plaintext().split()
        if len(args) < 2:
            await enable.finish(
                'Input not supported.\nUsage: <service_name> <group_id1> [<group_id2>, ...]'
            )
        name, *group_ids = args
        svs = Service.get_loaded_services()
        if name not in svs:
            await enable.finish(f'未找到服务:{name}')
        sv = svs[name]
        succ = []
        for gid in group_ids:
            try:
                gid = int(gid)
                sv.set_enable(gid)
                succ.append(gid)
            except:
                await bot.send(event, f'非法群号:{gid}')
        await enable.finish(f'服务[{name}]已于{len(succ)}个群内启用:{succ}')
예제 #2
0
async def ls_service(bot: Bot, event: CQEvent, service_name: str):
    all_services = Service.get_loaded_services()
    if service_name in all_services:
        sv = all_services[service_name]
        on_g = '\n'.join(map(lambda x: str(x), sv.enable_group))
        off_g = '\n'.join(map(lambda x: str(x), sv.disable_group))
        default_ = 'enabled' if sv.enable_on_default else 'disabled'
        msg = f"服务{sv.name}:\n默认:{default_}\nmanage_priv={sv.manage_priv}\nvisible={sv.visible}\n启用群:\n{on_g}\n禁用群:\n{off_g}"
        await bot.send(event, msg)
    else:
        await bot.send(event, f'未找到服务{service_name}')
예제 #3
0
async def help_handle(bot: Bot, event: CQEvent):
    name = event.get_plaintext().strip()
    bundles = Service.get_bundles()
    svs = Service.get_loaded_services()
    info = Service.get_help()
    if not name:
        await send_help.finish(TOP_MANUAL)
    elif name in bundles:
        if isinstance(event, GroupMessageEvent):
            msg = get_bundle_manual(name, bundles[name], event.group_id)
        elif isinstance(event, PrivateMessageEvent):
            msg = get_private_manual(name, bundles[name])
        await send_help.finish(msg)
    elif name in svs:
        msg = get_service_help(name, info[name])
        await send_help.finish(msg)
예제 #4
0
async def _(bot: Bot, event: CQEvent, state: T_State):
    if not 'gids' in state:
        await lssv.finish('Invalid input.')
    verbose_all = state['args']
    svs = Service.get_loaded_services().values()
    u_priv = priv.get_user_priv(bot, event)
    if u_priv >= 2:
        for gid in state['gids']:
            msg = [f"群{gid}服务一览:"]
            svs = map(lambda sv: (sv, sv.check_enabled(gid)), svs)
            key = cmp_to_key(lambda x, y: (y[1] - x[1]) or (-1 if x[
                0].name < y[0].name else 1 if x[0].name > y[0].name else 0))
            svs = sorted(svs, key=key)
            for sv, on in svs:
                if sv.visible or verbose_all:
                    ox = 'O' if on else 'X'
                    msg.append(f"|{ox}| {sv.name}")
            await lssv.finish('\n'.join(msg))
    else:
        await lssv.finish('查看服务列表需要管理及以上的权限')