From 29be40ab95f945ad4c1fbf5db5995d900c6bfc42 Mon Sep 17 00:00:00 2001 From: voldemort <5692900+yell0wsuit@users.noreply.github.com> Date: Wed, 23 Jul 2025 01:40:51 +0700 Subject: [PATCH] Add docstrings to user database functions for improved documentation and clarity --- custom_functions/database/user_db.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/custom_functions/database/user_db.py b/custom_functions/database/user_db.py index 7895567..35a632c 100644 --- a/custom_functions/database/user_db.py +++ b/custom_functions/database/user_db.py @@ -1,9 +1,12 @@ +"""Module to manage the user database.""" + import sqlite3 import os import bcrypt def create_user_database(): + """Create the user database.""" os.makedirs(f"{os.getcwd()}/databases/sql", exist_ok=True) with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: @@ -21,6 +24,7 @@ def create_user_database(): def add_user(username, password, api_key): + """Add a user to the database.""" hashed_pw = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()) with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: @@ -37,6 +41,7 @@ def add_user(username, password, api_key): def verify_user(username, password): + """Verify a user.""" with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: cursor = conn.cursor() cursor.execute( @@ -55,6 +60,7 @@ def verify_user(username, password): def fetch_api_key(username): + """Fetch the API key for a user.""" with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: cursor = conn.cursor() cursor.execute( @@ -69,7 +75,7 @@ def fetch_api_key(username): def change_password(username, new_password): - + """Change the password for a user.""" # Hash the new password new_hashed_pw = bcrypt.hashpw(new_password.encode("utf-8"), bcrypt.gensalt()) @@ -85,6 +91,7 @@ def change_password(username, new_password): def change_api_key(username, new_api_key): + """Change the API key for a user.""" # Update the API key in the database with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: cursor = conn.cursor() @@ -97,6 +104,7 @@ def change_api_key(username, new_api_key): def fetch_styled_username(username): + """Fetch the styled username for a user.""" with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: cursor = conn.cursor() cursor.execute( @@ -112,6 +120,7 @@ def fetch_styled_username(username): def fetch_username_by_api_key(api_key): + """Fetch the username for a user by API key.""" with sqlite3.connect(f"{os.getcwd()}/databases/sql/users.db") as conn: cursor = conn.cursor() cursor.execute("SELECT Username FROM user_info WHERE API_Key = ?", (api_key,))