5.7 KiB
5.7 KiB
Major problems found
1. Database / SQL issues
-
sql_commands.py
execute_query()returnscopy(cursor)after closing the cursor/connection, which is invalid and likely breaks fetch operations.insert()parses SQL text to buildON DUPLICATE KEY UPDATE; this is brittle and unsafe for many query forms.delete()builds SQL using f-strings withtable_nameand column names from caller input, so it can be SQL-injection vulnerable if those values are not controlled.create_table_if_not_exists()also uses unescaped table/schema names via f-string.bulk_insert()assumes params are list of dicts and rebuilds SQL based on keys; this is fragile and can break on mixed column orders.DatabaseManageris instantiated in many modules/cogs, creating multiple separate connection pools instead of reusing one singleton.
-
bank_functions.py
db = DatabaseManager("economy")is created at import time and may use incorrect/duplicate env loading.bank_data()treatsfetch_one()result inconsistently; if it returns{}instead ofNone, account creation may not happen.update_money()usesinsert(..., overwrite=True)to update balances, which is a weird and brittle upsert pattern.record_transaction()callsdb.insert("transactions", ...)without a proper query skeleton.
-
npc_memory.py
- Uses
sqlite3.connect('npc_memory.db')with a hardcoded path and no thread-safety handling. - Single SQLite connection is reused without controlling concurrency or isolation.
- Uses
2. Secret/configuration handling
- app.py
app.secret_key = os.getenv("SECRET_KEY")can beNone, breaking Flask session security.- Required env-vars are checked, but
DISCORD_BOT_TOKENis loaded and never used; config is inconsistent with actual bot startup.
- mail.py
- Loads email credentials from env and may fail silently if missing.
- bot.py
- Prints the bot token with
print(token); this is a secret leak risk.
- Prints the bot token with
- Multiple files call
load_dotenv()repeatedly instead of once at startup.
3. Bot startup / architecture
-
bot.py
iterate_prefix("Vamoc")anditerate_prefix("!V")generate all uppercase/lowercase permutations, which is extremely inefficient and unnecessary.self.iterate_prefix("Vamoc")+self.iterate_prefix("!V")creates huge prefixes list and prints it.- A Flask dev server is started in a daemon thread with
app.run(...), which is not suitable for production and may cause shutdown issues. tokenmissing path handling is minimal and should use explicit error handling.
-
app.py
- Uses Flask dev server, OAuth flows, and session storage without clear production readiness.
- Raw
requestscalls to Discord API are used without timeouts in some cases.
4. Code quality / maintainability
-
economy.py
from utils.bank_functions import *is bad practice and obscures imports.- Duplicate
from discord.ext import commandsimport. - Many methods have weak validation and inconsistent return semantics.
check_transfer()has odd parameter names and does not cleanly separate logic from reply behavior.dailycommand uses inconsistent datetime handling and stores timestamp as float in DB without schema enforcement.
-
sql_commands.py
- Uses
pandasonly forfetch_as_dataframe, which is heavy for a bot and likely unnecessary. pool_reset_sessionconfig usesbool(os.getenv(...)), which returnsTruefor any non-empty string, not only"True".
- Uses
-
README.md
- The documented repo structure does not match actual workspace structure.
- It claims SQLite usage while sql_commands.py uses MySQL.
- It references files/paths that are not present (e.g.
extras/,LICENSE).
5. Dependency / packaging
- requirements.txt
- Includes large packages like
numpy,pandas, andmysql-connectoreven though the bot only needs lightweight DB access and small utilities. mysql-connector==2.2.9is very old; upgrade or usemysql-connector-python/mysqlclient.
- Includes large packages like
6. Security / robustness
-
app.py
- OAuth redirect URL and query parameters are concatenated without URL encoding.
- Session data stores access tokens directly, which is sensitive.
get_user_transactions()builds ORDER BY using string interpolation; it is validated but could be improved with safer mapping.
-
mail.py
- HTML email is generated via large f-strings; this is hard to maintain and could be moved to a template.
-
Many files mix business logic and I/O without error boundaries, so failures can cascade.
7. Other issues / enhancements
- Several experimental files under Experimantal and implementing use
input()and are not production-ready. - npc_memory.py and sql_commands.py should expose a shared data access layer rather than ad-hoc DB wrappers in each module.
- Missing tests, linting, formatting, and structured error logging across the repo.
- app.py has duplicated code patterns for Discord API requests and could benefit from helper functions.
- bot.py and bot_development.py are almost duplicates; consolidate startup logic.
Recommended enhancements
- Centralize configuration and database initialization.
- Use a shared singleton
DatabaseManageror dependency injection. - Add strong type hints and remove wildcard imports.
- Replace Flask dev thread with proper web hosting or decouple the web interface.
- Validate all environment variables at startup.
- Add command-level checks and better error messages.
- Remove or replace heavy dependencies if they are not needed.
- Add tests for DB operations, command behavior, and web routes.
- Clean up README to match actual repository state.
Note: this is a high-level audit, not a full code rewrite. If you want, I can now create a prioritized issue list or fix the worst bugs first.