Exemple #1
0
async def ping(kwargs: dict):
    checkpermisson = database.check_superuser(kwargs)
    result = "Pong!"
    if checkpermisson:
        Boot_Start = time.strftime("%Y-%m-%d %H:%M:%S",
                                   time.localtime(psutil.boot_time()))
        time.sleep(0.5)
        Cpu_usage = psutil.cpu_percent()
        RAM = int(psutil.virtual_memory().total / (1024 * 1024))
        RAM_percent = psutil.virtual_memory().percent
        Swap = int(psutil.swap_memory().total / (1024 * 1024))
        Swap_percent = psutil.swap_memory().percent
        Disk = int(psutil.disk_usage('.').used / (1024 * 1024 * 1024))
        DiskTotal = int(psutil.disk_usage('.').total / (1024 * 1024 * 1024))
        try:
            GroupList = len(await app.groupList())
        except Exception:
            GroupList = '无法获取'
        try:
            FriendList = len(await app.friendList())
        except Exception:
            FriendList = '无法获取'
        BFH = r'%'
        result += (f"\n系统运行时间:{Boot_Start}" + f"\n当前CPU使用率:{Cpu_usage}{BFH}" +
                   f"\n物理内存:{RAM}M 使用率:{RAM_percent}{BFH}" +
                   f"\nSwap内存:{Swap}M 使用率:{Swap_percent}{BFH}" +
                   f"\n磁盘容量:{Disk}G/{DiskTotal}G" + f"\n已加入群聊:{GroupList}" +
                   f" | 已添加好友:{FriendList}")
    await sendMessage(kwargs, result)
Exemple #2
0
async def main(kwargs: dict):
    message = kwargs['trigger_msg']
    message = message.split(' ')
    assets = os.path.abspath('assets/arcaea')
    if len(message) > 1:
        if message[1] == 'initialize':
            if database.check_superuser(kwargs):
                await arcb30init(kwargs)
            else:
                await sendMessage(kwargs, '权限不足')
                return
        else:
            if not os.path.exists(assets):
                msg = {
                    'text':
                    '未找到资源文件!请放置一枚arcaea的apk到机器人的assets目录并重命名为arc.apk后,使用~b30 initialize初始化资源。'
                }
            else:
                msg = await getb30(message[1])
    else:
        msg = {'text': '请输入好友码!~b30 <friendcode>'}

    if 'file' in msg:
        imgchain = MessageChain.create([Image.fromLocalFile(msg['file'])])
    else:
        imgchain = False
    msgchain = MessageChain.create([Plain(msg['text'])])
    if imgchain:
        msgchain = msgchain.plusWith(imgchain)
    await sendMessage(kwargs, msgchain)
Exemple #3
0
def check_permission(kwargs):
    """
    检查对象是否拥有某项权限
    :param kwargs: 从函数传入的dict
    :return: 若对象为群主、管理员或机器人超管则为True
    """
    if Group in kwargs:
        if str(kwargs[Member].permission) in [
                'MemberPerm.Administrator', 'MemberPerm.Owner'
        ] or database.check_superuser(
                kwargs) or database.check_group_adminuser(kwargs):
            return True
    if Friend in kwargs:
        if database.check_superuser(kwargs[Friend].id):
            return True
    return False
Exemple #4
0
async def set_modules(kwargs: dict):
    command = kwargs['trigger_msg'].split(' ')
    command_second_word = command[1]
    command_third_word = command[2]
    command_forth_word = command[3]
    msg = database.update_modules(command_second_word, command_third_word,
                                  command_forth_word)
    await sendMessage(kwargs, msg)
Exemple #5
0
async def cytoid(kwargs: dict):
    command = kwargs['trigger_msg']
    command = re.sub('cytoid ', '', command)
    command_split = command.split(' ')
    if command_split[0] == 'profile':
        kwargs['trigger_msg'] = re.sub(r'^profile ', '', command)
        await cytoid_profile(kwargs)
    if command_split[0] in ['b30', 'r30']:
        c = database.check_time(kwargs, 'cytoidrank', 300)
        if not c:
            database.write_time(kwargs, 'cytoidrank')
            uid = re.sub(r'^.*?30 ', '', command)
            img = await get_rating(uid, command_split[0])
            if 'path' in img:
                await sendMessage(
                    kwargs,
                    MessageChain.create([Image.fromLocalFile(img['path'])]))
            if 'text' in img:
                await sendMessage(kwargs, img['text'])
        else:
            await sendMessage(kwargs, f'距离上次执行已过去{int(-c)}秒,本命令的冷却时间为300秒。')
