跨平台适配

This commit is contained in:
2025-09-29 00:41:29 +08:00
parent adebd51605
commit c8dae680a3
4 changed files with 31 additions and 11 deletions

View File

@ -1,2 +1,4 @@
DRIVER=~fastapi+~httpx+~websockets DRIVER=~fastapi+~httpx+~websockets
COMMAND_START=["!", "", "", "/"] COMMAND_START=["!", "", "", "/"]
ALCONNA_USE_ORIGIN=true

View File

@ -1,2 +1,4 @@
DRIVER=~fastapi+~httpx+~websockets DRIVER=~fastapi+~httpx+~websockets
COMMAND_START=["!", "", "", "/"] COMMAND_START=["!", "", "", "/"]
ALCONNA_USE_ORIGIN=true

View File

@ -1,3 +1,6 @@
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 nonebot_plugin_alconna import Alconna, UniMessage, on_alconna
from konabot.plugins.roll_dice.roll_dice import roll_dice from konabot.plugins.roll_dice.roll_dice import roll_dice
@ -7,5 +10,10 @@ evt = on_alconna(Alconna(
), use_cmd_start=True, use_cmd_sep=False, skip_for_unmatch=True) ), use_cmd_start=True, use_cmd_sep=False, skip_for_unmatch=True)
@evt.handle() @evt.handle()
async def _(): async def _(event: BaseEvent):
await evt.send(await UniMessage().text(await roll_dice()).export()) 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())

View File

@ -7,14 +7,14 @@ number_arts = {
''', ''',
2: ''' ____ 2: ''' ____
|___ \ |___ \\
__) | __) |
/ __/ / __/
|_____| |_____|
''', ''',
3: ''' _____ 3: ''' _____
|___ / |___ /
|_ \ |_ \\
___) | ___) |
|____/ |____/
''', ''',
@ -26,15 +26,15 @@ number_arts = {
''', ''',
5: ''' ____ 5: ''' ____
| ___| | ___|
|___ \ |___ \\
___) | ___) |
|____/ |____/
''', ''',
6: ''' __ 6: ''' __
/ /_ / /_
| '_ \ | '_ \\
| (_) | | (_) |
\___/ \\___/
''' '''
} }
@ -42,5 +42,13 @@ def get_random_number(min: int = 1, max: int = 6) -> int:
import random import random
return random.randint(min, max) return random.randint(min, max)
async def roll_dice() -> str: def roll_dice(wide: bool = False) -> str:
return number_arts[get_random_number()] raw = number_arts[get_random_number()]
if wide:
raw = (raw
.replace("/", "")
.replace("\\", "")
.replace("_", "_")
.replace("|", "")
.replace(" ", " "))
return raw