From 6a4c8b759a058039d75975e420d77de44f345e95 Mon Sep 17 00:00:00 2001 From: Lili Date: Tue, 18 Oct 2022 14:09:35 +0200 Subject: [PATCH] fix None type error --- tlapbot/owncast_helpers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tlapbot/owncast_helpers.py b/tlapbot/owncast_helpers.py index d432555..1bb4108 100644 --- a/tlapbot/owncast_helpers.py +++ b/tlapbot/owncast_helpers.py @@ -34,6 +34,7 @@ def send_chat(message): # # # db stuff # # # def read_users_points(db, user_id): + """Errors out if user doesn't exist.""" try: cursor = db.execute( "SELECT points FROM points WHERE id = ?", @@ -46,12 +47,17 @@ def read_users_points(db, user_id): def read_users_points_from_username(db, username): + """Returns None if user doesn't exist, their points otherwise.""" try: cursor = db.execute( "SELECT points FROM points WHERE name = ?", (username,) ) - return cursor.fetchone()[0] + points = cursor.fetchone() + if points is None: + return None + else: + return cursor.fetchone()[0] except Error as e: print("Error occured reading points from username:", e.args[0]) print("To user:", username)