Exemple #1
0
async def lolicon_keyword_searcher(
    app: Ariadne, message: MessageChain, group: Group, keyword: RegexResult
):
    keyword = keyword.result.asDisplay()
    msg_chain = await get_image(group, keyword)
    if msg_chain.onlyContains(Plain):
        return await app.sendGroupMessage(
            group, msg_chain, quote=message.getFirst(Source)
        )
    mode = await group_setting.get_setting(group, Setting.r18_process)
    r18 = await group_setting.get_setting(group, Setting.r18)
    if mode == "revoke" and r18:
        msg = await app.sendGroupMessage(
            group, msg_chain, quote=message.getFirst(Source)
        )
        await asyncio.sleep(20)
        await app.recallMessage(msg)
    elif mode == "flashImage" and r18:
        await app.sendGroupMessage(
            group, msg_chain.exclude(Image), quote=message.getFirst(Source)
        )
        await app.sendGroupMessage(
            group, MessageChain.create([msg_chain.getFirst(Image).toFlashImage()])
        )
    else:
        await app.sendGroupMessage(group, msg_chain, quote=message.getFirst(Source))
async def group_wordcloud_generator(
    app: Ariadne,
    message: MessageChain,
    group: Group,
    member: Member,
    scope: MatchResult,
    period: MatchResult,
    topK: MatchResult,
    mask: ElementResult
):
    scope = "group" if scope.result.asDisplay() == "本群" else "member"
    if scope == "group" and not await user_permission_require(group, member, 2):
        return await app.sendGroupMessage(
            group,
            MessageChain.create([Plain(text="权限不足呢~爪巴!")]),
            quote=message.getFirst(Source),
        )

    period = period.result.asDisplay()
    topK = min(int(topK.result.asDisplay()), 100000) if topK.matched else 1000
    await app.sendGroupMessage(
        group,
        await GroupWordCloudGenerator.get_review(group, member, period, scope, topK, mask.result),
        quote=message.getFirst(Source),
    )
async def dd_check(app: Ariadne, group: Group, message: MessageChain, username: RegexResult):
    if not username.result.asDisplay().strip():
        return await app.sendGroupMessage(group, MessageChain("空白名怎么查啊kora!"), quote=message.getFirst(Source))
    res = await get_reply(username.result.asDisplay().strip())
    await app.sendGroupMessage(
        group,
        MessageChain(res if isinstance(res, str) else [Image(data_bytes=res)]),
        quote=message.getFirst(Source)
    )
Exemple #4
0
async def emoji_mix(app: Ariadne, message: MessageChain, group: Group,
                    emoji1: RegexResult, emoji2: RegexResult):
    emoji1 = emoji1.result.asDisplay()
    emoji2 = emoji2.result.asDisplay()
    result = await mix_emoji(emoji1, emoji2)
    if isinstance(result, str):
        await app.sendGroupMessage(group,
                                   MessageChain(result),
                                   quote=message.getFirst(Source))
    elif isinstance(result, bytes):
        await app.sendGroupMessage(group,
                                   MessageChain([Image(data_bytes=result)]),
                                   quote=message.getFirst(Source))
async def genshin_resource_points(app: Ariadne, message: MessageChain,
                                  group: Group, resource_name: RegexResult):
    resource_name = resource_name.result.asDisplay().strip()
    if check_resource_exists(resource_name):
        await get_resource_list()
        await app.sendGroupMessage(group, MessageChain("正在生成位置...."))
        await app.sendGroupMessage(group,
                                   await query_resource(resource_name),
                                   quote=message.getFirst(Source))
    else:
        await app.sendGroupMessage(
            group,
            MessageChain(f"未查找到 {resource_name} 资源,可通过 “原神资源列表” 获取全部资源名称.."),
            quote=message.getFirst(Source))
