async def disable_modules(kwargs: dict):
    """
~disable [self] <modules/all>"""
    command = kwargs['trigger_msg'].split(' ')
    if not len(command) > 1:
        await sendMessage(kwargs, '命令格式错误。' + disable_modules.__doc__)
        return
    function_list = kwargs['function_list']
    command_second_word = command[1]
    if Group in kwargs:
        if command_second_word == 'self':
            if not len(command) > 2:
                await sendMessage(kwargs, '命令格式错误。' + disable_modules.__doc__)
                return
            command_third_word = command[2]
            if command_third_word in function_list:
                msg = database.update_modules_self('del', kwargs[Member].id,
                                                   command_third_word)
                await sendMessage(kwargs, msg)
            else:
                await sendMessage(kwargs, '此模块不存在。')
        elif command_second_word == 'all':
            if check_permission(kwargs):
                msglist = []
                for function in function_list:
                    msg = database.update_modules('del', kwargs[Group].id,
                                                  function)
                    msglist.append(msg)
                await sendMessage(kwargs, '\n'.join(msglist))
            else:
                await sendMessage(kwargs, '你没有使用该命令的权限。')
        elif command_second_word in function_list:
            if check_permission(kwargs):
                msg = database.update_modules('del', kwargs[Group].id,
                                              command_second_word)
                await sendMessage(kwargs, msg)
            else:
                await sendMessage(kwargs, '你没有使用该命令的权限。')
        else:
            await sendMessage(kwargs, '此模块不存在。')
    elif Friend in kwargs:
        if command_second_word == 'self':
            if not len(command) > 2:
                await sendMessage(kwargs, '命令格式错误。' + disable_modules.__doc__)
                return
            command_second_word = command[2]
        do = 'del'
        if command_second_word == 'all':
            msglist = []
            for function in function_list:
                msg = database.update_modules_self(do, kwargs[Friend].id,
                                                   function)
                msglist.append(msg)
            await sendMessage(kwargs, '\n'.join(msglist))
        elif command_second_word in function_list:
            msg = database.update_modules_self(do, kwargs[Friend].id,
                                               command_second_word)
            await sendMessage(kwargs, msg)
        else:
            await sendMessage(kwargs, '此模块不存在。')
Example #2
0
async def set_start_wiki(kwargs: dict):
    if Group in kwargs:
        if check_permission(kwargs):
            command = kwargs['trigger_msg']
            command = re.sub(r'^wiki_start_site ', '', command)
            check = await check_wiki_available(command)
            if check:
                result = database.add_start_wiki('start_wiki_link_group',
                                                 kwargs[Group].id, check[0])
                await sendMessage(
                    kwargs, MessageChain.create([Plain(result + check[1])]))
            else:
                result = '错误:此Wiki不是一个有效的MediaWiki/尝试建立连接超时。'
                await sendMessage(kwargs, MessageChain.create([Plain(result)]))
        else:
            result = '你没有使用该命令的权限。'
            await sendMessage(kwargs, MessageChain.create([Plain(result)]))
    if Friend in kwargs:
        command = kwargs['trigger_msg']
        command = re.sub(r'^wiki_start_site ', '', command)
        check = await check_wiki_available(command)
        if check:
            result = database.add_start_wiki('start_wiki_link_self',
                                             kwargs[Friend].id, check[0])
            await sendMessage(kwargs,
                              MessageChain.create([Plain(result + check[1])]))
        else:
            result = '错误:此Wiki不是一个有效的MediaWiki/尝试建立连接超时。'
            await sendMessage(kwargs, MessageChain.create([Plain(result)]))
