Пример #1
0
def load_modules(reload=False):
    global admin_list, essential_list, command_list, help_list, regex_list, self_options_list, options_list, function_list
    admin_list, essential_list, command_list, help_list, regex_list, self_options_list, options_list = command_loader(
        reload)
    function_list = []
    for command in command_list:
        function_list.append(command)
    for reg in regex_list:
        function_list.append(reg)
    for options in self_options_list:
        function_list.append(options)
    for options in options_list:
        function_list.append(options)
    logger_info(f'Now we have function = {function_list}')
async def newbie(app):
    logger_info('Subbot newbie launched')
    url = 'https://minecraft-zh.gamepedia.com/api.php?action=query&list=logevents&letype=newusers&format=json'
    while True:
        try:
            file = await get_data(url, 'json')
            qq = []
            for x in file['query']['logevents'][:]:
                qq.append(x['title'])
            while True:
                c = 'f'
                try:
                    qqqq = await get_data(url, 'json')
                    for xz in qqqq['query']['logevents'][:]:
                        if xz['title'] in qq:
                            pass
                        else:
                            s = await check([
                                UTC8(xz['timestamp'], 'onlytime') + '新增新人:' +
                                xz['title']
                            ])
                            if s.find("<吃掉了>") != -1 or s.find(
                                    "<全部吃掉了>") != -1:
                                await app.sendGroupMessage(
                                    731397727,
                                    MessageChain.create([
                                        Plain(
                                            s +
                                            '\n检测到外来信息介入,请前往日志查看所有消息。Special:日志?type=newusers'
                                        )
                                    ]).asSendable())
                            else:
                                await app.sendGroupMessage(
                                    731397727,
                                    MessageChain.create([Plain(s)
                                                         ]).asSendable())
                            c = 't'
                except Exception:
                    pass
                if c == 't':
                    break
                else:
                    await asyncio.sleep(10)
            await asyncio.sleep(5)
        except Exception:
            traceback.print_exc()
Пример #3
0
 async def bedrock_dungeons():
     url = 'https://bugs.mojang.com/rest/api/2/project/11901/versions'
     try:
         version_file = os.path.abspath(
             './assets/mcversion_jira-dungeons.txt')
         logger_info('Checking Jira mcv-bedrock...')
         verlist = getfileversions(version_file)
         file = await get_data(url, 'json')
         release = []
         for v in file:
             if not v['archived']:
                 release.append(v['name'])
         for x in release:
             if x not in verlist:
                 logger_info(f'huh, we find {x}.')
                 for qqgroup in check_enable_modules_all(
                         'group_permission', 'mcv_jira_rss'):
                     try:
                         await app.sendGroupMessage(
                             int(qqgroup),
                             MessageChain.create([
                                 Plain(
                                     f'Jira已更新Dungeons {x}。\n(Jira上的信息仅作版本号预览用,不代表商店已更新此版本)'
                                 )
                             ]))
                         await asyncio.sleep(0.5)
                     except Exception:
                         traceback.print_exc()
                 for qqfriend in check_enable_modules_all(
                         'friend_permission', 'mcv_jira_rss'):
                     try:
                         await app.sendFriendMessage(
                             int(qqfriend),
                             MessageChain.create([
                                 Plain(
                                     f'Jira已更新Dungeons {x}。\n(Jira上的信息仅作版本号预览用,不代表启动器已更新此版本)'
                                 )
                             ]))
                         await asyncio.sleep(0.5)
                     except Exception:
                         traceback.print_exc()
                 addversion = open(version_file, 'a')
                 addversion.write('\n' + x)
                 addversion.close()
         logger_info('jira mcv-dungeons checked.')
     except Exception:
         traceback.print_exc()
