from nonebot.adapters import Event as BaseEvent
from nonebot.adapters.console.event import MessageEvent as ConsoleMessageEvent
from nonebot.adapters.discord.event import MessageEvent as DiscordMessageEvent
from nonebot_plugin_alconna import Alconna, UniMessage, on_alconna

from konabot.plugins.roll_dice.roll_dice import roll_dice

evt = on_alconna(Alconna(
    "摇骰子"
), use_cmd_start=True, use_cmd_sep=False, skip_for_unmatch=True)

@evt.handle()
async def _(event: BaseEvent):
    if isinstance(event, DiscordMessageEvent):
        await evt.send(await UniMessage().text("```\n" + roll_dice() + "\n```").export())
    elif isinstance(event, ConsoleMessageEvent):
        await evt.send(await UniMessage().text(roll_dice()).export())
    else:
        await evt.send(await UniMessage().text(roll_dice(wide=True)).export())
