From c5a0f7ad7f78ac1925de0e15a7c4d66242d4466a Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 15 Mar 2020 14:42:42 +0100 Subject: [PATCH] Don't add units with invalid health values --- rpgpack/commands/dndaddunit.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rpgpack/commands/dndaddunit.py b/rpgpack/commands/dndaddunit.py index 56f6d720..b7637968 100644 --- a/rpgpack/commands/dndaddunit.py +++ b/rpgpack/commands/dndaddunit.py @@ -5,6 +5,7 @@ import royalnet.utils as ru from ..types import Faction from ..tables import DndBattleUnit from ..utils import get_active_battle +from ..types import Health class DndaddunitCommand(rc.Command): @@ -37,6 +38,11 @@ class DndaddunitCommand(rc.Command): if len(units_with_same_name) != 0: raise rc.InvalidInputError("A unit with the same name already exists.") + try: + health = Health.from_text(health) + except ValueError: + raise rc.InvalidInputError("Invalid health string.") + dbu = DndBattleUnitT( linked_character_id=None, initiative=initiative, @@ -54,4 +60,4 @@ class DndaddunitCommand(rc.Command): f"joins the battle!") if dbu.health.hidden: - await data.delete_invoking() \ No newline at end of file + await data.delete_invoking()