From f2768df33f2d798982ebc0df8db550f1bc3c6187 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sun, 24 Jan 2021 18:10:14 -0600 Subject: [PATCH] helper method for matching bot embeds to users, improve helper method docs/formatting --- bot/client.py | 2 +- bot/helpers.py | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/bot/client.py b/bot/client.py index 29c3627..df1a88c 100644 --- a/bot/client.py +++ b/bot/client.py @@ -54,7 +54,7 @@ class UnbelievaClient(discord.Client): if message.author.id == self.bot_id and len(message.embeds) > 0: embed = message.embeds[0] - is_self = embed.author.name == f'{self.user.name}#{self.user.discriminator}' + is_self = helpers.embed_author_matches(embed, self.user) if is_self: if parsers.TaskCooldownMessage.check_valid(message): diff --git a/bot/helpers.py b/bot/helpers.py index 6f22302..9a970a6 100644 --- a/bot/helpers.py +++ b/bot/helpers.py @@ -1,15 +1,14 @@ from pprint import pprint +from typing import Union import discord def print_embed(embed: discord.Embed) -> None: - pprint(( - embed.title, - embed.description, - embed.footer, - embed.color, - embed.fields, - embed.author, - embed.timestamp - )) + """Helper method for printing out a complex Embed's entire set of possible attributes.""" + pprint((embed.title, embed.description, embed.footer, embed.color, embed.fields, embed.author, embed.timestamp)) + + +def embed_author_matches(embed: discord.Embed, user: Union[discord.User, discord.ClientUser]): + """Returns if the Unbelievabot Embed relates to the given user.""" + return embed.author != discord.embeds.EmptyEmbed and embed.author.name == f'{user.name}#{user.discriminator}'