From f5ab1dd78d965ffb690fbd9fc7f4be533b83b194 Mon Sep 17 00:00:00 2001 From: csd4ni3l Date: Thu, 14 Aug 2025 13:25:22 +0200 Subject: [PATCH] fix check_grass_touching_bans crashing due to not using app context --- main.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 34f10cc..8c9e207 100644 --- a/main.py +++ b/main.py @@ -54,15 +54,16 @@ def close_connection(exception): def check_grass_touching_bans(): while True: - cur = get_db().cursor() - - cur.execute("SELECT username, last_grass_touch_time FROM Users") - for user in cur.fetchall(): - if time.time() - user[1] >= (24 * 3600): - cur.execute("UPDATE users SET banned = ? WHERE username = ?", (True, user[0])) - cur.close() + with app.app_context(): + cur = get_db().cursor() + + cur.execute("SELECT username, last_grass_touch_time FROM Users") + for user in cur.fetchall(): + if time.time() - user[1] >= (24 * 3600): + cur.execute("UPDATE users SET banned = ? WHERE username = ?", (True, user[0])) + cur.close() - time.sleep(60) + time.sleep(60) threading.Thread(target=check_grass_touching_bans, daemon=True).start()