aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2019-09-14 13:23:44 +0200
committerGravatar Leon Sandøy <[email protected]>2019-09-14 13:23:44 +0200
commit279fa85b93d5017a63d68516b2477a86920caa16 (patch)
tree92db20c3d0d3f8abe81cb9425090729c8917a3a1
parentMake 'post_infraction' catch the right exception (diff)
Improvements to the Wolfram cog.
This commit adds clearer error messages for all the errors produced by the Wolfram cog if the API key is missing in the config, or if the key isn't valid anymore. It also humanizes the timedelta returned in the error users get when they run out their cooldown. Instead of telling them they need to wait 84000 seconds, it will now tell them they need to wait 23 hours, 59 minutes ...
-rw-r--r--bot/cogs/wolfram.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/bot/cogs/wolfram.py b/bot/cogs/wolfram.py
index e8b16b243..7dd613083 100644
--- a/bot/cogs/wolfram.py
+++ b/bot/cogs/wolfram.py
@@ -4,12 +4,14 @@ from typing import List, Optional, Tuple
from urllib import parse
import discord
+from dateutil.relativedelta import relativedelta
from discord import Embed
from discord.ext import commands
from discord.ext.commands import BucketType, Context, check, group
from bot.constants import Colours, STAFF_ROLES, Wolfram
from bot.pagination import ImagePaginator
+from bot.utils.time import humanize_delta
log = logging.getLogger(__name__)
@@ -79,9 +81,11 @@ def custom_cooldown(*ignore: List[int]) -> check:
if user_rate:
# Can't use api; cause: member limit
+ delta = relativedelta(seconds=int(user_rate))
+ cooldown = humanize_delta(delta)
message = (
"You've used up your limit for Wolfram|Alpha requests.\n"
- f"Cooldown: {int(user_rate)}"
+ f"Cooldown: {cooldown}"
)
await send_embed(ctx, message)
return False
@@ -121,17 +125,27 @@ async def get_pod_pages(ctx, bot, query: str) -> Optional[List[Tuple]]:
result = json["queryresult"]
- if not result["success"]:
- message = f"I couldn't find anything for {query}."
- await send_embed(ctx, message)
- return
-
if result["error"]:
+ # API key not set up correctly
+ if result["error"]["msg"] == "Invalid appid":
+ message = "Wolfram API key is invalid or missing."
+ log.warning(
+ "API key seems to be missing, or invalid when "
+ f"processing a wolfram request: {url_str}, Response: {json}"
+ )
+ await send_embed(ctx, message)
+ return
+
message = "Something went wrong internally with your request, please notify staff!"
log.warning(f"Something went wrong getting a response from wolfram: {url_str}, Response: {json}")
await send_embed(ctx, message)
return
+ if not result["success"]:
+ message = f"I couldn't find anything for {query}."
+ await send_embed(ctx, message)
+ return
+
if not result["numpods"]:
message = "Could not find any results."
await send_embed(ctx, message)
@@ -191,6 +205,10 @@ class Wolfram:
message = "No input found"
footer = ""
color = Colours.soft_red
+ elif status == 403:
+ message = "Wolfram API key is invalid or missing."
+ footer = ""
+ color = Colours.soft_red
else:
message = ""
footer = "View original for a bigger picture."
@@ -272,10 +290,12 @@ class Wolfram:
if status == 501:
message = "Failed to get response"
color = Colours.soft_red
-
elif status == 400:
message = "No input found"
color = Colours.soft_red
+ elif response_text == "Error 1: Invalid appid":
+ message = "Wolfram API key is invalid or missing."
+ color = Colours.soft_red
else:
message = response_text
color = Colours.soft_orange