weight add_character change
This commit is contained in:
parent
9f9c034461
commit
cbdbefb5fc
1 changed files with 4 additions and 5 deletions
|
@ -3,12 +3,12 @@ from misskey.exceptions import MisskeyAPIException
|
||||||
from client import client_connection
|
from client import client_connection
|
||||||
from db_utils import insert_character
|
from db_utils import insert_character
|
||||||
from custom_types import Character
|
from custom_types import Character
|
||||||
|
from config import RARITY_TO_WEIGHT
|
||||||
|
|
||||||
|
|
||||||
def add_character(
|
def add_character(
|
||||||
name: str,
|
name: str,
|
||||||
rarity: int,
|
rarity: int,
|
||||||
weight: float,
|
|
||||||
image_url: str) -> tuple[int, str]:
|
image_url: str) -> tuple[int, str]:
|
||||||
'''
|
'''
|
||||||
Adds a character to the database, uploading the image from a public URL to
|
Adds a character to the database, uploading the image from a public URL to
|
||||||
|
@ -17,7 +17,6 @@ def add_character(
|
||||||
Args:
|
Args:
|
||||||
name (str): Character name.
|
name (str): Character name.
|
||||||
rarity (int): Character rarity (e.g., 1-5).
|
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
|
image_url (str): Public URL of the image from the post (e.g., from
|
||||||
note['files'][i]['url']).
|
note['files'][i]['url']).
|
||||||
|
|
||||||
|
@ -36,8 +35,8 @@ def add_character(
|
||||||
raise ValueError('Character name cannot be empty.')
|
raise ValueError('Character name cannot be empty.')
|
||||||
if rarity < 1:
|
if rarity < 1:
|
||||||
raise ValueError('Rarity must be a positive integer.')
|
raise ValueError('Rarity must be a positive integer.')
|
||||||
if weight <= 0:
|
if rarity not in RARITY_TO_WEIGHT.keys():
|
||||||
raise ValueError('Weight must be a positive number.')
|
raise ValueError(f'Invalid rarity: {rarity}')
|
||||||
if not image_url:
|
if not image_url:
|
||||||
raise ValueError('Image URL must be provided.')
|
raise ValueError('Image URL must be provided.')
|
||||||
|
|
||||||
|
@ -59,7 +58,7 @@ def add_character(
|
||||||
character_id = insert_character(
|
character_id = insert_character(
|
||||||
stripped_name,
|
stripped_name,
|
||||||
rarity,
|
rarity,
|
||||||
float(weight),
|
RARITY_TO_WEIGHT[rarity],
|
||||||
file_id
|
file_id
|
||||||
)
|
)
|
||||||
return character_id, file_id
|
return character_id, file_id
|
||||||
|
|
Loading…
Add table
Reference in a new issue