Skip to content

Commit

Permalink
discord.Embed.Empty solve (check switch)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtoid committed Mar 16, 2022
1 parent 9840dc2 commit 9727f0a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
29 changes: 19 additions & 10 deletions chat_exporter/construct/assets/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
)


def _gather_checker():
if hasattr(discord.Embed, "Empty"):
return discord.Embed.Empty
return None


class Embed:
r: str
g: str
Expand All @@ -32,11 +38,14 @@ class Embed:
footer: str
fields: str

check_against = None

def __init__(self, embed, guild):
self.embed: discord.Embed = embed
self.guild: discord.Guild = guild

async def flow(self):
self.check_against = _gather_checker()
self.build_colour()
await self.build_title()
await self.build_description()
Expand All @@ -52,19 +61,19 @@ async def flow(self):
def build_colour(self):
self.r, self.g, self.b = (
(self.embed.colour.r, self.embed.colour.g, self.embed.colour.b)
if self.embed.colour != discord.Embed.Empty else (0x20, 0x22, 0x25) # default colour
if self.embed.colour != self.check_against else (0x20, 0x22, 0x25) # default colour
)

async def build_title(self):
self.title = self.embed.title if self.embed.title != discord.Embed.Empty else ""
self.title = self.embed.title if self.embed.title != self.check_against else ""

if self.title:
self.title = await fill_out(self.guild, embed_title, [
("EMBED_TITLE", self.title, PARSE_MODE_MARKDOWN)
])

async def build_description(self):
self.description = self.embed.description if self.embed.description != discord.Embed.Empty else ""
self.description = self.embed.description if self.embed.description != self.check_against else ""

if self.description:
self.description = await fill_out(self.guild, embed_description, [
Expand All @@ -85,16 +94,16 @@ async def build_fields(self):
("FIELD_VALUE", field.value, PARSE_MODE_EMBED)])

async def build_author(self):
self.author = self.embed.author.name if self.embed.author.name != discord.Embed.Empty else ""
self.author = self.embed.author.name if self.embed.author.name != self.check_against else ""

self.author = f'<a class="chatlog__embed-author-name-link" href="{self.embed.author.url}">{self.author}</a>' \
if self.embed.author.url != discord.Embed.Empty \
if self.embed.author.url != self.check_against \
else self.author

author_icon = await fill_out(self.guild, embed_author_icon, [
("AUTHOR", self.author, PARSE_MODE_NONE),
("AUTHOR_ICON", self.embed.author.icon_url, PARSE_MODE_NONE)
]) if self.embed.author.icon_url != discord.Embed.Empty else ""
]) if self.embed.author.icon_url != self.check_against else ""

if author_icon == "" and self.author != "":
self.author = await fill_out(self.guild, embed_author, [("AUTHOR", self.author, PARSE_MODE_NONE)])
Expand All @@ -104,16 +113,16 @@ async def build_author(self):
async def build_image(self):
self.image = await fill_out(self.guild, embed_image, [
("EMBED_IMAGE", str(self.embed.image.proxy_url), PARSE_MODE_NONE)
]) if self.embed.image.url != discord.Embed.Empty else ""
]) if self.embed.image.url != self.check_against else ""

async def build_thumbnail(self):
self.thumbnail = await fill_out(self.guild, embed_thumbnail, [
("EMBED_THUMBNAIL", str(self.embed.thumbnail.url), PARSE_MODE_NONE)]) \
if self.embed.thumbnail.url != discord.Embed.Empty else ""
if self.embed.thumbnail.url != self.check_against else ""

async def build_footer(self):
self.footer = self.embed.footer.text if self.embed.footer.text != discord.Embed.Empty else ""
footer_icon = self.embed.footer.icon_url if self.embed.footer.icon_url != discord.Embed.Empty else None
self.footer = self.embed.footer.text if self.embed.footer.text != self.check_against else ""
footer_icon = self.embed.footer.icon_url if self.embed.footer.icon_url != self.check_against else None

if not self.footer:
return
Expand Down
4 changes: 2 additions & 2 deletions chat_exporter/html/message/message.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="chatlog__message " data-message-id="{{MESSAGE_ID}}" id="message-{{MESSAGE_ID}}">
{{MESSAGE_CONTENT}}

{{EMBEDS}}

{{COMPONENTS}}

{{ATTACHMENTS}}

{{EMBEDS}}

{{EMOJI}}

</div>

0 comments on commit 9727f0a

Please sign in to comment.