Пример #1
0
async def phantom_tank(app: GraiaMiraiApplication, message: MessageChain, group: Group):

    message_text = "".join([plain.text for plain in message.get(Plain)]).strip()
    if message_text in ["幻影", "彩色幻影"]:
        if len(message[Image]) != 2:
            try:
                await app.sendGroupMessage(group, MessageChain.create([Plain(text="非预期图片数量!请按 `显示图 隐藏图` 顺序发送,共两张")]))
            except AccountMuted:
                pass
            return None
        if globals()["signal"] >= 2:
            try:
                await app.sendGroupMessage(group, MessageChain.create([Plain(text=f"目前有{signal}个任务正在处理,请稍后再试!")]))
            except AccountMuted:
                pass
            return None

        globals()["signal"] += 1

        try:
            await app.sendGroupMessage(group, MessageChain.create([Plain(text="converting")]))
        except AccountMuted:
            pass

        im_1 = message[Image][0]
        async with aiohttp.ClientSession() as session:
            async with session.get(url=im_1.url) as resp:
                img_content = await resp.read()
        display_img = IMG.open(BytesIO(img_content))

        im_2 = message[Image][1]
        async with aiohttp.ClientSession() as session:
            async with session.get(url=im_2.url) as resp:
                img_content = await resp.read()
        hide_img = IMG.open(BytesIO(img_content))

        try:
            await app.sendGroupMessage(
                group,
                MessageChain.create([
                    Image.fromUnsafeBytes(await make_tank(display_img, hide_img) if message_text == "幻影" else await colorful_tank(display_img, hide_img))
                    # Image.fromUnsafeBytes(await colorful_tank(display_img, hide_img))
                ])
            )
        except AccountMuted:
            pass

        globals()["signal"] -= 1
async def friend_message_process(app: GraiaMiraiApplication, friend: Friend,
                                 message: MessageChain) -> None:
    message_test = message.asDisplay()
    if friend.id == await get_config("HostQQ"):
        if message_test[:5] == "发布消息:":
            msg = MessageChain.create([Plain(text=message_test[5:])])
            group_list = await app.groupList()
            for i in group_list:
                try:
                    await app.sendGroupMessage(i, msg)
                except AccountMuted:
                    pass
        elif message.has(Image):
            imgs = message.get(Image)
            for i in imgs:
                bot_setu_count = await get_total_calls("botSetuCount") + 1
                await update_total_calls(bot_setu_count, "botSetuCount")
                path = "%s%s.png" % (await get_config("listenImagePath"),
                                     bot_setu_count)

                async with aiohttp.ClientSession() as session:
                    async with session.get(url=i.url) as resp:
                        img_content = await resp.read()

                image = IMG.open(BytesIO(img_content))
                image.save(path)

                await insert_image_hash(
                    "%s%d.png" %
                    (await get_config("listenImagePath"), bot_setu_count),
                    await image_hash(path), "tribute")
            await app.sendFriendMessage(
                friend,
                MessageChain.create(
                    [Plain(text="%d Image saved!" % len(imgs))]))
            await write_log("save img from Host", path, await
                            get_config("HostQQ"), 0, True, "img")
Пример #3
0
async def head_splicer(app: GraiaMiraiApplication, message: MessageChain, member: Member, group: Group):
    print(globals()["signal"])
    if not os.path.exists("./modules/HeadSplicer/temp/"):
        os.mkdir("./modules/HeadSplicer/temp/")
    if "".join([plain.text for plain in message.get(Plain)]).strip() == "接头":
        if globals()["signal"] >= 2:
            try:
                await app.sendGroupMessage(group, MessageChain.create([Plain(text=f"目前有{signal}个任务正在处理,请稍后再试!")]))
            except AccountMuted:
                pass
            return None

        globals()["signal"] += 1

        if message.get(Image):
            image = message[Image][0]
            img_url = image.url
            async with aiohttp.ClientSession() as session:
                async with session.get(url=img_url) as resp:
                    img_content = await resp.read()
            image = IMG.open(BytesIO(img_content))
            image.save(f"./modules/HeadSplicer/temp/temp-{group.id}-{member.id}.png")
            try:
                try:
                    splicing_result = await process(
                        f"./modules/HeadSplicer/temp/temp-{group.id}-{member.id}.png",
                        f"./modules/HeadSplicer/temp/tempResult-{group.id}-{member.id}.png"
                    )
                except TooManyFacesDetected:
                    globals()["signal"] -= 1
                    await app.sendGroupMessage(
                        group,
                        MessageChain.create([Plain(text="脸太tm多了!说!你是不是故意欺负我!爪巴啊啊啊啊啊啊!")])
                    )
                    return None
                except Exception:
                    globals()["signal"] -= 1
                    await app.sendGroupMessage(
                        group,
                        MessageChain.create([Image.fromLocalFile("./modules/HeadSplicer/statics/接头失败.png")])
                    )
                    return None
                if splicing_result:
                    globals()["signal"] -= 1
                    await app.sendGroupMessage(
                        group,
                        MessageChain.create([
                            Image.fromLocalFile(f"./modules/HeadSplicer/temp/tempResult-{group.id}-{member.id}.png")
                        ])
                    )
                else:
                    globals()["signal"] -= 1
                    await app.sendGroupMessage(
                        group,
                        MessageChain.create([Image.fromLocalFile("./modules/HeadSplicer/statics/没找到头.png")])
                    )
            except AccountMuted:
                return None
        else:
            globals()["signal"] -= 1
            try:
                await app.sendGroupMessage(group, MessageChain.create([Plain(text="请附带图片!")]))
            except AccountMuted:
                pass