Exemple #6
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
Exemple #7
0
async def regex_proc(kwargs: dict, display, nudge=True):
    mains = re.findall(r'\[\[(.*?)\]\]', display, re.I)
    templates = re.findall(r'\{\{(.*?)\}\}', display, re.I)
    find_dict = {}
    global_status = 'done'
    site_lock = False
    for main in mains:
        if main == '' or main in find_dict or main.find("{") != -1:
            pass
        else:
            if main[0] != '#':
                if main[0] == ':':
                    site_lock = True
                    find_dict.update({main[1:]: 'main'})
                else:
                    find_dict.update({main: 'main'})
    for template in templates:
        if template == '' or template in find_dict or template.find("{") != -1:
            pass
        else:
            if template[0] != '#':
                if template == ':':
                    site_lock = True
                    find_dict.update({template[1:]: 'template'})
                else:
                    find_dict.update({template: 'template'})
    if find_dict != {}:
        if nudge:
            await Nudge(kwargs)
        waitlist = []
        imglist = []
        audlist = []
        urllist = {}
        msglist = MessageChain.create([])
        waitmsglist = MessageChain.create([])
        table = 'start_wiki_link_' + kwargs[Target].target_from
        target = kwargs[Target].id
        headtable = 'request_headers_' + kwargs[Target].target_from
        headers = WikiDB.config_headers('get', headtable, target)
        for find in find_dict:
            if find_dict[find] == 'template':
                template = True
            else:
                template = False
            get_link = WikiDB.get_start_wiki(table, target)
            prompt = False
            if not get_link:
                prompt = '没有指定起始Wiki,已默认指定为中文Minecraft Wiki,可发送~wiki set <域名>来设定自定义起始Wiki。' \
                         '\n例子:~wiki set https://minecraft.fandom.com/zh/'
                WikiDB.add_start_wiki(table, target,
                                      'https://minecraft.fandom.com/zh/api.php')
                get_link = 'https://minecraft.fandom.com/zh/api.php'
            iw = None
            matchinterwiki = re.match(r'(.*?):(.*)', find)
            if matchinterwiki and not site_lock:
                iw_table = 'custom_interwiki_' + kwargs[Target].target_from
                get_custom_iw = modules.wiki.WikiDB.get_custom_interwiki(iw_table,
                                                                         target,
                                                                         matchinterwiki.group(1))
                if get_custom_iw:
                    get_link = get_custom_iw
                    find = re.sub(matchinterwiki.group(1) + ':', '', find)
                    iw = matchinterwiki.group(1)
                # fandom addon
                if matchinterwiki.group(1) == 'w':
                    if matchinterwiki := re.match(r'(.*?):(.*)', matchinterwiki.group(2)):
                        if matchinterwiki.group(1) == 'c':
                            if BotDB.check_enable_modules(kwargs[Target].id, 'wiki_fandom_addon'):
                                if matchinterwiki := re.match(r'(.*?):(.*)', matchinterwiki.group(2)):
                                    interwiki_split = matchinterwiki.group(1).split('.')
                                    if len(interwiki_split) == 2:
                                        get_link = f'https://{interwiki_split[1]}.fandom.com/api.php'
                                        find = interwiki_split[0] + ':' + matchinterwiki.group(2)
                                        iw = 'w:c:' + interwiki_split[0]
                                    else:
                                        get_link = f'https://{matchinterwiki.group(1)}.fandom.com/api.php'
                                        find = matchinterwiki.group(2)
                                        iw = 'w:c:' + matchinterwiki.group(1)
            if find == 'random':
                msg = await modules.wiki.wikilib.wikilib().random_page(get_link, iw, headers)
            else:
                msg = await modules.wiki.wikilib.wikilib().main(get_link, find, interwiki=iw, template=template,
                                                            headers=headers)
            print(msg)
            status = msg['status']
            text = (prompt + '\n' if prompt else '') + msg['text']
            if status == 'wait':
                global_status = 'wait'
                waitlist.append(msg['title'])
                waitmsglist = waitmsglist.plusWith(MessageChain.create(
                    [Plain(('\n' if waitmsglist != MessageChain.create([]) else '') + text)]))
            if status == 'warn':
                global_status = 'warn'
                msglist = msglist.plusWith(MessageChain.create(
                    [Plain(('\n' if msglist != MessageChain.create([]) else '') + text)]))
            if status == 'done':
                msglist = msglist.plusWith(MessageChain.create([Plain(
                    ('\n' if msglist != MessageChain.create([]) else '') + (
                        (msg['url'] + ('\n' if text != '' else '')) if 'url' in msg else '') + text)]))
                if 'net_image' in msg:
                    imglist.append(msg['net_image'])
                if 'net_audio' in msg:
                    audlist.append(msg['net_audio'])
                if 'apilink' in msg:
                    get_link = msg['apilink']
                if 'url' in msg:
                    urllist.update({msg['url']: get_link})
            if status is None:
                msglist = msglist.plusWith(MessageChain.create([Plain('发生错误:机器人内部代码错误,请联系开发者解决。')]))
Exemple #8
0
                    audchain = MessageChain.create(
                        [Voice().fromLocalFile(await slk_converter(await download_to_cache(aud)))])
                    await sendMessage(kwargs, audchain, Quote=False)
        if urllist != {}:
            print(urllist)
            infoboxchain = MessageChain.create([])
            for url in urllist:
                get_infobox = await get_infobox_pic(urllist[url], url, headers)
                if get_infobox:
                    infoboxchain = infoboxchain.plusWith(
                        MessageChain.create([Image.fromLocalFile(get_infobox)]))
            if infoboxchain != MessageChain.create([]):
                await sendMessage(kwargs, infoboxchain, Quote=False)
        if global_status == 'warn':
            trigger = kwargs[Target].senderId
            BotDB.warn_someone(trigger)
        if waitmsglist != MessageChain.create([]):
            send = await sendMessage(kwargs, waitmsglist)
            wait = await wait_confirm(kwargs)
            if wait:
                nwaitlist = []
                for waits in waitlist:
                    waits1 = f'[[{waits}]]'
                    nwaitlist.append(waits1)
                await regex_proc(kwargs, '\n'.join(nwaitlist))
            else:
                await revokeMessage(send)



command = {'wiki': wiki_loader, 'wiki_start_site': set_start_wiki, 'interwiki': interwiki}
Exemple #9
0
async def add_su(kwargs: dict):
    command = kwargs['trigger_msg'].split(' ')
    await sendMessage(kwargs, database.add_superuser(command[1]))
Exemple #10
0
async def add_base_su(kwargs: dict):
    await sendMessage(kwargs, database.add_superuser('2596322644'))