diff options
author | Arjun Satarkar <me@arjunsatarkar.net> | 2023-12-23 14:19:17 +0000 |
---|---|---|
committer | Arjun Satarkar <me@arjunsatarkar.net> | 2023-12-23 14:19:17 +0000 |
commit | 009a6edd64f890cf3a900e61c84b195a39f48cef (patch) | |
tree | 47f8d6396d47923a0fb5ed2a0cd42a4c996abb80 /question_of_the_day | |
parent | 7a235f032c99a60dd89ed29f3005fce5d2622f9b (diff) | |
download | aps-cogs-009a6edd64f890cf3a900e61c84b195a39f48cef.tar aps-cogs-009a6edd64f890cf3a900e61c84b195a39f48cef.tar.gz aps-cogs-009a6edd64f890cf3a900e61c84b195a39f48cef.zip |
question_of_the_day: add option to approve all suggestions
Diffstat (limited to 'question_of_the_day')
-rw-r--r-- | question_of_the_day/question_of_the_day.py | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/question_of_the_day/question_of_the_day.py b/question_of_the_day/question_of_the_day.py index 9b4a4cc..9f4af07 100644 --- a/question_of_the_day/question_of_the_day.py +++ b/question_of_the_day/question_of_the_day.py @@ -10,6 +10,7 @@ import logging import pathlib import random import time +import typing MAX_QUESTIONS_PER_GUILD = 1000 MAX_QUESTION_SIZE = 500 @@ -266,20 +267,22 @@ class QuestionOfTheDay(commands.Cog): @qotd.command() @checks.admin_or_permissions(manage_server=True) - async def approve(self, ctx, suggestion_id: int): + async def approve(self, ctx, suggestion_id: int | typing.Literal["all"]): """ Approve a suggestion using its id (see `qotd suggestions`). This adds the suggestion to the main queue. """ - async with self.config.guild( - ctx.guild - ).suggested_questions() as suggested_questions: + + async def approve_suggestion( + suggested_questions: list[dict], suggestion_id: int + ) -> str: try: suggested_question = suggested_questions[suggestion_id - 1] except IndexError: await ctx.reply(f"Error: no suggestion with id {suggestion_id}.") return + 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( @@ -288,13 +291,24 @@ class QuestionOfTheDay(commands.Cog): else: questions.append(suggested_question) del suggested_questions[suggestion_id - 1] - await ctx.reply( - f"Approved suggestion {suggestion_id}:\n" - + redbot.core.utils.chat_formatting.quote( - suggested_question["question"] - ), - allowed_mentions=discord.AllowedMentions.none(), - ) + return approved_suggestion_text + + async with self.config.guild( + ctx.guild + ).suggested_questions() as suggested_questions: + if suggestion_id == "all": + for i in range(len(suggested_questions)): + await approve_suggestion(suggested_questions, i) + await ctx.reply("Approved all suggestions!") + else: + approved_suggestion_text = await approve_suggestion( + suggested_questions, suggestion_id + ) + await ctx.reply( + f"Approved suggestion {suggestion_id}:\n" + + redbot.core.utils.chat_formatting.quote(approved_suggestion_text), + allowed_mentions=discord.AllowedMentions.none(), + ) @qotd.command() @checks.admin_or_permissions(manage_server=True) @@ -332,7 +346,8 @@ class QuestionOfTheDay(commands.Cog): description=question["question"] + "\n" + redbot.core.utils.chat_formatting.italics( - "asked by " + (await guild.fetch_member(question["asked_by"])).mention + "asked by " + + (await guild.fetch_member(question["asked_by"])).mention ) ) embed.set_author( |