Пример #4
0
async def parser(kwargs: dict):
    """
    接收消息必经的预处理器
    :param kwargs: 从监听器接收到的dict,该dict将会经过此预处理器传入下游
    :return: 无返回
    """
    display = RemoveDuplicateSpace(kwargs_AsDisplay(kwargs))  # 将消息转换为一般显示形式
    if len(display) == 0:  # 转换后若为空消息则停止执行
        return
    trigger = kwargs_GetTrigger(kwargs)  # 得到触发者来源
    if trigger == 1143754816:  # 特殊规则
        display = re.sub('^.*:\n', '', display)
    if database.check_black_list(trigger):  # 检查是否在黑名单
        if not database.check_white_list(trigger):  # 检查是否在白名单
            return  # 在黑名单且不在白名单,给我爪巴
    if display.find('色图来') != -1:  # 双倍快乐给我爬
        return
    if display[0] in command_prefix:  # 检查消息前缀
        logger_info(kwargs)
        command = re.sub(r'^' + display[0], '', display)
        command_list = remove_ineffective_text(command_prefix,
                                               command.split('&&'))  # 并行命令处理
        if len(command_list) > 5:
            if not database.check_superuser(kwargs):
                await sendMessage(kwargs, '你不是本机器人的超级管理员,最多只能并排执行5个命令。')
                return
        for command in command_list:
            command_spilt = command.split(' ')  # 切割消息
            try:
                kwargs['trigger_msg'] = command  # 触发该命令的消息,去除消息前缀
                kwargs['bot_modules'] = Modules
                command_first_word = command_spilt[0]
                if command_first_word in Modules['alias']:
                    command_spilt[0] = Modules['alias'][command_first_word]
                    command = ' '.join(command_spilt)
                    command_spilt = command.split(' ')
                    command_first_word = command_spilt[0]
                    kwargs['trigger_msg'] = command
                if command_first_word in Modules['command']:  # 检查触发命令是否在模块列表中
                    if Group in kwargs:
                        await Nudge(kwargs)
                        check_command_enable = database.check_enable_modules(
                            kwargs[Group].id, command_first_word)  # 检查群组是否开启模块
                        if not check_command_enable:  # 若未开启
                            await sendMessage(
                                kwargs,
                                f'此模块未启用,请管理员在群内发送~enable {command_first_word}启用本模块。'
                            )
                            return
                    await Modules['command'][command_first_word](
                        kwargs)  # 将dict传入下游模块
                elif command_first_word in Modules[
                        'essential']:  # 若触发的对象命令为基础命令
                    if Group in kwargs:
                        await Nudge(kwargs)
                    await Modules['essential'][command_first_word](kwargs)
                elif command_first_word in Modules['admin']:  # 若触发的对象为超管命令
                    if database.check_superuser(kwargs):  # 检查是否为超管
                        await Modules['admin'][command_first_word](kwargs)
                    else:
                        await sendMessage(kwargs, '权限不足')
            except Exception as e:
                traceback.print_exc()
                await sendMessage(kwargs, '执行命令时发生错误,请报告管理员:\n' + str(e))
    # 正则模块部分
    if Group in kwargs:
        for regex in Modules['regex']:  # 遍历正则模块列表
            check_command_enable = database.check_enable_modules(
                kwargs[Group].id, regex)  # 检查群组是否打开模块
            if check_command_enable:
                await Modules['regex'][regex](kwargs)  # 将整条dict传入下游正则模块
    if Friend in kwargs:
        for regex in Modules['regex']:
            await Modules['regex'][regex](kwargs)
    return
Пример #5
0
 async def java_main():
     url = 'http://launchermeta.mojang.com/mc/game/version_manifest.json'
     try:
         version_file = os.path.abspath('./assets/mcversion.txt')
         logger_info('Checking mcv...')
         verlist = getfileversions(version_file)
         file = await get_data(url, 'json')
         release = file['latest']['release']
         snapshot = file['latest']['snapshot']
         if release not in verlist:
             logger_info(f'huh, we find {release}.')
             for qqgroup in check_enable_modules_all(
                     'group_permission', 'mcv_rss'):
                 try:
                     await app.sendGroupMessage(
                         int(qqgroup),
                         MessageChain.create([
                             Plain('启动器已更新' + file['latest']['release'] +
                                   '正式版。')
                         ]))
                     await asyncio.sleep(0.5)
                 except Exception:
                     traceback.print_exc()
             for qqfriend in check_enable_modules_all(
                     'friend_permission', 'mcv_rss'):
                 try:
                     await app.sendFriendMessage(
                         int(qqfriend),
                         MessageChain.create([
                             Plain('启动器已更新' + file['latest']['release'] +
                                   '正式版。')
                         ]))
                     await asyncio.sleep(0.5)
                 except Exception:
                     traceback.print_exc()
             addversion = open(version_file, 'a')
             addversion.write('\n' + release)
             addversion.close()
             verlist = getfileversions(version_file)
         if snapshot not in verlist:
             logger_info(f'huh, we find {snapshot}.')
             for qqgroup in check_enable_modules_all(
                     'group_permission', 'mcv_rss'):
                 try:
                     await app.sendGroupMessage(
                         int(qqgroup),
                         MessageChain.create([
                             Plain('启动器已更新' + file['latest']['snapshot'] +
                                   '快照。')
                         ]))
                     await asyncio.sleep(0.5)
                 except Exception:
                     traceback.print_exc()
             for qqfriend in check_enable_modules_all(
                     'friend_permission', 'mcv_rss'):
                 try:
                     await app.sendFriendMessage(
                         int(qqfriend),
                         MessageChain.create([
                             Plain('启动器已更新' + file['latest']['snapshot'] +
                                   '快照。')
                         ]))
                     await asyncio.sleep(0.5)
                 except Exception:
                     traceback.print_exc()
             addversion = open('./assets/mcversion.txt', 'a')
             addversion.write('\n' + snapshot)
             addversion.close()
         logger_info('mcv checked.')
     except Exception:
         traceback.print_exc()
Пример #6
0
async def slk_converter(filepath):
    filepath2 = filepath + '.silk'
    logger_info('Start encoding voice...')
    os.system('python slk_coder.py ' + filepath)
    logger_info('Voice encoded.')
    return filepath2