Split get_or_create_user
This commit is contained in:
parent
6ea5529ef5
commit
da2ca4cfec
1 changed files with 6 additions and 8 deletions
|
@ -28,21 +28,19 @@ def get_random_character():
|
||||||
|
|
||||||
return chosen['id'], chosen['name'], chosen['file_id'], chosen['rarity']
|
return chosen['id'], chosen['name'], chosen['file_id'], chosen['rarity']
|
||||||
|
|
||||||
def get_or_create_user(username):
|
def get_player(username):
|
||||||
'''Retrieves an ID for a given user, if the user does not exist, it will be
|
'''Retrieve a player ID by username, or return None if not found.'''
|
||||||
created.'''
|
|
||||||
CURSOR.execute('SELECT id FROM users WHERE username = ?', (username,))
|
CURSOR.execute('SELECT id FROM users WHERE username = ?', (username,))
|
||||||
user = CURSOR.fetchone()
|
user = CURSOR.fetchone()
|
||||||
if user:
|
return user[0] if user else None
|
||||||
return user[0]
|
|
||||||
|
|
||||||
# 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(
|
CURSOR.execute(
|
||||||
'INSERT INTO users (username, has_rolled) VALUES (?, ?)',
|
'INSERT INTO users (username, has_rolled) VALUES (?, ?)',
|
||||||
(username, False)
|
(username, False)
|
||||||
)
|
)
|
||||||
user_id = CURSOR.lastrowid
|
return CURSOR.lastrowid
|
||||||
return user_id
|
|
||||||
|
|
||||||
def insert_character(name: str, rarity: int, weight: float, file_id: str) -> int:
|
def insert_character(name: str, rarity: int, weight: float, file_id: str) -> int:
|
||||||
'''Inserts a character'''
|
'''Inserts a character'''
|
||||||
|
|
Loading…
Add table
Reference in a new issue