aboutsummaryrefslogtreecommitdiff
path: root/question_of_the_day/question_of_the_day.py
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2024-02-12 23:09:14 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2024-02-12 23:09:14 +0000
commit5735dd0b55c6bf0e398d9f6ca78230871f36efab (patch)
treeddf6430450e10b96a6dc8dabaeefaec6d0f0bbbb /question_of_the_day/question_of_the_day.py
parentb71b26cf9b32715dd503931180f9c671ba609241 (diff)
downloadaps-cogs-5735dd0b55c6bf0e398d9f6ca78230871f36efab.tar
aps-cogs-5735dd0b55c6bf0e398d9f6ca78230871f36efab.tar.gz
aps-cogs-5735dd0b55c6bf0e398d9f6ca78230871f36efab.zip
question_of_the_day: improve error handling in qotd approve command
Diffstat (limited to 'question_of_the_day/question_of_the_day.py')
-rw-r--r--question_of_the_day/question_of_the_day.py33
1 files changed, 15 insertions, 18 deletions
diff --git a/question_of_the_day/question_of_the_day.py b/question_of_the_day/question_of_the_day.py
index 82c7797..9f92449 100644
--- a/question_of_the_day/question_of_the_day.py
+++ b/question_of_the_day/question_of_the_day.py
@@ -1,7 +1,6 @@
import discord
from discord.ext import tasks
from redbot.core import Config
-from redbot.core import checks
from redbot.core import commands
import redbot.core
import copy
@@ -11,6 +10,7 @@ import pathlib
import random
import time
import typing
+from errors import *
MAX_QUESTIONS_PER_GUILD = 1000
MAX_QUESTION_SIZE = 500
@@ -274,8 +274,6 @@ class QuestionOfTheDay(commands.Cog):
This adds the suggestion to the main queue.
"""
- REPEATABLE_ERROR_REPLIES_MAX = 2
- repeatable_error_replies = 0
async def approve_suggestion(
suggested_questions: list[dict], suggestion_id: int
@@ -283,20 +281,11 @@ class QuestionOfTheDay(commands.Cog):
try:
suggested_question = suggested_questions[suggestion_id - 1]
except IndexError:
- nonlocal repeatable_error_replies
- if repeatable_error_replies <= REPEATABLE_ERROR_REPLIES_MAX:
- repeatable_error_replies += 1
- error_message = f"Error: no suggestion with id {suggestion_id}."
- if repeatable_error_replies == REPEATABLE_ERROR_REPLIES_MAX:
- error_message += " Suppressing further instances of this error on this invocation."
- await ctx.reply(error_message)
- return
+ raise NoSuchSuggestionError(suggestion_id)
approved_suggestion_text = suggested_question["question"]
async with self.config.guild(ctx.guild).questions() as questions:
if len(questions) >= MAX_QUESTIONS_PER_GUILD:
- await ctx.reply(
- f"Error: there are already {MAX_QUESTIONS_PER_GUILD} questions in the main queue; can't approve suggestion."
- )
+ raise QuestionLimitReachedError
else:
questions.append(suggested_question)
del suggested_questions[suggestion_id - 1]
@@ -307,12 +296,20 @@ class QuestionOfTheDay(commands.Cog):
).suggested_questions() as suggested_questions:
if suggestion_id == "all":
for _ in suggested_questions:
- await approve_suggestion(suggested_questions, 1)
+ try:
+ await approve_suggestion(suggested_questions, 1)
+ except (NoSuchSuggestionError, QuestionLimitReachedError) as e:
+ await ctx.reply(str(e))
+ return
await ctx.reply("Approved all suggestions!")
else:
- approved_suggestion_text = await approve_suggestion(
- suggested_questions, suggestion_id
- )
+ try:
+ approved_suggestion_text = await approve_suggestion(
+ suggested_questions, suggestion_id
+ )
+ except (NoSuchSuggestionError, QuestionLimitReachedError) as e:
+ await ctx.reply(str(e))
+ return
await ctx.reply(
f"Approved suggestion {suggestion_id}:\n"
+ redbot.core.utils.chat_formatting.quote(approved_suggestion_text),