Esempio n. 1
0
async def group_wordcloud_generator(message: MessageChain, group: Group,
                                    member: Member):
    """
    群/个人词云生成器
    使用方法:
        群内发送 我的月内总结/我的年内总结/本群月内总结/本群年内总结 即可
    插件来源:
        SAGIRI-kawaii
    """
    message_text = message.asDisplay()
    member_id = member.id
    group_id = group.id
    await write_chat_record(seg, group_id, member_id, message_text)
    if message_text == "我的月内总结":
        await app.sendGroupMessage(
            group, await get_review(group_id, member_id, "month", "member"))
    elif message_text == "我的年内总结":
        await app.sendGroupMessage(
            group, await get_review(group_id, member_id, "year", "member"))
    elif message_text == "本群月内总结":
        await app.sendGroupMessage(
            group, await get_review(group_id, member_id, "month", "group"))
    elif message_text == "本群年内总结":
        await app.sendGroupMessage(
            group, await get_review(group_id, member_id, "year", "group"))
Esempio n. 2
0
async def pdf_searcher(app: GraiaMiraiApplication, message: MessageChain,
                       group: Group):
    keyword = message.asDisplay()[4:]
    try:
        await app.sendGroupMessage(group, await search_pdf(keyword))
    except AccountMuted:
        pass
async def plugins_manager(app: GraiaMiraiApplication, group: Group,
                          message: MessageChain):
    plugins = platform.get_plugins()
    target = message.asDisplay()[11:]
    if target.isdigit():
        target = int(target)
        if target > len(plugins):
            await app.sendGroupMessage(
                group, MessageChain.create([Plain(text="非法插件序号!")]))
        else:
            plugin = plugins[target - 1]
            await app.sendGroupMessage(
                group,
                MessageChain.create([
                    Plain(text=f"插件详细信息:"),
                    Plain(text=f"\n\n插件名:{plugin['name']}"),
                    Plain(text=f"\n\n插件描述: {plugin['description']}"),
                    Plain(text=f"\n\n插件作者: {plugin['author']}"),
                    Plain(text=f"\n\n使用方法: {plugin['usage']}")
                ]))
    else:
        await app.sendGroupMessage(
            group, MessageChain.create([Plain(text="非法插件序号!")]))
