1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00

Don't add units with invalid health values

This commit is contained in:
Steffo 2020-03-15 14:42:42 +01:00
parent af778309bf
commit c5a0f7ad7f

View file

@ -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()
await data.delete_invoking()