Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/dice/__init__.py

32 lines
1.5 KiB
Python
Raw Normal View History

2023-01-19 12:02:49 +00:00
from core.builtins.message import MessageSession
2023-02-26 04:03:25 +00:00
from core.component import on_command, on_regex
from .dice import GenerateMessage
2023-01-19 12:02:49 +00:00
2023-02-22 10:42:09 +00:00
dice = on_command('dice', alias={'d4': 'dice d4', 'd6': 'dice d6',
2023-02-28 10:38:21 +00:00
'd8': 'dice d8', 'd10': 'dice d10', 'd12': 'dice d12', 'd20': 'dice d20', 'd100': 'dice d100'}, developers=['Light-Beacon'], desc='随机骰子', recommend_modules=['dice_regex'])
2023-01-19 12:02:49 +00:00
2023-01-19 14:22:14 +00:00
2023-02-28 10:28:57 +00:00
@dice.handle('<dices> [<dc>] {投掷指定骰子,可指定投骰次数与 dc 判断判定。}',)
2023-01-19 12:02:49 +00:00
async def _(msg: MessageSession):
2023-01-26 07:16:11 +00:00
dice = msg.parsed_msg['<dices>']
dc = msg.parsed_msg.get('<dc>', '0')
2023-02-28 10:47:28 +00:00
times = '1'
2023-02-28 10:28:57 +00:00
if '#' in dice:
times = dice.partition('#')[0]
dice = dice.partition('#')[2]
2023-02-28 10:47:28 +00:00
if not times.isdigit():
await msg.finish('发生错误:无效的投骰次数:' + times)
if not dc.isdigit():
2023-02-22 15:52:54 +00:00
await msg.finish('发生错误:无效的 dc' + dc)
2023-02-26 04:03:25 +00:00
await msg.finish(await GenerateMessage(dice, int(times), int(dc)))
dicergex = on_regex('dice_regex',
desc='打开后将在发送的聊天内容匹配以下信息时执行对应命令:\n'
'[扔投骰丢](N)个(n面)骰(子)', developers=['Light-Beacon'])
2023-02-28 04:39:27 +00:00
@dicergex.handle(r"[扔|投|掷|丢]([0-9]*)?个([0-9]*面)?骰子?")
2023-02-26 04:03:25 +00:00
async def _(message: MessageSession):
groups = message.matched_msg.groups()
diceType = groups[1][:-1] if groups[1] else '6'
2023-02-28 04:39:27 +00:00
await message.finish(await GenerateMessage(f'{groups[0]}D{diceType}',1,0))