diff --git a/src/cogs/starboard.py b/src/cogs/starboard.py index d721a4a..a6fa28b 100644 --- a/src/cogs/starboard.py +++ b/src/cogs/starboard.py @@ -18,24 +18,28 @@ class Starboard(commands.Cog): self.log = logging.getLogger("jimmy.cogs.starboard") self.redis = Redis(**CONFIG["redis"]) - async def generate_starboard_embed(self, message: discord.Message) -> tuple[discord.Embed, int]: + async def generate_starboard_embed(self, message: discord.Message) -> tuple[list[discord.Embed], int]: """ Generates an embed ready for a starboard message. :param message: The message to base off of. :return: The created embed """ - reactions: list[discord.Reaction] = [x for x in message.reactions if x.emoji == self.emoji] - downvote_reactions = [x for x in message.reactions if x.emoji == self.DOWNVOTE_EMOJI] + reactions: list[discord.Reaction] = [x for x in message.reactions if str(x.emoji) == str(self.emoji)] + downvote_reactions = [x for x in message.reactions if str(x.emoji) == str(self.DOWNVOTE_EMOJI)] if not reactions: # Nobody has added the star reaction. star_count = 0 + self.log.debug("There are no star reactions at all on message.") else: # Count the number of reactions star_count = sum([x.count for x in reactions]) + self.log.debug("There are a total of %d star reactions on message.", star_count) if downvote_reactions: - star_count -= sum([x.count for x in downvote_reactions]) + _dv = sum([x.count for x in downvote_reactions]) + star_count -= _dv + self.log.debug("There are %d downvotes on message, resulting in %d stars.", _dv, star_count) if star_count >= 0: star_emoji_count = (str(self.emoji) * star_count)[:10] @@ -69,7 +73,7 @@ class Starboard(commands.Cog): continue if message_embed.description: embed.description = message_embed.description - if not message.attachments and not embed.description: + if not message.attachments: raise ValueError("Message does not appear to contain any text, embeds, or attachments.") if message.attachments: @@ -97,7 +101,7 @@ class Starboard(commands.Cog): # This whacky reverse -> perform -> reverse basically just means we can set the first image/* # attachment as the image. - return embed, star_count + return [embed, *filter(lambda e: e.type == "rich", message.embeds)], star_count async def get_or_fetch_message(self, channel_id: int, message_id: int) -> discord.Message: """ @@ -160,7 +164,7 @@ class Starboard(commands.Cog): "starboard_channel_id": starboard_channel, "starboard_message_id": None } - if not starboard_channel.can_send(embed): + if not starboard_channel.can_send(embed[0]): self.log.warning( "Cannot send starboard messages in %d, %d (#%s @ %s)", starboard_channel.id, @@ -171,7 +175,7 @@ class Starboard(commands.Cog): return starboard_message = await starboard_channel.send( - embed=embed, + embeds=embed, silent=True ) data["starboard_message_id"] = starboard_message.id @@ -186,7 +190,7 @@ class Starboard(commands.Cog): if star_count <= 0: return starboard_message = await starboard_channel.send( - embed=embed, + embeds=embed, silent=True ) data["starboard_message_id"] = starboard_message.id @@ -201,8 +205,8 @@ class Starboard(commands.Cog): starboard_message.channel.name, starboard_message.guild.name ) - elif starboard_message.embeds[0] != embed: - await starboard_message.edit(embed=embed) + elif starboard_message.embeds[0] != embed[0]: + await starboard_message.edit(embeds=embed) @commands.message_command(name="Preview Starboard Message") async def preview_starboard_message(self, ctx: discord.ApplicationContext, message: discord.Message): @@ -210,7 +214,7 @@ class Starboard(commands.Cog): data = await self.redis.get(str(message.id)) return await ctx.respond( f"```json\n{json.dumps(data, indent=4)}\n```\nStars: {stars:,}", - embed=embed + embeds=embed )