FEAT: Changed Spotify and Plex to use Embeds to make them look neater
This commit is contained in:
parent
4f3bc7669d
commit
100d9af588
@ -19,15 +19,18 @@ class PlexModule:
|
||||
try:
|
||||
libraries = self.plex.library.sections()
|
||||
library_names = [lib.title for lib in libraries]
|
||||
await interaction.followup.send(
|
||||
f"Plex Libraries: {', '.join(library_names)}"
|
||||
embed = discord.Embed(
|
||||
title="Plex Libraries",
|
||||
description=", ".join(library_names),
|
||||
color=discord.Color.blue()
|
||||
)
|
||||
await interaction.followup.send(embed=embed)
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"An error occurred: {e}")
|
||||
|
||||
@app_commands.command(
|
||||
name="search_library",
|
||||
description="Search for a movie in a library"
|
||||
description="Search for a movie or TV show in a library"
|
||||
)
|
||||
async def search_library(
|
||||
interaction: discord.Interaction, library: str, query: str
|
||||
@ -38,20 +41,27 @@ class PlexModule:
|
||||
results = lib.search(query)
|
||||
if not results:
|
||||
await interaction.followup.send(
|
||||
f"No results found for '{query}' in '{library}'"
|
||||
embed=discord.Embed(
|
||||
title="Search Library",
|
||||
description=f"No results found for '{query}' in '{library}'", # noqa: E501
|
||||
color=discord.Color.red()
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
result_titles = [result.title for result in results]
|
||||
await interaction.followup.send(
|
||||
f"Search results in {library}: {', '.join(result_titles)}"
|
||||
embed = discord.Embed(
|
||||
title=f"Search results in {library}",
|
||||
description=", ".join(result_titles),
|
||||
color=discord.Color.blue()
|
||||
)
|
||||
await interaction.followup.send(embed=embed)
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"An error occurred: {e}")
|
||||
|
||||
@app_commands.command(
|
||||
name="play_movie", description="Play a movie on a specified Plex "
|
||||
"client"
|
||||
name="play_movie",
|
||||
description="Play a movie on a specified Plex client"
|
||||
)
|
||||
async def play_movie(
|
||||
interaction: discord.Interaction, client_name: str, movie_name: str
|
||||
@ -64,21 +74,65 @@ class PlexModule:
|
||||
)
|
||||
if not client:
|
||||
await interaction.followup.send(
|
||||
f"No client found with the name '{client_name}'"
|
||||
embed=discord.Embed(
|
||||
title="Play Movie",
|
||||
description=f"No client found with the name '{client_name}'", # noqa: E501
|
||||
color=discord.Color.red()
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
movie = self.plex.library.section('Movies').get(movie_name)
|
||||
client.playMedia(movie)
|
||||
await interaction.followup.send(
|
||||
f"Playing '{movie_name}' on '{client_name}'"
|
||||
embed = discord.Embed(
|
||||
title="Playing Movie",
|
||||
description=f"Playing '{movie_name}' on '{client_name}'",
|
||||
color=discord.Color.green()
|
||||
)
|
||||
await interaction.followup.send(embed=embed)
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"An error occurred: {e}")
|
||||
|
||||
@app_commands.command(
|
||||
name="play_tv_show",
|
||||
description="Play a TV show on a specified Plex client"
|
||||
)
|
||||
async def play_tv_show(
|
||||
interaction: discord.Interaction, client_name: str, library: str,
|
||||
show_name: str, season: int, episode: int
|
||||
):
|
||||
await interaction.response.defer()
|
||||
try:
|
||||
client = next(
|
||||
(c for c in self.plex.clients() if c.title == client_name),
|
||||
None
|
||||
)
|
||||
if not client:
|
||||
await interaction.followup.send(
|
||||
embed=discord.Embed(
|
||||
title="Play TV Show",
|
||||
description=f"No client found with the name '{client_name}'", # noqa: E501
|
||||
color=discord.Color.red()
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
show = self.plex.library.section(library).get(show_name)
|
||||
episode = show.season(season).episode(episode)
|
||||
client.playMedia(episode)
|
||||
embed = discord.Embed(
|
||||
title="Playing TV Show",
|
||||
description=f"Playing '{show_name}' S{season}E{episode} on '{client_name}'", # noqa: E501
|
||||
color=discord.Color.green()
|
||||
)
|
||||
await interaction.followup.send(embed=embed)
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"An error occurred: {e}")
|
||||
|
||||
self.bot.tree.add_command(list_libraries)
|
||||
self.bot.tree.add_command(search_library)
|
||||
self.bot.tree.add_command(play_movie)
|
||||
self.bot.tree.add_command(play_tv_show)
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
|
@ -31,15 +31,26 @@ class SpotifyModule:
|
||||
current = self.sp.currently_playing()
|
||||
if current is None or current["item"] is None:
|
||||
await interaction.followup.send(
|
||||
"No song is currently playing"
|
||||
embed=discord.Embed(
|
||||
title="Current Track",
|
||||
description="No song is currently playing",
|
||||
color=discord.Color.red()
|
||||
)
|
||||
)
|
||||
else:
|
||||
track = current["item"]
|
||||
artist = ", ".join([a["name"] for a in track["artists"]])
|
||||
await interaction.followup.send(
|
||||
f"Currently playing: {track['name']} by {artist} "
|
||||
f"({track['album']['name']})"
|
||||
embed = discord.Embed(
|
||||
title="Current Track",
|
||||
description=f"{track['name']} by {artist}",
|
||||
color=discord.Color.green()
|
||||
)
|
||||
embed.add_field(
|
||||
name="Album", value=track['album']['name'],
|
||||
inline=False
|
||||
)
|
||||
embed.set_thumbnail(url=track['album']['images'][0]['url'])
|
||||
await interaction.followup.send(embed=embed)
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"An error occurred: {e}")
|
||||
|
||||
@ -51,7 +62,13 @@ class SpotifyModule:
|
||||
try:
|
||||
results = self.sp.search(q=query, limit=1, type="track")
|
||||
if not results["tracks"]["items"]:
|
||||
await interaction.followup.send("No results found")
|
||||
await interaction.followup.send(
|
||||
embed=discord.Embed(
|
||||
title="Play Track",
|
||||
description="No results found",
|
||||
color=discord.Color.red()
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
track = results["tracks"]["items"][0]
|
||||
@ -60,17 +77,26 @@ class SpotifyModule:
|
||||
devices = self.sp.devices()
|
||||
if not devices["devices"]:
|
||||
await interaction.followup.send(
|
||||
"No active devices found. Please open Spotify on a "
|
||||
"device."
|
||||
embed=discord.Embed(
|
||||
title="Play Track",
|
||||
description="No active devices found."
|
||||
"Please open Spotify on a device.",
|
||||
color=discord.Color.red()
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
self.sp.start_playback(uris=[uri])
|
||||
await interaction.followup.send(
|
||||
f"Now playing: {track['name']} by "
|
||||
f"{', '.join([a['name'] for a in track['artists']])} "
|
||||
f"({track['album']['name']})"
|
||||
embed = discord.Embed(
|
||||
title="Now Playing",
|
||||
description=f"{track['name']} by {', '.join([a['name'] for a in track['artists']])}", # noqa: E501
|
||||
color=discord.Color.green()
|
||||
)
|
||||
embed.add_field(
|
||||
name="Album", value=track['album']['name'], inline=False
|
||||
)
|
||||
embed.set_thumbnail(url=track['album']['images'][0]['url'])
|
||||
await interaction.followup.send(embed=embed)
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"An error occurred: {e}")
|
||||
|
||||
@ -83,7 +109,13 @@ class SpotifyModule:
|
||||
try:
|
||||
results = self.sp.search(q=query, limit=1, type="playlist")
|
||||
if not results["playlists"]["items"]:
|
||||
await interaction.followup.send("No results found")
|
||||
await interaction.followup.send(
|
||||
embed=discord.Embed(
|
||||
title="Play Playlist",
|
||||
description="No results found",
|
||||
color=discord.Color.red()
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
playlist = results["playlists"]["items"][0]
|
||||
@ -92,16 +124,23 @@ class SpotifyModule:
|
||||
devices = self.sp.devices()
|
||||
if not devices["devices"]:
|
||||
await interaction.followup.send(
|
||||
"No active devices found. Please open Spotify on a "
|
||||
"device."
|
||||
embed=discord.Embed(
|
||||
title="Play Playlist",
|
||||
description="No active devices found."
|
||||
"Please open Spotify on a device.",
|
||||
color=discord.Color.red()
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
self.sp.start_playback(context_uri=uri)
|
||||
await interaction.followup.send(
|
||||
f"Now playing playlist: {playlist['name']} by "
|
||||
f"{playlist['owner']['display_name']}"
|
||||
embed = discord.Embed(
|
||||
title="Now Playing Playlist",
|
||||
description=f"{playlist['name']} by {playlist['owner']['display_name']}", # noqa: E501
|
||||
color=discord.Color.green()
|
||||
)
|
||||
embed.set_thumbnail(url=playlist['images'][0]['url'])
|
||||
await interaction.followup.send(embed=embed)
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"An error occurred: {e}")
|
||||
|
||||
@ -112,7 +151,13 @@ class SpotifyModule:
|
||||
await interaction.response.defer()
|
||||
try:
|
||||
self.sp.pause_playback()
|
||||
await interaction.followup.send("Playback paused.")
|
||||
await interaction.followup.send(
|
||||
embed=discord.Embed(
|
||||
title="Pause",
|
||||
description="Playback paused.",
|
||||
color=discord.Color.green()
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"An error occurred: {e}")
|
||||
|
||||
@ -123,7 +168,13 @@ class SpotifyModule:
|
||||
await interaction.response.defer()
|
||||
try:
|
||||
self.sp.start_playback()
|
||||
await interaction.followup.send("Playback resumed.")
|
||||
await interaction.followup.send(
|
||||
embed=discord.Embed(
|
||||
title="Resume",
|
||||
description="Playback resumed.",
|
||||
color=discord.Color.green()
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"An error occurred: {e}")
|
||||
|
||||
@ -134,7 +185,13 @@ class SpotifyModule:
|
||||
await interaction.response.defer()
|
||||
try:
|
||||
self.sp.next_track()
|
||||
await interaction.followup.send("Skipped to the next track.")
|
||||
await interaction.followup.send(
|
||||
embed=discord.Embed(
|
||||
title="Next Track",
|
||||
description="Skipped to the next track.",
|
||||
color=discord.Color.green()
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"An error occurred: {e}")
|
||||
|
||||
@ -146,7 +203,11 @@ class SpotifyModule:
|
||||
try:
|
||||
self.sp.previous_track()
|
||||
await interaction.followup.send(
|
||||
"Returned to the previous track."
|
||||
embed=discord.Embed(
|
||||
title="Previous Track",
|
||||
description="Returned to the previous track.",
|
||||
color=discord.Color.green()
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"An error occurred: {e}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user