Exemple #6
0
async def random_character(app: Ariadne, message: MessageChain, group: Group):
    await app.sendGroupMessage(group,
                               MessageChain("\n".join([
                                   f"{k}:{random.choice(character_dict[k])}"
                                   for k in character_dict.keys()
                               ])),
                               quote=message.getFirst(Source))
Exemple #7
0
async def gacha(app: Ariadne, group: Group, message: MessageChain,
                member: Member, count: RegexResult):
    gid = group.id
    user_id = member.id
    count = int(count.result.asDisplay())
    if all([
            count == 10 and not daily_limiter_10.check(user_id), count == 90
            and not daily_limiter_90.check(user_id), count == 180
            and not daily_limiter_180.check(user_id)
    ]):
        await app.sendMessage(
            group, MessageChain.create([Plain(text='今天已经抽了很多次啦,明天再来吧~')]))
        return
    if gid in group_pool:
        G = Gacha(group_pool[gid])
    else:
        G = Gacha()
    if count == 10:
        daily_limiter_10.increase(user_id)
    elif count == 90:
        daily_limiter_90.increase(user_id)
    else:
        daily_limiter_180.increase(user_id)
    await app.sendMessage(group,
                          G.gacha_10() if count == 10 else
                          (G.gacha_90() if count == 90 else G.gacha_90(180)),
                          quote=message.getFirst(Source))
async def image_searcher(app: Ariadne, message: MessageChain, group: Group, member: Member, image: ElementResult):

    @Waiter.create_using_function(listening_events=[GroupMessage])
    async def image_waiter(
        waiter_group: Group, waiter_member: Member, waiter_message: MessageChain
    ):
        if waiter_group.id == group.id and waiter_member.id == member.id:
            if waiter_message.has(Image):
                return waiter_message.getFirst(Image).url
            else:
                return False

    if not image.matched:
        try:
            await app.sendMessage(
                group, MessageChain.create("请在30s内发送要处理的图片"), quote=message[Source][0]
            )
            image = await asyncio.wait_for(inc.wait(image_waiter), 30)
            if not image:
                return await app.sendGroupMessage(
                    group, MessageChain("未检测到图片,请重新发送,进程退出"), quote=message.getFirst(Source)
                )
        except asyncio.TimeoutError:
            return await app.sendGroupMessage(
                group, MessageChain("图片等待超时,进程退出"), quote=message.getFirst(Source)
            )
    else:
        image = image.result.url
    await app.sendGroupMessage(group, MessageChain("已收到图片,正在进行搜索..."), quote=message.getFirst(Source))
    tasks = [
        asyncio.create_task(saucenao_search(SAUCENAO_API_KEY, proxy, url=image)),
        asyncio.create_task(ascii2d_search(proxy, url=image)),
        asyncio.create_task(ehentai_search(proxy, url=image)),
        asyncio.create_task(google_search(proxy, url=image)),
        asyncio.create_task(baidu_search(url=image))
    ]
    msgs = await asyncio.gather(*tasks)
    await app.sendGroupMessage(group, MessageChain([
        Forward([
            ForwardNode(
                senderId=config.bot_qq,
                time=datetime.now(),
                senderName="SAGIRI BOT",
                messageChain=msg,
            ) for msg in msgs
        ])
    ]))
