1
0
Fork 0
forked from waifu/kemoverse

Split get_or_create_user

This commit is contained in:
w 2025-06-01 18:08:51 -03:00
parent 6ea5529ef5
commit da2ca4cfec

View file

@ -28,21 +28,19 @@ def get_random_character():
return chosen['id'], chosen['name'], chosen['file_id'], chosen['rarity']
def get_or_create_user(username):
'''Retrieves an ID for a given user, if the user does not exist, it will be
created.'''
def get_player(username):
'''Retrieve a player ID by username, or return None if not found.'''
CURSOR.execute('SELECT id FROM users WHERE username = ?', (username,))
user = CURSOR.fetchone()
if user:
return user[0]
return user[0] if user else None
# New user starts with has_rolled = False
def insert_player(username):
'''Insert a new player with default has_rolled = False and return their user ID.'''
CURSOR.execute(
'INSERT INTO users (username, has_rolled) VALUES (?, ?)',
(username, False)
)
user_id = CURSOR.lastrowid
return user_id
return CURSOR.lastrowid
def insert_character(name: str, rarity: int, weight: float, file_id: str) -> int:
'''Inserts a character'''