Added table and general functions for stats system #21
2 changed files with 11 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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.',
|
||||
|
|
Loading…
Add table
Reference in a new issue