diff options
author | Arjun Satarkar <me@arjunsatarkar.net> | 2023-12-24 12:01:01 +0000 |
---|---|---|
committer | Arjun Satarkar <me@arjunsatarkar.net> | 2023-12-24 12:11:05 +0000 |
commit | f6716a5a46292e6adec4f31e2a8641f8cdbab8b5 (patch) | |
tree | 5c3e4a06daa0ba2cf8fb58bdc211963a9ba885a1 /question_of_the_day | |
parent | 4ae42acfb779fc145666618488c378fdc689afe3 (diff) | |
download | aps-cogs-f6716a5a46292e6adec4f31e2a8641f8cdbab8b5.tar aps-cogs-f6716a5a46292e6adec4f31e2a8641f8cdbab8b5.tar.gz aps-cogs-f6716a5a46292e6adec4f31e2a8641f8cdbab8b5.zip |
question_of_the_day: make sure we will never spam errors in edge cases
Diffstat (limited to 'question_of_the_day')
-rw-r--r-- | question_of_the_day/question_of_the_day.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/question_of_the_day/question_of_the_day.py b/question_of_the_day/question_of_the_day.py index 21f41b3..3f7971e 100644 --- a/question_of_the_day/question_of_the_day.py +++ b/question_of_the_day/question_of_the_day.py @@ -274,6 +274,8 @@ 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 @@ -281,7 +283,13 @@ class QuestionOfTheDay(commands.Cog): try: suggested_question = suggested_questions[suggestion_id - 1] except IndexError: - await ctx.reply(f"Error: no suggestion with id {suggestion_id}.") + 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 approved_suggestion_text = suggested_question["question"] async with self.config.guild(ctx.guild).questions() as questions: @@ -298,7 +306,7 @@ class QuestionOfTheDay(commands.Cog): ctx.guild ).suggested_questions() as suggested_questions: if suggestion_id == "all": - for _ in range(len(suggested_questions)): + for _ in suggested_questions: await approve_suggestion(suggested_questions, 1) await ctx.reply("Approved all suggestions!") else: |