blob: 10b3317cdaa1bdccb4569c3d9d958ebc7588caa8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
import re
from nonebot.adapters.cqhttp import Bot, MessageEvent
from ATRI.service import Service as sv
from ATRI.rule import (
is_block,
is_in_dormant,
is_in_service
)
from .data_source import roll_dice
__plugin_name__ = "roll"
roll = sv.on_command(
name="roll一下",
cmd="/roll",
rule=is_block() & is_in_dormant()
& is_in_service(__plugin_name__)
)
@roll.handle()
async def _roll(bot: Bot, event: MessageEvent, state: dict) -> None:
args = str(event.message).strip()
if args:
state['resu'] = args
@roll.got("resu", prompt="roll 参数不能为空~!\ndemo:1d10 或 2d10+2d10")
async def _(bot: Bot, event: MessageEvent, state: dict) -> None:
resu = state['resu']
match = re.match(r'^([\dd+\s]+?)$', resu)
if not match:
await roll.finish("请输入正确的参数!!\ndemo:1d10 或 2d10+2d10")
await roll.finish(roll_dice(resu))
|