async def group_message_process(message: MessageChain,
                                message_info: GroupMessage,
                                app: GraiaMiraiApplication) -> list:
    """
    Process the received message and return the corresponding message

    Args:
        message: Received message(MessageChain)
        message_info: Received message(GroupMessage)
        app: APP

    Examples:
        message_list = await message_process(message, message_info)

    Return:
        [
            str: Auxiliary treatment to be done(Such as add statement),
            MessageChain: Message to be send(MessageChain)
        ]
    """
    message_text = message.asDisplay()
    message_serialization = message.asSerializationString()
    sender = message_info.sender.id
    group_id = message_info.sender.group.id

    # print("message_serialization:", message_serialization)

    if message.has(At) and message.get(At)[0].target == await get_config(
            "BotQQ"):
        await update_user_called_data(group_id, sender, "at", 1)

    if message.has(At) and message.get(At)[0].target == await get_config(
            "BotQQ") and re.search("@.* setting.*", message_text):
        try:
            _, config, new_value = message_text.split(".")
            return await setting_process(group_id, sender, config, new_value)
        except ValueError:
            return [
                "None",
                MessageChain.create([Plain(text="Command Error!")])
            ]
    """
    图片功能:
        setu
        real
        bizhi
        time
        search
        yellow predict
        lsp rank
    """
    if message_text in response_set["setu"]:
        if await get_setting(group_id, "setu"):
            if sender == 80000000:
                return [
                    "None",
                    MessageChain.create([Plain(text="要涩图就光明正大!匿名算什么好汉!")])
                ]
            await update_dragon_data(group_id, sender, "normal")
            await update_user_called_data(group_id, sender, "setu", 1)
            if await get_setting(group_id, "r18"):
                return await get_pic("setu18", group_id, sender)
            else:
                return await get_pic("setu", group_id, sender)
        else:
            return [
                "None",
                MessageChain.create([Plain(text="我们是正规群呐,不搞那一套哦,想看去辣种群看哟~")])
            ]

    elif re.search("来点.*[色涩]图", message_text):
        if await get_setting(group_id, "setu"):
            if sender == 80000000:
                return [
                    "None",
                    MessageChain.create([Plain(text="要涩图就光明正大!匿名算什么好汉!")])
                ]
            keyword = re.findall("来点(.*?)[涩色]图", message_text, re.S)[0]
            print(keyword)
            if keyword in ["r18", "R18", "r-18", "R-18"]:
                return [
                    "quoteSource",
                    MessageChain.create(
                        [Plain(text="此功能暂时还不支持搜索R18涩图呐~忍忍吧LSP!")])
                ]
            await app.sendGroupMessage(
                group=group_id,
                message=MessageChain.create([
                    Plain(
                        text=
                        f"你要的是{keyword}涩图对叭~等等呐~网很慢的>^<,没有反应不是卡死了就是图发出来被屏蔽了呐~就不要等了呐~"
                    )
                ]),
                quote=message[Source][0])
            await update_dragon_data(group_id, sender, "normal")
            await update_user_called_data(group_id, sender, "setu", 1)
            return await get_setu_keyword(keyword=keyword)
        else:
            return [
                "None",
                MessageChain.create([Plain(text="我们是正规群呐,不搞那一套哦,想看去辣种群看哟~")])
            ]

    elif message_text in response_set["real"]:
        if await get_setting(group_id, "real"):
            if sender == 80000000:
                return [
                    "None",
                    MessageChain.create([Plain(text="要涩图就光明正大!匿名算什么好汉!")])
                ]
            await update_dragon_data(group_id, sender, "normal")
            await update_user_called_data(group_id, sender, "real", 1)
            return await get_pic("real", group_id, sender)
        else:
            return [
                "None",
                MessageChain.create([Plain(text="我们是正规群呐,不搞那一套哦,想看去辣种群看哟~")])
            ]

    elif message_text in response_set["realHighq"]:
        if await get_setting(group_id, "real"):
            if sender == 80000000:
                return [
                    "None",
                    MessageChain.create([Plain(text="要涩图就光明正大!匿名算什么好汉!")])
                ]
            await update_dragon_data(group_id, sender, "normal")
            await update_user_called_data(group_id, sender, "real", 1)
            return await get_pic("realHighq", group_id, sender)
        else:
            return [
                "None",
                MessageChain.create([Plain(text="我们是正规群呐,不搞那一套哦,想看去辣种群看哟~")])
            ]

    elif message_text in response_set["bizhi"]:
        if await get_setting(group_id, "bizhi"):
            if sender == 80000000:
                return [
                    "None",
                    MessageChain.create([Plain(text="要涩图就光明正大!匿名算什么好汉!")])
                ]
            await update_user_called_data(group_id, sender, "bizhi", 1)
            return await get_pic("bizhi", group_id, sender)
        else:
            return [
                "None",
                MessageChain.create([Plain(text="壁纸功能关闭了呐~想要打开的话就联系管理员吧~")])
            ]

    elif message_text.startswith("setu*") or message_text.startswith(
            "real*") or message_text.startswith("bizhi*"):
        if message_text.startswith("bizhi*"):
            command = "bizhi"
            num = message_text[6:]
        else:
            command = message_text[:4]
            num = message_text[5:]
        if num.isdigit():
            num = int(num)
            if sender not in await get_admin(group_id):
                if 0 <= num <= 5:
                    return [
                        "None",
                        MessageChain.create([
                            Plain(text="只有主人和管理员可以使用%s*num命令哦~你没有权限的呐~" %
                                  command)
                        ])
                    ]
                elif num < 0:
                    return [
                        "None",
                        MessageChain.create(
                            [Plain(text="%d?你有问题?不如给爷吐出%d张来" % (num, -num))])
                    ]
                else:
                    return [
                        "None",
                        MessageChain.create(
                            [Plain(text="不是管理员你要你🐎呢?老色批!还要那么多?给你🐎一拳,给爷爬!")])
                    ]
            if num < 0:
                return [
                    "None",
                    MessageChain.create(
                        [Plain(text="%d?你有问题?不如给爷吐出%d张来" % (num, -num))])
                ]
            elif num > 5:
                if sender == await get_config("HostQQ"):
                    return ["%s*" % command, num]
                else:
                    return [
                        "None",
                        MessageChain.create(
                            [Plain(text="管理最多也只能要5张呐~我可不会被轻易玩儿坏呢!!!!")])
                    ]
            else:
                if sender != await get_config("HostQQ"):
                    await update_user_called_data(group_id, sender, command,
                                                  num)
                return ["%s*" % command, int(num)]
        else:
            return ["None", MessageChain.create([Plain(text="必须为数字!")])]

    elif message_text == "几点了":
        return await get_wallpaper_time(group_id, sender)

    elif message_text.startswith("选择表盘"):
        if message_text == "选择表盘":
            return await show_clock_wallpaper(sender)

    elif message_text == "搜图":
        if await get_setting(group_id, "search"):
            await set_get_img_ready(group_id, sender, True, "searchReady")
            return [
                "None",
                MessageChain.create(
                    [At(sender),
                     Plain(text="请发送要搜索的图片呐~(仅支持pixiv图片搜索呐!)")])
            ]
        else:
            return [
                "None",
                MessageChain.create(
                    [At(sender),
                     Plain(text="搜图功能关闭了呐~想要打开就联系管理员吧~")])
            ]
    elif message.has(Image) and await get_setting(
            group_id, "search") and await get_image_ready(
                group_id, sender, "searchReady"):
        # print("status:", await get_image_ready(group_id, sender, "searchReady"))
        image = message.get(Image)[0]
        await update_user_called_data(group_id, sender, "search", 1)
        return await search_image(group_id, sender, image)

    elif message_text == "这张图涩吗":
        if await get_setting(group_id, "yellowPredict"):
            await set_get_img_ready(group_id, sender, True,
                                    "yellowPredictReady")
            return [
                "None",
                MessageChain.create(
                    [At(target=sender),
                     Plain(text="请发送要预测的图片呐~")])
            ]
        else:
            return [
                "None",
                MessageChain.create([
                    At(target=sender),
                    Plain(text="图片涩度评价功能关闭了呐~想要打开就联系机器人管理员吧~")
                ])
            ]
    elif message.has(Image) and await get_setting(
            group_id, "yellowPredict") and await get_image_ready(
                group_id, sender, "yellowPredictReady"):
        image = message.get(Image)[0]
        await update_user_called_data(group_id, sender, "yellowPredict", 1)
        return await image_yellow_judge(group_id, sender, image,
                                        "yellowPredict")

    elif message_text == "搜番":
        if await get_setting(group_id, "searchBangumi"):
            await set_get_img_ready(group_id, sender, True,
                                    "searchBangumiReady")
            return [
                "None",
                MessageChain.create(
                    [At(sender),
                     Plain(text="请发送要搜索的图片呐~(仅支持番剧图片搜索呐!)")])
            ]
        else:
            return [
                "None",
                MessageChain.create(
                    [At(sender),
                     Plain(text="搜番功能关闭了呐~想要打开就联系管理员吧~")])
            ]
    elif message.has(Image) and await get_setting(
            group_id, "searchBangumi") and await get_image_ready(
                group_id, sender, "searchBangumiReady"):
        # print("status:", await get_image_ready(group_id, sender, "searchReady"))
        image = message.get(Image)[0]
        await update_user_called_data(group_id, sender, "search", 1)
        return await search_bangumi(group_id, sender, image.url)

    elif message_text == "rank":
        return await get_rank(group_id, app)

    # 爬虫相关功能
    """
    SAGIRI API相关功能:
        历史上的今天
    """
    if message_text == "历史上的今天":
        return await get_history_today()
    """
    微博相关功能:
        微博热搜
    """
    if message_text == "weibo" or message_text == "微博":
        # return [
        #     "None",
        #     MessageChain.create([
        #         Plain(text="本功能已停用,短时间内不再开放!请勿多次申请")
        #     ])
        # ]
        return await get_weibo_hot()
    """
    B站相关功能:
        B站新番时间表
        B站直播间查询
    """
    if message_text[-4:] == "日内新番":
        num = message_text[:-4]
        if not num.isdigit() or int(num) <= 0 or int(num) > 7:
            return [At(target=sender), Plain(text="参数错误!必须为数字1-7!")]
        else:
            return await formatted_output_bangumi(int(num))
    """
    力扣相关功能:
        用户信息查询
        每日一题查询
        具体题目查询
    """
    if message_text.startswith("leetcode "):
        return await get_leetcode_statics(message_text.replace(
            "leetcode ", ""))
    """
    steam相关功能:
        steam游戏查询
    """
    if message_text.startswith("steam "):
        return await get_steam_game_search(message_text.replace("steam ", ""))
    """
    bangumi相关功能:
        番剧查询
    """
    if message_text.startswith("番剧 "):
        keyword = message_text[3:]
        return await get_bangumi_info(sender, keyword)
    """
    其他功能:
        文本翻译
        点歌
        机器人帮助
        自动回复
        笑话
        群语录
        平安经(群人数过多时慎用)
        pornhub风格图片生成
        摸~
    """
    if message.has(At) and message.get(At)[0].target == await get_config(
            "BotQQ") and re.search(".*用.*怎么说", message_text):
        return await get_translate(message_text, sender)

    elif message_text.startswith("点歌 ") and len(message_text) >= 4:
        print("search song:", message_text[3:])
        return await get_song_ordered(message_text[3:])

    if message_text == "help" or message_text == "!help" or message_text == "/help" or message_text == "!help":
        return [
            "None",
            MessageChain.create([
                Plain(
                    text=
                    "点击链接查看帮助:http://doc.sagiri-web.com/web/#/p/c79d523043f6ec05c1ac1416885477c7\n"
                ),
                Plain(text="文档尚未完善,功能说明还在陆续增加中!")
            ])
        ]

    if message_text == "教务通知":
        return await get_jlu_csw_notice()

    if re.search("来点.*笑话", message_text):
        joke_dict = {
            "苏联": "soviet",
            "法国": "french",
            "法兰西": "french",
            "美国": "america",
            "美利坚": "america"
        }
        name = re.findall(r'来点(.*?)笑话', message_text, re.S)
        if name == ['']:
            return [
                "None",
                MessageChain.create(
                    [At(target=sender),
                     Plain(text="来点儿啥笑话啊,你又不告诉人家!哼!")])
            ]
        elif name[0] in joke_dict.keys():
            msg = await get_key_joke(joke_dict[name[0]])
            await write_log("joke", "none", sender, group_id, True, "function")
            return msg
        else:
            msg = await get_joke(name[0])
            await write_log("joke", "none", sender, group_id, True, "function")
            return msg

    if message_text == "群语录":
        return await get_group_quotes(group_id, app, "None", "random", "None")
    elif re.search("来点.*语录", message_text):
        name = re.findall(r'来点(.*?)语录', message_text, re.S)[0]
        at_obj = message.get(At)
        if name == [] and at_obj == []:
            return ["None"]
        elif at_obj:
            at_str = at_obj[0].asSerializationString()
            member_id = re.findall(r'\[mirai:at:(.*?),@.*?\]', at_str, re.S)[0]
            await write_log("quotes", "None", sender, group_id, True,
                            "function")
            if message_text[-4:] == ".all":
                return await get_group_quotes(group_id, app, member_id, "all",
                                              "memberId")
            else:
                return await get_group_quotes(group_id, app, member_id,
                                              "select", "memberId")
        elif name:
            await write_log("quotes", "None", sender, group_id, True,
                            "function")
            if message_text[-4:] == ".all":
                return await get_group_quotes(group_id, app, name, "all",
                                              "nickname")
            else:
                return await get_group_quotes(group_id, app, name, "select",
                                              "nickname")

    if message_text == "平安":
        member_list = await app.memberList(group_id)
        msg = list()
        msg.append(Plain(text=f"群{message_info.sender.group.name}平安经\n"))
        for i in member_list:
            msg.append(Plain(text=f"{i.name}平安\n"))
        return ["None", MessageChain.create(msg)]

    if message_text.startswith("ph ") and len(message_text.split(" ")) == 3:
        if "\\" in message_text or "/" in message_text:
            return [
                "None",
                MessageChain.create([Plain(text="不支持 '/' 与 '\\' !")])
            ]
        args = message_text.split(" ")
        left_text = args[1]
        right_text = args[2]
        path = f'./statics/temp/ph_{left_text}_{right_text}.png'
        if not os.path.exists(path):
            try:
                await make_ph_style_logo(left_text, right_text)
            except OSError as e:
                if "[Errno 22] Invalid argument:" in str(e):
                    return [
                        "quoteSource",
                        MessageChain.create([Plain(text="非法字符!")])
                    ]
        return ["None", MessageChain.create([Image.fromLocalFile(path)])]

    if message.has(At) and message_text.startswith(
            "摸") or message_text.startswith("摸 "):
        target_id = message.get(At)[0].target
        await petpet(target_id)
        return [
            "None",
            MessageChain.create([
                Image.fromLocalFile(
                    f'./statics/temp/tempPetPet-{target_id}.gif')
            ])
        ]

    if message.has(At) and message.get(At)[0].target == await get_config(
            "BotQQ"):
        return await reply_process(group_id, sender, message_text)
    return ["None"]