Example #3
0
async def interwiki(kwargs: dict):
    command = kwargs['trigger_msg']
    command = re.sub(r'^interwiki ', '', command)
    command = command.split(' ')
    print(command)
    if Group in kwargs:
        check = check_permission(kwargs)
        if not check:
            result = '你没有使用该命令的权限,请联系管理员进行操作。'
            await sendMessage(kwargs, MessageChain.create([Plain(result)]))
            return
    table = 'custom_interwiki_' + kwargs[Target].target_from
    htable = 'request_headers_' + kwargs[Target].target_from
    target = kwargs[Target].id
    if command[0] in ['add', 'set']:
        command = ' '.join(command[1:])
        command = re.sub(' ', '>', command)
        iw = command.split('>')
        if len(iw) == 1 or len(iw) > 2:
            await sendMessage(kwargs,
                              '错误:命令不合法:~wiki iw add <interwiki> <url>')
            return
        check = await wikilib.wikilib().check_wiki_available(
            iw[1], headers=WikiDB.config_headers('get', htable, target))
        if check[0]:
            result = WikiDB.config_custom_interwiki('add', table, target,
                                                    iw[0], check[0])
            await sendMessage(
                kwargs,
                MessageChain.create([Plain(result + f'{iw[0]} > {check[1]}')]))
        else:
            if check[1] == 'Timeout':
                result = '错误:尝试建立连接超时。'
            else:
                result = '错误:此站点也许不是一个有效的Mediawiki:' + check[1]
            link = re.match(r'^(https?://).*', iw[1])
            if not link:
                result = '错误:所给的链接没有指明协议头(链接应以http://或https://开头)。'
            await sendMessage(kwargs, MessageChain.create([Plain(result)]))
    elif command[0] == 'del':
        result = WikiDB.config_custom_interwiki('del', table, target,
                                                command[1])
        await sendMessage(kwargs, MessageChain.create([Plain(result)]))
    elif command[0] == 'list':
        query_database = WikiDB.get_custom_interwiki_list(table, target)
        if query_database:
            result = '当前设置了以下Interwiki:\n' + query_database
            await sendMessage(kwargs, result)
        else:
            await sendMessage(
                kwargs,
                '当前没有设置任何Interwiki,使用~wiki iw add <interwiki> <api_endpoint_link>添加一个。'
            )
    else:
        await sendMessage(kwargs, '命令不合法,参数应为add/del/list。')
Example #4
0
async def config_gu(kwargs):
    if Group in kwargs:
        if check_permission(kwargs):
            command = kwargs['trigger_msg'].split(' ')
            if len(command) < 3:
                await sendMessage(kwargs, '命令格式错误。')
                return
            print(command)
            if command[1] == 'add':
                await sendMessage(kwargs, database.add_group_adminuser(command[2], kwargs[Group].id))
            if command[1] == 'del':
                await sendMessage(kwargs, database.del_group_adminuser(command[2], kwargs[Group].id))
Example #5
0
async def set_headers(kwargs: dict):
    command = kwargs['trigger_msg']
    command = command.split(' ')
    if Group in kwargs:
        check = check_permission(kwargs)
        if not check:
            result = '你没有使用该命令的权限,请联系管理员进行操作。'
            await sendMessage(kwargs, MessageChain.create([Plain(result)]))
            return
    table = 'request_headers_' + kwargs[Target].target_from
    id = kwargs[Target].id
    do = command[0]
    if do == 'show':
        headers = WikiDB.config_headers(do, table, id)
        msg = f'当前设置了以下标头:\n{headers}\n如需自定义,请使用~wiki headers <set> <headers>,不同标头之间使用换行隔开。'
    else:
        msg = WikiDB.config_headers(do, table, id, ' '.join(command[1:]))
    await sendMessage(kwargs, msg)
Example #6
0
async def set_start_wiki(kwargs: dict):
    command = kwargs['trigger_msg']
    command = re.sub(r'^wiki_start_site ', '', command)
    if Group in kwargs:
        if not check_permission(kwargs):
            result = '你没有在群内使用该命令的权限,请联系管理员进行操作。'
            await sendMessage(kwargs, MessageChain.create([Plain(result)]))
            return
    check = await wikilib.wikilib().check_wiki_available(command)
    if check[0]:
        result = WikiDB.add_start_wiki('start_wiki_link_' + kwargs[Target].target_from, kwargs[Target].id, check[0])
        await sendMessage(kwargs, MessageChain.create([Plain(result + check[1])]))
    else:
        if check[1] == 'Timeout':
            result = '错误:尝试建立连接超时。'
        else:
            result = '错误:此站点也许不是一个有效的Mediawiki:' + check[1]
        link = re.match(r'^(https?://).*', command)
        if not link:
            result = '错误:所给的链接没有指明协议头(链接应以http://或https://开头)。'
        await sendMessage(kwargs, MessageChain.create([Plain(result)]))
