From 5cdc4e9a538b469a9ab55f25de8cc4ba6cd3be04 Mon Sep 17 00:00:00 2001 From: Rafael Vargas Date: Tue, 24 Jan 2023 19:42:57 -0300 Subject: [PATCH] Fixing error in starting playing songs that the Player lost reference to the current playing song --- Handlers/PlayHandler.py | 3 ++- Parallelism/PlayerProcess.py | 7 ++++--- Parallelism/ProcessManager.py | 1 + requirements.txt | Bin 254 -> 1202 bytes 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Handlers/PlayHandler.py b/Handlers/PlayHandler.py index 218db30..3463010 100644 --- a/Handlers/PlayHandler.py +++ b/Handlers/PlayHandler.py @@ -14,6 +14,7 @@ from Parallelism.Commands import VCommands, VCommandsType from Music.VulkanBot import VulkanBot from typing import Union from discord import Interaction +from Music.Playlist import Playlist class PlayHandler(AbstractHandler): @@ -38,7 +39,7 @@ class PlayHandler(AbstractHandler): # Get the process context for the current guild processManager = self.config.getProcessManager() processInfo = processManager.getOrCreatePlayerInfo(self.guild, self.ctx) - playlist = processInfo.getPlaylist() + playlist: Playlist = processInfo.getPlaylist() process = processInfo.getProcess() if not process.is_alive(): # If process has not yet started, start process.start() diff --git a/Parallelism/PlayerProcess.py b/Parallelism/PlayerProcess.py index f20611e..836ddd9 100644 --- a/Parallelism/PlayerProcess.py +++ b/Parallelism/PlayerProcess.py @@ -119,6 +119,7 @@ class PlayerProcess(Process): if song is not None: self.__loop.create_task(self.__playSong(song), name=f'Song {song.identifier}') + self.__playing = True async def __playSong(self, song: Song) -> None: """Function that will trigger the player to play the song""" @@ -139,7 +140,7 @@ class PlayerProcess(Process): return self.__playing = True - self.__playingSong = song + self.__songPlaying = song player = FFmpegPCMAudio(song.source, **self.FFMPEG_OPTIONS) self.__guild.voice_client.play(player, after=lambda e: self.__playNext(e)) @@ -168,7 +169,7 @@ class PlayerProcess(Process): self.__loop.create_task(self.__playSong(song), name=f'Song {song.identifier}') else: self.__playlist.loop_off() - self.__playingSong = None + self.__songPlaying = None self.__playing = False # Send a command to the main process put this one to sleep sleepCommand = VCommands(VCommandsType.SLEEPING) @@ -253,7 +254,7 @@ class PlayerProcess(Process): sleepCommand = VCommands(VCommandsType.SLEEPING) self.__queueSend.put(sleepCommand) self.__guild.voice_client.stop() - self.__playingSong = None + self.__songPlaying = None await self.__guild.voice_client.disconnect() self.__semStopPlaying.release() diff --git a/Parallelism/ProcessManager.py b/Parallelism/ProcessManager.py index ccfc667..d0792d1 100644 --- a/Parallelism/ProcessManager.py +++ b/Parallelism/ProcessManager.py @@ -65,6 +65,7 @@ class ProcessManager(Singleton): def getRunningPlayerInfo(self, guild: Guild) -> ProcessInfo: """Return the process info for the guild, if not, return None""" if guild.id not in self.__playersProcess.keys(): + print('Process Info not found') return None return self.__playersProcess[guild.id] diff --git a/requirements.txt b/requirements.txt index 476b8f1e95fa060577fe907d5354d3dacaa7ac01..d0e0801f637641ea0b3679d904ba4748254675f8 100644 GIT binary patch literal 1202 zcmY+E!A`;9Xl)^a53kO*+aEBb2Hn}&nc1zsKXa?B zv3J|))7qmx6T7i{JySicYP~8WyS6I}Y_E>BZS`C2__1)go`mV`sOr)(^;Nd9QXG4I zha1k3lwU;P3oI!&1r3#Zrjtzr#?F>b=)9<Fg*nTDeDx(Xyx8eNp^9AsrNFm=uaNVU^BSmuE&1ep^L6oyjyMV zP3jJs!i}JXOFDarPV&Wlp~OI*um delta 86 zcmdnQ`HxZi|Gxr;N(NnqWQKf(B8C)(XofN%D-+01Wr$_41wtbRJqVusmC0~&1G5;r cA%i7Q%wTdSi!>)l7Q{20e3jX9@-#*b0HV|r!vFvP