diff --git a/config.py b/config.py index 8a15c90..e999ad3 100644 --- a/config.py +++ b/config.py @@ -10,3 +10,6 @@ SPOTIPY_CLIENT_SECRET = os.getenv("SPOTIPY_CLIENT_SECRET") SPOTIPY_REDIRECT_URI = os.getenv("SPOTIPY_REDIRECT_URI") PLEX_URL = os.getenv("PLEX_URL") PLEX_TOKEN = os.getenv("PLEX_TOKEN") +TWITCH_CLIENT_ID = os.getenv("TWITCH_CLIENT_ID") +TWITCH_CLIENT_SECRET = os.getenv("TWITCH_CLIENT_SECRET") +TWITCH_CHANNEL = os.getenv("TWITCH_CHANNEL") diff --git a/main.py b/main.py index d9487c5..a70fbda 100644 --- a/main.py +++ b/main.py @@ -8,12 +8,11 @@ class Selena(discord.Client): self.tree = discord.app_commands.CommandTree(self) async def setup_hook(self): - guild = discord.Object(id=config.DISCORD_GUILD_ID) - modules = ["modules.spotify_module", "modules.plex_module"] + modules = ["modules.media.spotify_module", + "modules.media.plex_module"] for module in modules: await self.load_extension(module) - # self.tree.copy_global_to(guild=guild) - await self.tree.sync(guild=guild) + await self.tree.sync() async def load_extension(self, name): module = __import__(name, fromlist=["setup"]) diff --git a/modules/plex_module.py b/modules/media/plex_module.py similarity index 100% rename from modules/plex_module.py rename to modules/media/plex_module.py diff --git a/modules/spotify_module.py b/modules/media/spotify_module.py similarity index 79% rename from modules/spotify_module.py rename to modules/media/spotify_module.py index 5485e8e..ea624cc 100644 --- a/modules/spotify_module.py +++ b/modules/media/spotify_module.py @@ -74,6 +74,37 @@ class SpotifyModule: except Exception as e: await interaction.followup.send(f"An error occurred: {e}") + @app_commands.command( + name="play_playlist", + description="Play a playlist by searching for it" + ) + async def play_playlist(interaction: discord.Interaction, query: str): + await interaction.response.defer() + try: + results = self.sp.search(q=query, limit=1, type="playlist") + if not results["playlists"]["items"]: + await interaction.followup.send("No results found") + return + + playlist = results["playlists"]["items"][0] + uri = playlist["uri"] + + devices = self.sp.devices() + if not devices["devices"]: + await interaction.followup.send( + "No active devices found. Please open Spotify on a " + "device." + ) + return + + self.sp.start_playback(context_uri=uri) + await interaction.followup.send( + f"Now playing playlist: {playlist['name']} by " + f"{playlist['owner']['display_name']}" + ) + except Exception as e: + await interaction.followup.send(f"An error occurred: {e}") + @app_commands.command( name="pause", description="Pause the currently playing track" ) @@ -122,6 +153,7 @@ class SpotifyModule: self.bot.tree.add_command(current_track) self.bot.tree.add_command(play_track) + self.bot.tree.add_command(play_playlist) self.bot.tree.add_command(pause) self.bot.tree.add_command(resume) self.bot.tree.add_command(next_track)