diff options
author | Parker <contact@pkrm.dev> | 2024-11-28 00:41:33 -0600 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-11-28 00:41:33 -0600 |
commit | e73db927c17866793293868d915bf0e37a906737 (patch) | |
tree | e05843e8e4af9b672731a435e8bd8a1f559bece9 /code/utils/source_helpers/spotify | |
parent | 1ce91a4b0984407bcd08b4fbf7448d7f4dbcead2 (diff) |
Create `create_embed` template to replace `discord.Embed()`
- Auto-set color to BOT_COLOR
- Set footer to timestamp (overridden is timestamp is passed)
- Optional thumbnail
Diffstat (limited to 'code/utils/source_helpers/spotify')
-rw-r--r-- | code/utils/source_helpers/spotify/album.py | 13 | ||||
-rw-r--r-- | code/utils/source_helpers/spotify/playlist.py | 13 | ||||
-rw-r--r-- | code/utils/source_helpers/spotify/song.py | 13 |
3 files changed, 12 insertions, 27 deletions
diff --git a/code/utils/source_helpers/spotify/album.py b/code/utils/source_helpers/spotify/album.py index cf527ed..0ebc7d5 100644 --- a/code/utils/source_helpers/spotify/album.py +++ b/code/utils/source_helpers/spotify/album.py @@ -4,7 +4,7 @@ import requests from typing import Tuple, Optional from requests.exceptions import JSONDecodeError -from utils.config import BOT_COLOR, LOG +from utils.config import create_embed, LOG async def load( @@ -25,13 +25,12 @@ async def load( ) if response.status_code == 404: - embed = discord.Embed( + embed = create_embed( title="Album Not Found", description=( "The album could not be found as the provided link is" " invalid. Please try again." ), - color=BOT_COLOR, ) return None, embed @@ -56,18 +55,14 @@ async def load( LOG.error("Failed making request to Spotify API") return None, None - embed = discord.Embed( + embed = create_embed( title="Album Queued", description=( f"**{name}** by **{artist}**\n" f"` {num_tracks} ` tracks\n\n" f"Queued by: {user.mention}" ), - color=BOT_COLOR, - ) - embed.set_thumbnail(url=artwork_url) - embed.set_footer( - text=datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " UTC" + thumbnail=artwork_url, ) return album, embed diff --git a/code/utils/source_helpers/spotify/playlist.py b/code/utils/source_helpers/spotify/playlist.py index c806e39..c7313a4 100644 --- a/code/utils/source_helpers/spotify/playlist.py +++ b/code/utils/source_helpers/spotify/playlist.py @@ -4,7 +4,7 @@ import requests from typing import Tuple, Optional from requests.exceptions import JSONDecodeError -from utils.config import BOT_COLOR, LOG +from utils.config import create_embed, LOG async def load( @@ -25,13 +25,12 @@ async def load( ) if response.status_code == 404: - embed = discord.Embed( + embed = create_embed( title="Playlist Not Found", description=( "The playlist could not be found as the provided link is" " invalid. Please try again." ), - color=BOT_COLOR, ) return None, embed @@ -56,18 +55,14 @@ async def load( LOG.error("Failed making request to Spotify API") return None, None - embed = discord.Embed( + embed = create_embed( title="Playlist Queued", description=( f"**{name}** from **{owner}**\n" f"` {num_tracks} ` tracks\n\n" f"Queued by {user.mention}" ), - color=BOT_COLOR, - ) - embed.set_thumbnail(url=artwork_url) - embed.set_footer( - text=datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " UTC" + thumbnail=artwork_url, ) return playlist, embed diff --git a/code/utils/source_helpers/spotify/song.py b/code/utils/source_helpers/spotify/song.py index 258b652..b0c7379 100644 --- a/code/utils/source_helpers/spotify/song.py +++ b/code/utils/source_helpers/spotify/song.py @@ -4,7 +4,7 @@ import requests from typing import Tuple, Optional from requests.exceptions import JSONDecodeError -from utils.config import BOT_COLOR, LOG +from utils.config import create_embed, LOG async def load( @@ -25,13 +25,12 @@ async def load( ) if response.status_code == 404: - embed = discord.Embed( + embed = create_embed( title="Song Not Found", description=( "The song could not be found as the provided link is" " invalid. Please try again." ), - color=BOT_COLOR, ) return None, embed @@ -55,14 +54,10 @@ async def load( LOG.error("Failed making request to Spotify API") return None, None - embed = discord.Embed( + embed = create_embed( title="Song Queued", description=f"**{name}** by **{artist}**\n\nQueued by {user.mention}", - color=BOT_COLOR, - ) - embed.set_thumbnail(url=artwork_url) - embed.set_footer( - text=datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " UTC" + thumbnail=artwork_url, ) return song, embed |