From 91dfe77ffa6935dc3dabac8863a0cf94c755d01d Mon Sep 17 00:00:00 2001 From: w Date: Thu, 26 Jun 2025 00:37:47 -0300 Subject: [PATCH] Enhance add_card function to include power, charm, and wit parameters with validation checks --- bot/add_card.py | 13 ++++++++++--- bot/response.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bot/add_card.py b/bot/add_card.py index def64f6..a914b2e 100644 --- a/bot/add_card.py +++ b/bot/add_card.py @@ -19,7 +19,7 @@ import config from fediverse_factory import get_fediverse_service import db_utils -def add_card(name: str, rarity: int, image_url: str) -> tuple[int, str]: +def add_card(name: str, rarity: int, image_url: str, power: int, charm: int, wit: int) -> tuple[int, str]: """ Adds a card to the database, uploading the image from a public URL to the Fediverse instance. @@ -27,6 +27,9 @@ def add_card(name: str, rarity: int, image_url: str) -> tuple[int, str]: name (str): Card name. rarity (int): Card rarity (e.g., 1-5). image_url (str): Public URL of the image from the post. + power (int): Card power value. + charm (int): Card charm value. + wit (int): Card wit value. Returns: tuple[int, str]: Card ID and file_id. @@ -47,7 +50,8 @@ def add_card(name: str, rarity: int, image_url: str) -> tuple[int, str]: raise ValueError(f'Invalid rarity: {rarity}') if not image_url: raise ValueError('Image URL must be provided.') - + if power < 0 or charm < 0 or wit < 0: + raise ValueError('Power, charm, and wit must be non-negative integers.') try: # Download image response = requests.get(image_url, stream=True, timeout=30) @@ -66,7 +70,10 @@ def add_card(name: str, rarity: int, image_url: str) -> tuple[int, str]: card_id = db_utils.insert_card( stripped_name, rarity, - file_id + file_id, + power, + charm, + wit ) return card_id, file_id diff --git a/bot/response.py b/bot/response.py index 63b5d0c..8ec698e 100644 --- a/bot/response.py +++ b/bot/response.py @@ -140,7 +140,7 @@ be a number between 1 and 5', if len(arguments) == 2: pass else: - if not all(is_float(arg) for arg in arguments[2:]): + if not all(arg.isnumeric() for arg in arguments[2:]): return { 'message': f'{author} Invalid attributes: power, charm and \ wit must be numbers.',