from io import BytesIO

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

from konabot.plugins.memepack.drawing.saying import draw_geimao, draw_mnk, draw_pt, draw_suan

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())


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

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

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


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

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

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


dsuan = on_alconna(Alconna(
    "大蒜说",
    Args["saying", MultiVar(str, '+'), Field(
        missing_tips=lambda: "你没有写大蒜说了什么"
    )]
), use_cmd_start=True, use_cmd_sep=False, skip_for_unmatch=False, aliases=set())

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

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