diff --git a/bot/db_utils.py b/bot/db_utils.py index daff8c5..6f94cc8 100644 --- a/bot/db_utils.py +++ b/bot/db_utils.py @@ -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'''