Exemple #9
0
async def memes(app: Ariadne, message: MessageChain, group: Group,
                prefix: RegexResult, content: RegexResult):
    prefix = prefix.result.asDisplay().strip()
    content = [content.result.asDisplay()]
    result = None
    if prefix == "nokia":
        result = await Memes.make_nokia(content)
    elif prefix == "鲁迅说":
        result = await Memes.make_luxunsay(content)
    elif prefix == "喜报":
        result = await Memes.make_goodnews(content)
    elif prefix == "记仇":
        result = await Memes.make_jichou(content)
    elif prefix in ("狂爱", "狂粉"):
        result = await Memes.make_fanatic(content)
    elif prefix == "低语":
        result = await Memes.make_diyu(content)
    elif prefix == "别说了":
        result = await Memes.make_shutup(content)
    elif prefix == "一巴掌":
        result = await Memes.make_slap(content)
    elif prefix == "滚屏":
        result = await Memes.make_scroll(content)
    else:
        content = shlex.split(content[0])
        for key in gif_subtitle_memes.keys():
            if prefix in gif_subtitle_memes[key]["aliases"]:
                if len(content) != len(gif_subtitle_memes[key]["pieces"]):
                    await app.sendGroupMessage(
                        group,
                        MessageChain(
                            f"参数数量不符,需要输入{len(gif_subtitle_memes[key]['pieces'])}段文字,若包含空格请加引号"
                        ),
                        quote=message.getFirst(Source))
                    return
                else:
                    result = await Memes.gif_func(gif_subtitle_memes[key],
                                                  content)
    if result:
        await app.sendGroupMessage(
            group,
            MessageChain([
                Image(data_bytes=result.getvalue()) if isinstance(
                    result, BytesIO) else Plain(text=result)
            ]),
            quote=message.getFirst(Source))
Exemple #10
0
 async def image_waiter(
     waiter_group: Group, waiter_member: Member, waiter_message: MessageChain
 ):
     if waiter_group.id == group.id and waiter_member.id == member.id:
         if waiter_message.has(Image):
             return waiter_message.getFirst(Image).url
         else:
             return False
async def github_info(app: Ariadne, message: MessageChain, group: Group, image: ArgResult, keyword: RegexResult):
    image = image.matched
    keyword = keyword.result.asDisplay()
    url = "https://api.github.com/search/repositories?q="
    img_url = "https://opengraph.githubassets.com/c9f4179f4d560950b2355c82aa2b7750bffd945744f9b8ea3f93cc24779745a0/"
    async with get_running(Adapter).session.get(url=url + keyword) as resp:
        result = (await resp.json())["items"]
    if not result:
        await app.sendGroupMessage(group, MessageChain("没有搜索到结果呢~"), quote=message.getFirst(Source))
    elif image:
        img_url += result[0]["full_name"]
        async with get_running(Adapter).session.get(img_url) as resp:
            content = await resp.read()
        await app.sendGroupMessage(group, MessageChain([Image(data_bytes=content)]), quote=message.getFirst(Source))
    else:
        result = result[0]
        name = result["name"]
        owner = result["owner"]["login"]
        description = result["description"]
        repo_url = result["html_url"]
        stars = result["stargazers_count"]
        watchers = result["watchers"]
        language = result["language"]
        forks = result["forks"]
        issues = result["open_issues"]
        repo_license = result["license"]["key"] if result["license"] else "无"
        msg = MessageChain([
            Plain(text=f"名称:{name}\n"),
            Plain(text=f"作者:{owner}\n"),
            Plain(text=f"描述:{description}\n"),
            Plain(text=f"链接:{repo_url}\n"),
            Plain(text=f"stars:{stars}\n"),
            Plain(text=f"watchers:{watchers}\n"),
            Plain(text=f"forks:{forks}\n"),
            Plain(text=f"issues:{issues}\n"),
            Plain(text=f"language:{language}\n"),
            Plain(text=f"license:{repo_license}")
        ])
        try:
            await app.sendGroupMessage(group, msg, quote=message.getFirst(Source))
        except MessageTooLong:
            await app.sendGroupMessage(
                group,
                MessageChain([Image(data_bytes=TextEngine([GraiaAdapter(msg)]).draw())]),
                quote=message.getFirst(Source)
            )
async def wolfram_alpha(app: Ariadne, message: MessageChain, group: Group,
                        content: RegexResult):
    question = content.result.asDisplay()
    if not api_key or api_key == "wolfram_alpha_key":
        return MessageItem(
            MessageChain.create([Plain(text="尚未配置wolfram_alpha_key!")]),
            QuoteSource())
    url = f"https://api.wolframalpha.com/v1/simple?i={question.replace('+', '%2B')}&appid={api_key}"
    async with get_running(Adapter).session.get(url=url) as resp:
        if resp.status == 200:
            res = await resp.read()
            await app.sendGroupMessage(group,
                                       MessageChain([Image(data_bytes=res)]),
                                       quote=message.getFirst(Source))
        else:
            await app.sendGroupMessage(group,
                                       MessageChain(await resp.text()),
                                       quote=message.getFirst(Source))
