diff --git a/.gitignore b/.gitignore index 40aa9d2..71d50e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .vscode -assets/ __pycache__ .env .cache diff --git a/Assets/playermenu.jfif b/Assets/playermenu.jfif new file mode 100644 index 0000000..bd10207 Binary files /dev/null and b/Assets/playermenu.jfif differ diff --git a/Assets/vulkan-logo.png b/Assets/vulkan-logo.png new file mode 100644 index 0000000..7f52e39 Binary files /dev/null and b/Assets/vulkan-logo.png differ diff --git a/Assets/vulkancommands.jfif b/Assets/vulkancommands.jfif new file mode 100644 index 0000000..588aaf6 Binary files /dev/null and b/Assets/vulkancommands.jfif differ diff --git a/DiscordCogs/MusicCog.py b/DiscordCogs/MusicCog.py index 859e88b..add48a2 100644 --- a/DiscordCogs/MusicCog.py +++ b/DiscordCogs/MusicCog.py @@ -17,7 +17,6 @@ from Handlers.QueueHandler import QueueHandler from Handlers.LoopHandler import LoopHandler from UI.Responses.EmoteCogResponse import EmoteCommandResponse from UI.Responses.EmbedCogResponse import EmbedCommandResponse -from UI.Views.PlayerView import PlayerView from Music.VulkanBot import VulkanBot from Config.Configs import VConfigs from Parallelism.ProcessManager import ProcessManager @@ -233,11 +232,6 @@ class MusicCog(Cog): except Exception as e: print(f'[ERROR IN COG] -> {e}') - @command(name='rafael') - async def rafael(self, ctx: Context) -> None: - view = PlayerView(self.__bot) - await ctx.send(view=view) - def setup(bot): bot.add_cog(MusicCog(bot)) diff --git a/Handlers/PlayHandler.py b/Handlers/PlayHandler.py index 4674336..505e793 100644 --- a/Handlers/PlayHandler.py +++ b/Handlers/PlayHandler.py @@ -38,7 +38,7 @@ class PlayHandler(AbstractHandler): # Get the process context for the current guild processManager = self.config.getProcessManager() - processInfo = processManager.getPlayerInfo(self.guild, self.ctx) + processInfo = processManager.getOrCreatePlayerInfo(self.guild, self.ctx) playlist = processInfo.getPlaylist() process = processInfo.getProcess() if not process.is_alive(): # If process has not yet started, start @@ -119,7 +119,7 @@ class PlayHandler(AbstractHandler): await task song = songs[index] if not song.problematic: # If downloaded add to the playlist and send play command - processInfo = processManager.getPlayerInfo(self.guild, self.ctx) + processInfo = processManager.getOrCreatePlayerInfo(self.guild, self.ctx) processLock = processInfo.getLock() acquired = processLock.acquire(timeout=self.config.ACQUIRE_LOCK_TIMEOUT) if acquired: diff --git a/Handlers/PrevHandler.py b/Handlers/PrevHandler.py index 1e25b4c..b1d63ef 100644 --- a/Handlers/PrevHandler.py +++ b/Handlers/PrevHandler.py @@ -13,8 +13,13 @@ class PrevHandler(AbstractHandler): super().__init__(ctx, bot) async def run(self) -> HandlerResponse: + if not self.__user_connected(): + error = ImpossibleMove() + embed = self.embeds.NO_CHANNEL() + return HandlerResponse(self.ctx, embed, error) + processManager = self.config.getProcessManager() - processInfo = processManager.getPlayerInfo(self.guild, self.ctx) + processInfo = processManager.getOrCreatePlayerInfo(self.guild, self.ctx) if not processInfo: embed = self.embeds.NOT_PLAYING() error = BadCommandUsage() @@ -26,11 +31,6 @@ class PrevHandler(AbstractHandler): embed = self.embeds.NOT_PREVIOUS_SONG() return HandlerResponse(self.ctx, embed, error) - if not self.__user_connected(): - error = ImpossibleMove() - embed = self.embeds.NO_CHANNEL() - return HandlerResponse(self.ctx, embed, error) - if playlist.isLoopingAll() or playlist.isLoopingOne(): error = BadCommandUsage() embed = self.embeds.FAIL_DUE_TO_LOOP_ON() diff --git a/Handlers/SkipHandler.py b/Handlers/SkipHandler.py index c5f1e90..0640b85 100644 --- a/Handlers/SkipHandler.py +++ b/Handlers/SkipHandler.py @@ -1,6 +1,6 @@ from discord.ext.commands import Context from Handlers.AbstractHandler import AbstractHandler -from Config.Exceptions import BadCommandUsage +from Config.Exceptions import BadCommandUsage, ImpossibleMove from Handlers.HandlerResponse import HandlerResponse from Music.VulkanBot import VulkanBot from Parallelism.Commands import VCommands, VCommandsType @@ -13,6 +13,11 @@ class SkipHandler(AbstractHandler): super().__init__(ctx, bot) async def run(self) -> HandlerResponse: + if not self.__user_connected(): + error = ImpossibleMove() + embed = self.embeds.NO_CHANNEL() + return HandlerResponse(self.ctx, embed, error) + processManager = self.config.getProcessManager() processInfo = processManager.getRunningPlayerInfo(self.guild) if processInfo: # Verify if there is a running process @@ -31,3 +36,9 @@ class SkipHandler(AbstractHandler): else: embed = self.embeds.NOT_PLAYING() return HandlerResponse(self.ctx, embed) + + def __user_connected(self) -> bool: + if self.author.voice: + return True + else: + return False diff --git a/Parallelism/ProcessManager.py b/Parallelism/ProcessManager.py index 9a1fdde..3136474 100644 --- a/Parallelism/ProcessManager.py +++ b/Parallelism/ProcessManager.py @@ -35,16 +35,9 @@ class ProcessManager(Singleton): def setPlayerInfo(self, guild: Guild, info: ProcessInfo): self.__playersProcess[guild.id] = info - def getPlayerInfo(self, guild: Guild, context: Union[Context, Interaction]) -> ProcessInfo: - """Return the process info for the guild, if not and context is a instance - of discord.Context then create one, else return None""" + def getOrCreatePlayerInfo(self, guild: Guild, context: Union[Context, Interaction]) -> ProcessInfo: + """Return the process info for the guild, the user in context must be connected to a voice_channel""" try: - if isinstance(context, Interaction): - if guild.id not in self.__playersProcess.keys(): - return None - else: - return self.__playersProcess[guild.id] - if guild.id not in self.__playersProcess.keys(): self.__playersProcess[guild.id] = self.__createProcessInfo(guild, context) else: @@ -102,12 +95,16 @@ class ProcessManager(Singleton): return processInfo - def __recreateProcess(self, guild: Guild, context: Context) -> ProcessInfo: + def __recreateProcess(self, guild: Guild, context: Union[Context, Interaction]) -> ProcessInfo: """Create a new process info using previous playlist""" guildID: int = context.guild.id textID: int = context.channel.id - voiceID: int = context.author.voice.channel.id - authorID: int = context.author.id + if isinstance(context, Interaction): + authorID: int = context.user.id + voiceID: int = context.user.voice.channel.id + else: + authorID: int = context.author.id + voiceID: int = context.author.voice.channel.id playlist: Playlist = self.__playersProcess[guildID].getPlaylist() lock = Lock() diff --git a/README.md b/README.md index e7bf7f3..ccc634e 100644 --- a/README.md +++ b/README.md @@ -1,68 +1,48 @@ -# **Vulkan** - -A Music Discord bot, written in Python, that plays *Youtube*, *Spotify* and *Deezer* links. Vulkan was designed so that anyone can fork this project, follow the instructions and use it in their own way, Vulkan can also be configured in Heroku to work 24/7. +
+
+
+
+