diff options
| author | 2023-04-19 17:08:33 +0800 | |
|---|---|---|
| committer | 2023-04-19 17:08:33 +0800 | |
| commit | f80e9f05b43a4883e58eaf82f2200d31ac87b23e (patch) | |
| tree | bb0fdd35c219bf67e8ece4010e23e39884262200 /ChienDice/plugins/iamai_plugin_dice/__init__.py | |
| parent | bfac2edccf0f83caab5321587de3d7876fd52871 (diff) | |
| download | HydroRoll-f80e9f05b43a4883e58eaf82f2200d31ac87b23e.tar.gz HydroRoll-f80e9f05b43a4883e58eaf82f2200d31ac87b23e.zip | |
rename to `HydroRoll`
Diffstat (limited to 'ChienDice/plugins/iamai_plugin_dice/__init__.py')
| -rw-r--r-- | ChienDice/plugins/iamai_plugin_dice/__init__.py | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/ChienDice/plugins/iamai_plugin_dice/__init__.py b/ChienDice/plugins/iamai_plugin_dice/__init__.py deleted file mode 100644 index 6005406..0000000 --- a/ChienDice/plugins/iamai_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)) |
