CHANGE: Modified admin utils to use with clause

This commit is contained in:
JustIceO7
2025-02-27 00:37:19 +00:00
parent 6ba9539fcb
commit 3f95b35acc
3 changed files with 31 additions and 32 deletions

View File

@@ -1,37 +1,36 @@
from database.database import Database
def check_if_admin(username):
# Create a connection to the database
db = Database()
db.create_connection()
"""
Returns whether user is admin
"""
with Database() as db:
is_admin = db.fetchone("""
SELECT is_admin
FROM users
WHERE username = ?;
""", (username,))
return is_admin
return bool(is_admin)
def check_if_user_exists(banned_user):
# Create a connection to the database
db = Database()
db.create_connection()
"""
Returns whether user exists
"""
with Database() as db:
user_exists = db.fetchone("""
SELECT user_id
FROM users
WHERE username = ?;""",
(banned_user,))
return user_exists
return bool(user_exists)
def ban_user(banned_user):
"""Ban a user."""
# Create a connection to the database
db = Database()
db.create_connection()
"""
Bans a user
"""
with Database() as db:
db.execute("""
DELETE FROM users
WHERE username = ?;""",