async def message_merger(app: Ariadne, message: MessageChain, group: Group,
                         msg_to_merge: RegexResult):
    await app.sendGroupMessage(
        group,
        MessageChain([
            Image(data_bytes=TextEngine([GraiaAdapter(msg_to_merge.result)],
                                        min_width=1080).draw())
        ]),
        quote=message.getFirst(Source))
Exemple #14
0
async def cp_generator(app: Ariadne, message: MessageChain, group: Group,
                       attack: RegexResult, defence: RegexResult):
    attack = attack.result.asDisplay()
    defence = defence.result.asDisplay()
    template = random.choice(cp_data["data"])
    content = template.replace("<攻>", attack).replace("<受>", defence)
    await app.sendGroupMessage(group,
                               MessageChain(content),
                               quote=message.getFirst(Source))
Exemple #15
0
async def random_wife(app: Ariadne, message: MessageChain, group: Group):
    await app.sendGroupMessage(
        group,
        MessageChain([
            Image(
                url=
                f"https://www.thiswaifudoesnotexist.net/example-{random.randint(1, 100000)}.jpg"
            )
        ]),
        quote=message.getFirst(Source))
Exemple #16
0
async def up_pool_(app: Ariadne, group: Group, member: Member,
                   message: MessageChain):
    if not await user_permission_require(group, member, 3):
        await app.sendMessage(group,
                              MessageChain('只有群管理才能更新卡池'),
                              quote=message.getFirst(Source))
        return
    await app.sendMessage(group, MessageChain('正在更新卡池'))
    _ = await init_pool_list()
    await app.sendMessage(group, MessageChain('更新卡池完成'))
Exemple #17
0
async def qrcode_generator(app: Ariadne, message: MessageChain, group: Group,
                           content: RegexResult):
    content = content.result.asDisplay()
    qrcode_img = qrcode.make(content)
    bytes_io = BytesIO()
    qrcode_img.save(bytes_io)
    await app.sendGroupMessage(group,
                               MessageChain(
                                   [Image(data_bytes=bytes_io.getvalue())]),
                               quote=message.getFirst(Source))
Exemple #18
0
async def pdf_searcher(app: Ariadne, message: MessageChain, group: Group,
                       keyword: RegexResult):
    base_url = "https://zh.sg1lib.org"
    keyword = keyword.result.asDisplay().strip()
    url = f"{base_url}/s/?q={keyword}"
    async with aiohttp.ClientSession(connector=TCPConnector(
            verify_ssl=False)) as session:
        async with session.get(url=url, proxy=proxy) as resp:
            html = await resp.read()
    soup = BeautifulSoup(html, "html.parser")
    try:
        divs = soup.find("div", {
            "id": "searchResultBox"
        }).find_all("div", {"class": "resItemBox resItemBoxBooks exactMatch"})
    except AttributeError:
        await app.sendGroupMessage(
            group,
            MessageChain(
                f"请检查{base_url}是否可以正常访问!若不可以请检查代理是否正常,若代理正常可能为域名更换,请向仓库提出PR"))
        return
    count = 0
    books = []
    text = "搜索到以下结果:\n\n"
    for div in divs:
        count += 1
        if count > 5:
            break
        name = div.find("h3").get_text().strip()
        href = div.find("h3").find("a", href=True)["href"]
        # cover = div.find("table").find("img")["src"]
        first_div = div.find("table").find("table").find("div")
        publisher = first_div.get_text().strip() if re.search(
            '.*?title="Publisher".*?', str(first_div)) else None
        authors = div.find("div", {"class": "authors"}).get_text().strip()

        text += f"{count}.\n"
        text += f"名字:{name}\n"
        text += f"作者:{authors}\n" if authors else ""
        text += f"出版社:{publisher}\n" if publisher else ""
        text += f"页面链接:{base_url + href}\n\n"

        books.append({
            "name": name,
            # "cover": cover,
            "href": base_url + href,
            "publisher": publisher,
            "authors": authors
        })

    if not books:
        text = "未搜索到结果呢 >A<\n要不要换个关键词试试呢~"
    await app.sendGroupMessage(group,
                               MessageChain(text),
                               quote=message.getFirst(Source))
