fix check_grass_touching_bans crashing due to not using app context

This commit is contained in:
csd4ni3l
2025-08-14 13:25:22 +02:00
parent f61ca26ce5
commit f5ab1dd78d

15
main.py
View File

@@ -54,15 +54,16 @@ def close_connection(exception):
def check_grass_touching_bans(): def check_grass_touching_bans():
while True: while True:
cur = get_db().cursor() with app.app_context():
cur = get_db().cursor()
cur.execute("SELECT username, last_grass_touch_time FROM Users") cur.execute("SELECT username, last_grass_touch_time FROM Users")
for user in cur.fetchall(): for user in cur.fetchall():
if time.time() - user[1] >= (24 * 3600): if time.time() - user[1] >= (24 * 3600):
cur.execute("UPDATE users SET banned = ? WHERE username = ?", (True, user[0])) cur.execute("UPDATE users SET banned = ? WHERE username = ?", (True, user[0]))
cur.close() cur.close()
time.sleep(60) time.sleep(60)
threading.Thread(target=check_grass_touching_bans, daemon=True).start() threading.Thread(target=check_grass_touching_bans, daemon=True).start()