1
0
Fork 0
forked from waifu/kemoverse

weight add_character change

This commit is contained in:
w 2025-06-03 23:08:15 -03:00
parent 9f9c034461
commit cbdbefb5fc

View file

@ -3,12 +3,12 @@ from misskey.exceptions import MisskeyAPIException
from client import client_connection
from db_utils import insert_character
from custom_types import Character
from config import RARITY_TO_WEIGHT
def add_character(
name: str,
rarity: int,
weight: float,
image_url: str) -> tuple[int, str]:
'''
Adds a character to the database, uploading the image from a public URL to
@ -17,7 +17,6 @@ def add_character(
Args:
name (str): Character name.
rarity (int): Character rarity (e.g., 1-5).
weight (float): Pull weight (e.g., 0.02).
image_url (str): Public URL of the image from the post (e.g., from
note['files'][i]['url']).
@ -36,8 +35,8 @@ def add_character(
raise ValueError('Character name cannot be empty.')
if rarity < 1:
raise ValueError('Rarity must be a positive integer.')
if weight <= 0:
raise ValueError('Weight must be a positive number.')
if rarity not in RARITY_TO_WEIGHT.keys():
raise ValueError(f'Invalid rarity: {rarity}')
if not image_url:
raise ValueError('Image URL must be provided.')
@ -59,7 +58,7 @@ def add_character(
character_id = insert_character(
stripped_name,
rarity,
float(weight),
RARITY_TO_WEIGHT[rarity],
file_id
)
return character_id, file_id