Exemple #19
0
async def genshin_material_remind(
    app: Ariadne,
    message: MessageChain,
    group: Group,
):
    if time.strftime("%w") == "0":
        await app.sendGroupMessage(group,
                                   MessageChain("今天是周日,所有材料副本都开放了。"),
                                   quote=message.getFirst(Source))
        return
    file_name = str((datetime.now() - timedelta(hours=4)).date())
    if not (Path(IMAGE_PATH) / f"{file_name}.png").exists():
        await app.sendMessage(group, MessageChain("正在自动更新中..."))
        _ = await update_image()
        print(_)
    await app.sendGroupMessage(group,
                               MessageChain([
                                   Image(path=Path(IMAGE_PATH) /
                                         f"{file_name}.png"),
                                   Plain(text="\n※ 每日素材数据来源于 genshin.pub")
                               ]),
                               quote=message.getFirst(Source))
Exemple #20
0
async def i_have_a_friend(app: Ariadne, message: MessageChain, group: Group,
                          member: Member, content: RegexResult,
                          target: ElementResult, dark: RegexResult):
    if content.matched and content.result.asDisplay().strip():
        content = content.result.asDisplay()
        if target.matched:
            target = target.result.target
            member = await app.getMember(group, target)
            if not member:
                await app.sendGroupMessage(group,
                                           MessageChain("获取成员信息失败!"),
                                           quote=message.getFirst(Source))
                return
        else:
            target = member
        if avatar := await get_avatar(target, 160):
            avatar = BuildImage(200, 100, background=BytesIO(avatar))
        else:
            avatar = BuildImage(200, 100, color=(0, 0, 0))
        avatar.circle_new()
        text = BuildImage(300,
                          30,
                          font_size=30,
                          color="white" if not dark.matched else "black")
        text.text((0, 0), member.name, (0, 0, 0) if not dark.matched else
                  (141, 141, 146))
        A = BuildImage(700,
                       150,
                       font_size=25,
                       color="white" if not dark.matched else "black")
        A.paste(avatar, (30, 25), True)
        A.paste(text, (150, 38))
        A.text((150, 85), content.strip(),
               (125, 125, 125) if not dark.matched else (255, 255, 255))
        await app.sendGroupMessage(group,
                                   MessageChain(
                                       [Image(data_bytes=A.pic2bytes())]),
                                   quote=message.getFirst(Source))
Exemple #21
0
async def dice(app: Ariadne, message: MessageChain, group: Group):
    if not await group_setting.get_setting(group.id, Setting.dice):
        await app.sendGroupMessage(group,
                                   MessageChain("骰子功能尚未开启哟~"),
                                   quote=message.getFirst(Source))
        return
    times, max_point = message.asDisplay().strip().split('d')
    times, max_point = int(times), int(max_point)
    if times > 100:
        await app.sendGroupMessage(group,
                                   MessageChain("nmd,太多次了!"),
                                   quote=message.getFirst(Source))
    elif max_point > 1000:
        await app.sendGroupMessage(group,
                                   MessageChain("你滴太大,我忍不住!"),
                                   quote=message.getFirst(Source))
    else:
        await app.sendGroupMessage(
            group,
            MessageChain(
                f"{random.choice([num for num in range(1, max_point + 1)])}/{max_point} "
                for _ in range(times)),
            quote=message.getFirst(Source))
