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:
@@ -242,7 +242,7 @@ class Fun(commands.Cog):
|
||||
api_url = f"https://tenor.googleapis.com/v2/search?q={search_query}&key={self.tenor_api_key}&limit=10"
|
||||
|
||||
try:
|
||||
response = requests.get(api_url)
|
||||
response = requests.get(api_url, timeout=10)
|
||||
response.raise_for_status()
|
||||
gif_data = response.json()
|
||||
|
||||
@@ -263,7 +263,7 @@ class Fun(commands.Cog):
|
||||
api_url = "https://meme-api.com/memes/random"
|
||||
|
||||
try:
|
||||
response = requests.get(api_url)
|
||||
response = requests.get(api_url, timeout=10)
|
||||
response.raise_for_status()
|
||||
meme_data = response.json()
|
||||
|
||||
|
||||
@@ -38,7 +38,16 @@ class Test(commands.Cog):
|
||||
@commands.is_owner()
|
||||
@commands.command(name="quiz")
|
||||
async def quiz(self, ctx):
|
||||
response = requests.get("https://opentdb.com/api.php?amount=1&category=18&difficulty=medium&type=multiple").json()["results"][0]
|
||||
try:
|
||||
resp = requests.get(
|
||||
"https://opentdb.com/api.php?amount=1&category=18&difficulty=medium&type=multiple",
|
||||
timeout=10,
|
||||
)
|
||||
resp.raise_for_status()
|
||||
response = resp.json()["results"][0]
|
||||
except requests.RequestException:
|
||||
await ctx.send("Failed to fetch quiz question.")
|
||||
return
|
||||
question = response["question"]
|
||||
|
||||
view = MyView(response["correct_answer"], response["incorrect_answers"])
|
||||
|
||||
Reference in New Issue
Block a user