From b3cadb61824a3ae07de4ca2d89f405dc979e1326 Mon Sep 17 00:00:00 2001 From: Arjun Satarkar Date: Fri, 22 Dec 2023 20:02:58 +0530 Subject: question_of_the_day: switch to using an embed --- question_of_the_day/data/abstract_swirl/README.txt | 3 ++ .../data/abstract_swirl/abstract_swirl_160x160.png | Bin 0 -> 58787 bytes question_of_the_day/question_of_the_day.py | 35 ++++++++++++++++++--- 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 question_of_the_day/data/abstract_swirl/README.txt create mode 100644 question_of_the_day/data/abstract_swirl/abstract_swirl_160x160.png diff --git a/question_of_the_day/data/abstract_swirl/README.txt b/question_of_the_day/data/abstract_swirl/README.txt new file mode 100644 index 0000000..985d763 --- /dev/null +++ b/question_of_the_day/data/abstract_swirl/README.txt @@ -0,0 +1,3 @@ +Image from https://publicdomainpictures.net/en/view-image.php?image=138773&picture=absztrakt-orveny +Author: Kevin Phillips +CC0 (public domain) diff --git a/question_of_the_day/data/abstract_swirl/abstract_swirl_160x160.png b/question_of_the_day/data/abstract_swirl/abstract_swirl_160x160.png new file mode 100644 index 0000000..2a8f1ed Binary files /dev/null and b/question_of_the_day/data/abstract_swirl/abstract_swirl_160x160.png differ diff --git a/question_of_the_day/question_of_the_day.py b/question_of_the_day/question_of_the_day.py index bd5f4ea..92335ba 100644 --- a/question_of_the_day/question_of_the_day.py +++ b/question_of_the_day/question_of_the_day.py @@ -7,11 +7,13 @@ import redbot.core import copy import datetime import logging +import pathlib import random import time MAX_QUESTIONS_PER_GUILD = 1000 MAX_QUESTION_SIZE = 500 +ICON_PATH = pathlib.Path("abstract_swirl/abstract_swirl_160x160.png") class QuestionOfTheDay(commands.Cog): @@ -325,17 +327,42 @@ class QuestionOfTheDay(commands.Cog): else: question_index = random.randrange(0, questions_len) question = questions[question_index] + asked_by = await guild.fetch_member(question["asked_by"]) allowed_mentions = discord.AllowedMentions.none() allowed_mentions.users = [asked_by] - message = await channel.send( - f"**Question of the day:** " - f"{question['question']}\n" + + embed = discord.Embed( + description=question["question"] + + "\n" + redbot.core.utils.chat_formatting.italics( - "asked by " + asked_by.mention + "asked by" + asked_by.mention + ) + ) + embed.set_author( + name="Question of the Day", + icon_url=f"attachment://{ICON_PATH.name}", + ) + footer = f"{questions_len - 1} questions left | " + suggestions_count = len( + await self.config.guild(guild).suggested_questions() + ) + footer += ( + f"{suggestions_count} suggestion{'s' if suggestions_count > 1 else ''}" + if suggestions_count + else "no suggestions yet! use qotd suggest" + ) + embed.set_footer(text=footer) + + message = await channel.send( + embed=embed, + file=discord.File( + redbot.core.data_manager.bundled_data_path(self) / ICON_PATH, + ICON_PATH.name, ), allowed_mentions=allowed_mentions, ) + del questions[question_index] await self.manage_qotd_pins(message) self.logger.info(f"Posted QOTD for guild {guild.name} ({guild.id}).") -- cgit v1.2.3-57-g22cb