from io import BytesIO

from nonebot_plugin_alconna import (Alconna, Args, Field, MultiVar, UniMessage,
                                    on_alconna)

from konabot.plugins.memepack.drawing.geimao import draw_geimao
from konabot.plugins.memepack.drawing.pt import draw_pt

geimao = on_alconna(Alconna(
    "给猫说",
    Args["saying", MultiVar(str, '+'), Field(
        missing_tips=lambda: "你没有写给猫说了什么"
    )]
), use_cmd_start=True, use_cmd_sep=False, skip_for_unmatch=False, aliases={"给猫哈"})

@geimao.handle()
async def _(saying: list[str]):
    img = await draw_geimao("\n".join(saying))
    img_bytes = BytesIO()
    img.save(img_bytes, format="PNG")

    await geimao.send(await UniMessage().image(raw=img_bytes).export())


pt = on_alconna(Alconna(
    "pt说",
    Args["saying", MultiVar(str, '+'), Field(
        missing_tips=lambda: "你没有写小帕说了什么"
    )]
), use_cmd_start=True, use_cmd_sep=False, skip_for_unmatch=False, aliases={"小帕说"})

@pt.handle()
async def _(saying: list[str]):
    img = await draw_pt("\n".join(saying))
    img_bytes = BytesIO()
    img.save(img_bytes, format="PNG")

    await pt.send(await UniMessage().image(raw=img_bytes).export())