async def network_compiler(app: Ariadne, message: MessageChain, group: Group,
                           language: RegexResult, code: RegexResult):
    if not await group_setting.get_setting(group.id, Setting.compile):
        await app.sendGroupMessage(group,
                                   MessageChain("网络编译器功能关闭了呐~去联系管理员开启吧~"))
        return
    language = language.result.asDisplay()
    code = code.result.asDisplay()
    result = await get_result(language, code)
    if isinstance(result, str):
        await app.sendGroupMessage(group,
                                   MessageChain(result),
                                   quote=message.getFirst(Source))
    else:
        try:
            await app.sendGroupMessage(
                group,
                MessageChain(result["output"]
                             if result["output"] else result["errors"]),
                quote=message.getFirst(Source))
        except MessageTooLong:
            await app.sendGroupMessage(group,
                                       MessageChain("MessageTooLong"),
                                       quote=message.getFirst(Source))
Exemple #23
0
async def abstract_message_transformer(app: Ariadne, message: MessageChain, group: Group, content: RegexResult):
    result = ""
    content = content.result.asDisplay()
    length = len(content)
    index = 0
    while index < length:
        if index < length - 1 and (get_pinyin(content[index]) + get_pinyin(content[index + 1])) in emoji:
            result += emoji[get_pinyin(content[index]) + get_pinyin(content[index + 1])]
            index += 1
        elif get_pinyin(content[index]) in emoji:
            result += emoji[get_pinyin(content[index])]
        else:
            result += content[index]
        index += 1
    await app.sendGroupMessage(group, MessageChain(result), quote=message.getFirst(Source))
async def marketing_content_generator(app: Ariadne, message: MessageChain,
                                      group: Group, somebody: RegexResult,
                                      something: RegexResult,
                                      other_word: RegexResult):
    somebody = somebody.result.asDisplay()
    something = something.result.asDisplay()
    other_word = other_word.result.asDisplay()
    content = f"{somebody}{something}是怎么回事呢?" \
              f"{somebody}相信大家都很熟悉,但是{somebody}{something}是怎么回事呢,下面就让小编带大家一起了解下吧。\n" \
              f"{somebody}{something},其实就是{somebody}{other_word},大家可能会很惊讶{somebody}怎么会{something}呢?" \
              f"但事实就是这样,小编也感到非常惊讶。\n" \
              f"这就是关于{somebody}{something}的事情了,大家有什么想法呢,欢迎在评论区告诉小编一起讨论哦! "
    await app.sendGroupMessage(group,
                               MessageChain(content),
                               quote=message.getFirst(Source))
Exemple #25
0
async def speak(app: Ariadne, message: MessageChain, group: Group,
                voice_type: ArgResult, content: RegexResult):
    text = content.result.asDisplay()
    voice_type = voice_type.result if voice_type.matched else await group_setting.get_setting(
        group.id, Setting.voice)
    if voice_type == "off":
        return None
    if voice := await Speak.aget_voice(text, voice_type):
        if isinstance(voice, str):
            await app.sendGroupMessage(group,
                                       MessageChain(voice),
                                       quote=message.getFirst(Source))
        elif isinstance(voice, bytes):
            await app.sendGroupMessage(
                group,
                MessageChain(
                    [Voice(data_bytes=await silkcoder.async_encode(voice))]))
async def phantom_tank(app: Ariadne, message: MessageChain, group: Group,
                       colorful: RegexResult, img1: ElementResult,
                       img2: ElementResult):
    async with get_running(Adapter).session.get(url=img1.result.url) as resp:
        display_img = PIL.Image.open(BytesIO(await resp.read()))
    async with get_running(Adapter).session.get(url=img2.result.url) as resp:
        hide_img = PIL.Image.open(BytesIO(await resp.read()))
    if colorful.matched:
        msg = MessageChain([
            Image(data_bytes=await PhantomTank.colorful_tank(
                display_img, hide_img))
        ])
    else:
        msg = MessageChain([
            Image(
                data_bytes=await PhantomTank.make_tank(display_img, hide_img))
        ])
    await app.sendGroupMessage(group, msg, quote=message.getFirst(Source))
