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

49 lines
2 KiB
Python
Raw Normal View History

from core.builtins import Bot
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-09-03 08:50:12 +00:00
dice = module('dice', alias='rd', 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={
2023-06-07 08:26:44 +00:00
'{dice.help.option.polynomial.title}': '{dice.help.option.polynomial}',
'n': '{dice.help.option.n}',
'm': '{dice.help.option.m}',
'kx': '{dice.help.option.kx}',
'klx': '{dice.help.option.klx}',
'y': '{dice.help.option.y}',
'N': '{dice.help.option.N}',
'dc': '{dice.help.option.dc}'
2023-03-09 14:18:57 +00:00
})
async def _(msg: Bot.MessageSession, dices, dc='0'):
2023-02-28 10:47:28 +00:00
times = '1'
2023-12-11 09:49:25 +00:00
if 'x' in dices:
times = dices.partition('x')[0]
dices = dices.partition('x')[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-06-07 07:56:42 +00:00
await msg.finish(await GenerateMessage(msg, dices, int(times), int(dc)))
2023-02-26 04:03:25 +00:00
2023-03-09 14:18:57 +00:00
2023-07-11 18:15:08 +00:00
@dice.regex(r"[扔投掷擲丢]([0-9]*)?[个個]([0-9]*面)?骰子?([0-9]*次)?", desc="{dice.help.regex.desc}")
async def _(message: Bot.MessageSession):
2023-02-26 04:03:25 +00:00
groups = message.matched_msg.groups()
2023-09-03 11:49:14 +00:00
dice_type = groups[1][:-1] if groups[1] else '6'
roll_time = groups[2][:-1] if groups[2] else '1'
await message.finish(await GenerateMessage(message, f'{groups[0]}D{dice_type}', int(roll_time), 0))
2023-07-15 17:12:31 +00:00
2023-12-06 17:55:11 +00:00
@dice.command('rule {{dice.help.rule}}', required_admin=True)
2023-07-15 17:12:31 +00:00
async def _(msg: Bot.MessageSession):
dc_rule = msg.data.options.get('dice_dc_reversed')
2023-09-03 08:50:12 +00:00
2023-07-15 17:12:31 +00:00
if dc_rule:
msg.data.edit_option('dice_dc_reversed', False)
await msg.finish(msg.locale.t("dice.message.rule.disable"))
else:
msg.data.edit_option('dice_dc_reversed', True)
2023-07-15 17:14:36 +00:00
await msg.finish(msg.locale.t("dice.message.rule.enable"))