From 0b8f466120872903561ffd946e6bff221524a7d9 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 26 Sep 2019 00:18:36 +0200 Subject: [PATCH] Fix some more discord embed bugs --- royalnet/audio/ytdlinfo.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/royalnet/audio/ytdlinfo.py b/royalnet/audio/ytdlinfo.py index e0462c72..bd7c0ae3 100644 --- a/royalnet/audio/ytdlinfo.py +++ b/royalnet/audio/ytdlinfo.py @@ -103,14 +103,24 @@ class YtdlInfo: def to_discord_embed(self) -> discord.Embed: """Return this info as a :py:class:`discord.Embed`.""" + colors = { + "youtube": 0xCC0000, + "soundcloud": 0xFF5400, + "Clyp": 0x3DBEB3, + "Bandcamp": 0x1DA0C3 + } embed = discord.Embed(title=self.title, - colour=discord.Colour(0xcc0000), - url=self.webpage_url) - embed.set_thumbnail(url=self.thumbnail) - embed.set_author(name=self.uploader, url=self.uploader_url if self.uploader_url is not None else discord.embeds.EmptyEmbed) + colour=discord.Colour(colors.get(self.extractor, 0x4F545C)), + url=self.webpage_url if self.webpage_url is not None else discord.embeds.EmptyEmbed) + if self.thumbnail: + embed.set_thumbnail(url=self.thumbnail) + if self.uploader: + embed.set_author(name=self.uploader, url=self.uploader_url if self.uploader_url is not None else discord.embeds.EmptyEmbed) # embed.set_footer(text="Source: youtube-dl", icon_url="https://i.imgur.com/TSvSRYn.png") - embed.add_field(name="Duration", value=str(self.duration), inline=True) - embed.add_field(name="Published on", value=self.upload_date.strftime("%d %b %Y"), inline=True) + if self.duration: + embed.add_field(name="Duration", value=str(self.duration), inline=True) + if self.upload_date: + embed.add_field(name="Published on", value=self.upload_date.strftime("%d %b %Y"), inline=True) return embed def __repr__(self):