Exemple #27
0
async def random_tea(app: Ariadne, message: MessageChain, group: Group,
                     option: MatchResult):
    option = option.result.asDisplay()
    if randrange(101) < 5:
        return "没得喝!"
    body = random.choice(food[option]["body"])
    addon = ""
    cream = ""
    temperature = random.choice(food[option]["temperature"])
    sugar = random.choice(food[option]["sugar"])
    divider = "加"
    for i in range(0, randrange(1, 4)):
        addon = divider + str(random.choice(food[option]["addon"]))
    if randrange(2):
        cream = divider + str(random.choice(food[option]["cream"]))
    result = f"你的随机{option}是:\n" + temperature + sugar + addon + cream + body
    await app.sendGroupMessage(group,
                               MessageChain(result),
                               quote=message.getFirst(Source))
async def bot_manager_handler(app: Ariadne, message: MessageChain,
                              group: Group, member: Member):
    message_text = message.asDisplay()
    if message_text.startswith("setting -set "):
        msg = await execute_setting_update(group, member, message_text)
    elif re.match(r"user -grant @[1-9][0-9]{4,14} .*", message_text):
        msg = await execute_grant_permission(group, member, message_text)
    elif re.match(r"blacklist -add @[1-9][0-9]{4,14}", message_text):
        msg = await execute_blacklist_append(int(message_text[16:]), group,
                                             member)
    elif re.match(r"blacklist -add -all @[1-9][0-9]{4,14}", message_text):
        msg = await execute_blacklist_append(int(message_text[16:]), group,
                                             member)
    elif re.match(r"blacklist -remove @[1-9][0-9]{4,14}", message_text):
        msg = await execute_blacklist_remove(int(message_text[19:]), group,
                                             member)
    else:
        return None
    await app.sendGroupMessage(group, msg, quote=message.getFirst(Source))
async def abbreviated_prediction(app: Ariadne, group: Group, message: MessageChain, content: RegexResult):
    url = "https://lab.magiconch.com/api/nbnhhsh/guess"
    headers = {"referer": "https://lab.magiconch.com/nbnhhsh/"}
    data = {"text": content.result.asDisplay()}

    async with get_running(Adapter).session.post(url=url, headers=headers, data=data) as resp:
        res = await resp.json()

    result = "可能的结果:\n\n"
    has_result = False
    for i in res:
        if "trans" in i and i["trans"]:
            has_result = True
            result += f"{i['name']} => {','.join(i['trans'])}\n\n"
        elif "trans" in i or not i["inputting"]:
            result += f"{i['name']} => 没找到结果!\n\n"
        else:
            has_result = True
            result += f"{i['name']} => {','.join(i['inputting'])}\n\n"
    result = result if has_result else "没有找到结果哦~"
    await app.sendGroupMessage(group, MessageChain(result), quote=message.getFirst(Source))
Exemple #30
0
async def random_meal(app: Ariadne, message: MessageChain, group: Group,
                      option: MatchResult):
    option = option.result.asDisplay()
    main_amount = 1 if option == "早餐" else 2
    dish = []
    if randrange(101) < 5:
        return "没得吃!"
    if randrange(2) if option != "午餐" else 1:
        dish.append(random.choice(food[option]["drink"]))
    if randrange(2) if option != "午餐" else 1:
        dish.append(random.choice(food[option]["pre"]))
    if not dish:
        if randrange(2):
            dish.append(random.choice(food[option]["drink"]))
        else:
            dish.append(random.choice(food[option]["pre"]))
    for i in range(0, main_amount):
        dish.append(random.choice(food[option]["main"]))
    result = f"你的随机{option}是:\n" + " ".join(dish)
    await app.sendGroupMessage(group,
                               MessageChain(result),
                               quote=message.getFirst(Source))