Example #7
0
async def config_modules(kwargs: dict):
    """
~module <enable/disable> <module/all>"""
    command = kwargs['trigger_msg'].split(' ')
    bot_modules = kwargs['bot_modules']
    function_list = bot_modules['modules_function']
    friend_function_list = bot_modules['friend_modules_function']
    alias_list = bot_modules['alias']
    msg = '命令格式错误。' + config_modules.__doc__
    if not len(command) > 2:
        await sendMessage(kwargs, msg)
        return
    do = command[1]
    command_third_word = command[2]
    if command_third_word in alias_list:
        command_third_word = alias_list[command_third_word]
    if Group in kwargs:
        if not check_permission(kwargs):
            await sendMessage(kwargs, '你没有使用该命令的权限。')
            return
        if command_third_word == 'all':
            msglist = []
            for function in function_list:
                msg = database.update_modules(do, kwargs[Group].id, function)
                msglist.append(msg)
            msg = '\n'.join(msglist)
        elif command_third_word in function_list:
            msg = database.update_modules(do, kwargs[Group].id,
                                          command_third_word)
        else:
            msg = '此模块不存在。'
    elif Friend in kwargs:
        if command_third_word in friend_function_list:
            msg = database.update_modules(do,
                                          kwargs[Friend].id,
                                          command_third_word,
                                          table='friend_permission')
        else:
            msg = '此模块不存在。'
    await sendMessage(kwargs, msg)
Example #8
0
async def interwiki(kwargs: dict):
    command = kwargs['trigger_msg']
    command = re.sub(r'^interwiki ', '', command)
    command = command.split(' ')
    if Group in kwargs:
        check = check_permission(kwargs)
        if check:
            if command[0] == 'add':
                command = re.sub(r'^interwiki add ', '', kwargs['trigger_msg'])
                command = re.sub(' ', '>', command)
                iw = command.split('>')
                try:
                    check = await check_wiki_available(iw[1])
                except:
                    await sendMessage(
                        kwargs, '错误:命令不合法:~interwiki add <Interwiki> <url>')
                    check = False
                if check:
                    result = database.config_custom_interwiki(
                        'add', 'custom_interwiki_group', kwargs[Group].id,
                        iw[0], check[0])
                    await sendMessage(
                        kwargs,
                        MessageChain.create([Plain(result + check[1])]))
                else:
                    result = '错误:此Wiki不是一个有效的MediaWiki/尝试建立连接超时。'
                    await sendMessage(kwargs,
                                      MessageChain.create([Plain(result)]))
            elif command[0] == 'del':
                result = database.config_custom_interwiki(
                    'del', 'custom_interwiki_group', kwargs[Group].id,
                    command[1])
                await sendMessage(kwargs, MessageChain.create([Plain(result)]))
            else:
                await sendMessage(kwargs, '命令不合法。')
        else:
            result = '你没有使用该命令的权限。'
            await sendMessage(kwargs, MessageChain.create([Plain(result)]))
    if Friend in kwargs:
        if command[0] == 'add':
            command = re.sub(r'^interwiki add ', '', kwargs['trigger_msg'])
            command = re.sub(' ', '>', command)
            iw = command.split('>')
            try:
                check = await check_wiki_available(iw[1])
            except:
                await sendMessage(kwargs,
                                  '错误:命令不合法:~interwiki add <Interwiki> <url>')
                check = False
            if check:
                result = database.config_custom_interwiki(
                    'add', 'custom_interwiki_self', kwargs[Friend].id, iw[0],
                    check[0])
                await sendMessage(
                    kwargs, MessageChain.create([Plain(result + check[1])]))
            else:
                result = '错误:此Wiki不是一个有效的MediaWiki/尝试建立连接超时。'
                await sendMessage(kwargs, MessageChain.create([Plain(result)]))
        elif command[0] == 'del':
            result = database.config_custom_interwiki('del',
                                                      'custom_interwiki_self',
                                                      kwargs[Friend].id,
                                                      command[1])
            await sendMessage(kwargs, MessageChain.create([Plain(result)]))
        else:
            await sendMessage(kwargs, '命令不合法。')