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

44 lines
2.2 KiB
Python
Raw Normal View History

2023-01-19 12:02:49 +00:00
from core.builtins.message import MessageSession
2023-03-04 08:51:56 +00:00
from core.component import module
2023-02-26 04:03:25 +00:00
from .dice import GenerateMessage
2023-01-19 12:02:49 +00:00
2023-04-30 03:30:59 +00:00
dice = module('dice', alias={'d4': 'dice d4',
2023-04-21 10:11:03 +00:00
'd6': 'dice d6',
2023-04-30 03:30:59 +00:00
'd8': 'dice d8',
'd10': 'dice d10',
'd12': 'dice d12',
2023-04-21 10:11:03 +00:00
'd20': 'dice d20',
2023-04-22 04:13:58 +00:00
'd100': 'dice d100'}, developers=['Light-Beacon'], desc='{dice.help.desc}',)
2023-01-19 12:02:49 +00:00
2023-01-19 14:22:14 +00:00
2023-04-22 04:13:58 +00:00
@dice.command('<dices> [<dc>] {{dice.help}}',
2023-03-09 14:18:57 +00:00
options_desc={
'dn': '表示n面骰',
'mdn': '表示m个n面骰输出其所有点数之和m若省略即为1',
'mdnkx': '表示m个n面骰输出其最大的x个骰子点数之和',
'mdnklx': '与上一个相同但其会输出最小的x个骰子点数之和',
'多项式': '式子可以兼容多项如“10d4-2d20”会输出10个4面骰所有点数之和减去2个20面骰点数之和',
'整数项': '一项可以是一个整数也就是调节值如“d20+5”会输出1个20面骰的点数加上5的结果',
'多项式最前面加 N#': '将这个式子的操作重复N次投掷N次之后输出N次的结果',
'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():
2023-04-22 04:13:58 +00:00
await msg.finish(msg.locale.t('dice.message.error.N.invalid') + times)
if not dc.isdigit():
2023-04-22 04:13:58 +00:00
await msg.finish(msg.locale.t('dice.message.error.dc.invalid') + dc)
2023-04-22 04:48:10 +00:00
await msg.finish(await GenerateMessage(dice, int(times), int(dc)))
2023-02-26 04:03:25 +00:00
2023-03-09 14:18:57 +00:00
2023-05-22 04:34:43 +00:00
@dice.regex(r"[扔|投|掷|丢]([0-9]*)?个([0-9]*面)?骰子?", desc="{dice.help.regex.desc}")
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-03-09 14:18:57 +00:00
await message.finish(await GenerateMessage(f'{groups[0]}D{diceType}', 1, 0))