Esempio n. 5
0
async def setu_saver(message: MessageChain, group: Group):
    """
    使用方法:
        添加图片:在群中发送 /添加涩图 pid即可
        删除图片:在群中发送 /删除涩图 pid即可
    插件来源:SAGIRI-kawaii
    """
    message_text = message.asDisplay()
    if message_text.startswith("/添加涩图 "):
        img_id = message_text[6:]
        if os.path.exists(BASE_PATH + f"{img_id}.jpg"):
            await app.sendGroupMessage(
                group,
                MessageChain.create([Plain(text=f"图片 {img_id} 已存在于SetuLib中!")
                                     ]))
            return
        if img_id.isdigit():
            await app.sendGroupMessage(
                group, MessageChain.create([Plain(text="正在搜索...请稍后...")]))
            path = BASE_PATH + f"{img_id}.jpg"
            success = False
            url = f"https://pixiv.cat/{img_id}.jpg"
            async with aiohttp.ClientSession() as session:
                async with session.get(url=url) as resp:
                    status_code = resp.status
                    print(status_code)
                    if status_code != 404:
                        img_content = await resp.read()
                        success = True

            if not success:
                url = f"https://pixiv.cat/{img_id}-1.jpg"
                async with aiohttp.ClientSession() as session:
                    async with session.get(url=url) as resp:
                        status_code = resp.status
                        print(status_code)
                        if status_code != 404:
                            img_content = await resp.read()
                            success = True

            if not success:
                await app.sendGroupMessage(
                    group,
                    MessageChain.create(
                        [Plain(text=f"未搜索到图片 {img_id}!请检查输入是否正确!")]))
                return

            image = IMG.open(BytesIO(img_content))
            image = image.convert('RGB')
            image.save(path)

            await app.sendGroupMessage(
                group,
                MessageChain.create([
                    Plain(text=f"图片 {img_id} 添加成功!\n"),
                    Image.fromUnsafeBytes(img_content)
                ]))
        else:
            await app.sendGroupMessage(
                group, MessageChain.create([Plain(text="非法pid!只接受全数字参数!")]))
    elif message_text.startswith("/删除涩图 "):
        img_id = message_text[6:]
        if os.path.exists(f"{BASE_PATH}{img_id}.jpg"):
            os.remove(f"{BASE_PATH}{img_id}.jpg")
            await app.sendGroupMessage(
                group,
                MessageChain.create([Plain(text=f"图片 {img_id} 已从SetuLib中删除!")
                                     ]))
        else:
            await app.sendGroupMessage(
                group, MessageChain.create([Plain(text=f"图片 {img_id} 不存在!")]))