Refactor bot server setup to use Waitress for production; fallback to Flask dev server for local development. Added timeout to HTTP requests in Fun and Test cogs. Improved error handling for missing environment variables. Enhanced secret key management in Flask app. Added request timeout configuration. Introduced new experimental features including user profile and balance cards, and a Tic-Tac-Toe game with Minimax AI. Addressed various database and security issues, and improved code quality across multiple files.

This commit is contained in:
2026-05-31 12:01:12 +00:00
parent be89cc3acd
commit 1b91cbcb2f
17 changed files with 284 additions and 61 deletions
+20 -6
View File
@@ -9,7 +9,17 @@ import threading
def run_web():
app.run(debug=False, host="0.0.0.0", port=5000)
try:
# Prefer a production-ready WSGI server if available
from waitress import serve
serve(app, host="0.0.0.0", port=5000)
except Exception:
# Fall back to Flask dev server for local development only.
print(
"Warning: Running Flask development server. For production use a WSGI server (gunicorn, waitress, etc.)."
)
app.run(debug=False, host="0.0.0.0", port=5000, use_reloader=False)
class MyNewHelp(commands.MinimalHelpCommand):
@@ -62,11 +72,15 @@ def main():
initialize_database()
client = Client()
token = os.getenv("TOKEN")
if token is not None:
threading.Thread(target=run_web, daemon=True).start()
client.run(token)
else:
print("Token is missing.")
if not token:
raise SystemExit("ERROR: TOKEN environment variable not set.")
# Only start the web interface if explicitly enabled to avoid
# running a dev server inside the bot process by default.
if os.getenv("START_WEB") == "1":
threading.Thread(target=run_web, daemon=False).start()
client.run(token)
if __name__ == "__main__":