diff options
| author | 2023-04-19 01:23:44 +0800 | |
|---|---|---|
| committer | 2023-04-19 01:23:44 +0800 | |
| commit | 23b32b900423ae8fe36a50224f0308cb3d97d4d0 (patch) | |
| tree | b5a59158f31d7aed0e3d65b0cb1563e7e5ff7edc /plugins/alicebot_plugin_dice | |
| parent | a69a07edfedf5e15d8013fb639ed6574e0078988 (diff) | |
| download | HydroRoll-23b32b900423ae8fe36a50224f0308cb3d97d4d0.tar.gz HydroRoll-23b32b900423ae8fe36a50224f0308cb3d97d4d0.zip | |
🏷bump
Diffstat (limited to 'plugins/alicebot_plugin_dice')
| -rw-r--r-- | plugins/alicebot_plugin_dice/__init__.py | 50 | ||||
| -rw-r--r-- | plugins/alicebot_plugin_dice/config.py | 13 |
2 files changed, 0 insertions, 63 deletions
diff --git a/plugins/alicebot_plugin_dice/__init__.py b/plugins/alicebot_plugin_dice/__init__.py deleted file mode 100644 index ef2ca79..0000000 --- a/plugins/alicebot_plugin_dice/__init__.py +++ /dev/null @@ -1,50 +0,0 @@ -import re -import random - -from iamai.log import logger - -from plugins.iamai_plugin_base import CommandPluginBase - -from .config import Config - - -class Dice(CommandPluginBase[None, Config]): - Config = Config - - def __post_init__(self): - self.re_pattern = re.compile( - r"\s*(?P<dice_times>\d+)d(?P<dice_faces>\d+)([*x](?P<dice_multiply>\d+))?", - flags=re.I, - ) - - async def handle(self) -> None: - dice_times = int(self.msg_match.group("dice_times")) - dice_faces = int(self.msg_match.group("dice_faces")) - if self.msg_match.group("dice_multiply") is None: - dice_multiply = None - else: - dice_multiply = int(self.msg_match.group("dice_multiply")) - - if dice_times > self.config.max_dice_times: - await self.event.reply( - self.format_str(self.config.exceed_max_dice_times_str) - ) - return - - dice = [random.randint(1, dice_faces) for _ in range(dice_times)] - dice_sum = sum(dice) - if dice_multiply is None: - result_str = f"{dice_times}D{dice_faces}=" - if dice_times != 1: - result_str += f"{'+'.join(map(lambda x: str(x), dice))}=" - result_str += str(dice_sum) - else: - result_str = f"{dice_times}D{dice_faces}X{dice_multiply}=" - if dice_times != 1: - result_str += ( - f"({'+'.join(map(lambda x: str(x), dice))})X{dice_multiply}=" - ) - result_str += f"{dice_sum}X{dice_multiply}={dice_sum * dice_multiply}" - - logger.info(f"Dice Plugin: {result_str}") - await self.event.reply(self.format_str(self.config.message_str, result_str)) diff --git a/plugins/alicebot_plugin_dice/config.py b/plugins/alicebot_plugin_dice/config.py deleted file mode 100644 index a8c6700..0000000 --- a/plugins/alicebot_plugin_dice/config.py +++ /dev/null @@ -1,13 +0,0 @@ -from typing import Set - -from plugins.iamai_plugin_base import CommandPluginConfig - - -class Config(CommandPluginConfig): - __config_name__ = "plugin_dice" - command: Set[str] = {"r", "roll", "dice"} - """命令文本。""" - max_dice_times: int = 1000 - """最大单次投掷次数。""" - exceed_max_dice_times_str: str = "错误:超过最大投掷次数。" - """超过最大单次投掷次数时的提示语。""" |
