mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Fixing errors when closing the player info and trying to access it again
This commit is contained in:
@@ -13,7 +13,7 @@ class AbstractPlayersManager(ABC):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def sendCommandToPlayer(self, command: VCommands, guild: Guild, forceCreation: bool = False, context: Union[Context, Interaction] = None):
|
||||
async def sendCommandToPlayer(self, command: VCommands, guild: Guild, context: Union[Context, Interaction], forceCreation: bool = False):
|
||||
"""If the forceCreation boolean is True, then the context must be provided for the Player to be created"""
|
||||
pass
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ class ProcessPlayerManager(Singleton, AbstractPlayersManager):
|
||||
self.__playersListeners: Dict[int, Tuple[Thread, bool]] = {}
|
||||
self.__playersCommandsExecutor: Dict[int, ProcessCommandsExecutor] = {}
|
||||
|
||||
async def sendCommandToPlayer(self, command: VCommands, guild: Guild, forceCreation: bool = False, context: Union[Context, Interaction] = None):
|
||||
async def sendCommandToPlayer(self, command: VCommands, guild: Guild, context: Union[Context, Interaction], forceCreation: bool = False):
|
||||
if forceCreation:
|
||||
processInfo = self.createPlayerForGuild(guild, context)
|
||||
else:
|
||||
@@ -89,6 +89,10 @@ class ProcessPlayerManager(Singleton, AbstractPlayersManager):
|
||||
if processInfo == None:
|
||||
return
|
||||
|
||||
if processInfo.getStatus() == ProcessStatus.SLEEPING:
|
||||
self.resetPlayer(guild, context)
|
||||
processInfo = self.__getRunningPlayerInfo(guild)
|
||||
|
||||
queue = processInfo.getQueueToPlayer()
|
||||
self.__putCommandInQueue(queue, command)
|
||||
|
||||
@@ -172,24 +176,19 @@ class ProcessPlayerManager(Singleton, AbstractPlayersManager):
|
||||
process = playerProcess.getProcess()
|
||||
process.close()
|
||||
process.kill()
|
||||
playerProcess.getQueueToMain().close()
|
||||
playerProcess.getQueueToMain().join_thread()
|
||||
playerProcess.getQueueToPlayer().close()
|
||||
playerProcess.getQueueToPlayer().join_thread()
|
||||
except ValueError:
|
||||
pass
|
||||
except Exception as e:
|
||||
print(f'[ERROR STOPPING PROCESS] -> {e}')
|
||||
print(f'[WARNINGS] -> {e}')
|
||||
|
||||
def __recreateProcess(self, guild: Guild, context: Union[Context, Interaction]) -> PlayerProcessInfo:
|
||||
"""Create a new process info using previous playlist"""
|
||||
self.__stopPossiblyRunningProcess(guild)
|
||||
|
||||
guildID: int = context.guild.id
|
||||
textID: int = context.channel.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()
|
||||
@@ -197,7 +196,7 @@ class ProcessPlayerManager(Singleton, AbstractPlayersManager):
|
||||
queueToListen = Queue()
|
||||
queueToSend = Queue()
|
||||
process = ProcessPlayer(context.guild.name, playlist, lock, queueToSend,
|
||||
queueToListen, guildID, textID, voiceID, authorID)
|
||||
queueToListen, guildID, voiceID)
|
||||
processInfo = PlayerProcessInfo(process, queueToSend, queueToListen,
|
||||
playlist, lock, context.channel)
|
||||
|
||||
|
||||
@@ -342,11 +342,13 @@ class ThreadPlayer(Thread):
|
||||
else:
|
||||
break
|
||||
|
||||
if self.__voiceClient is not None:
|
||||
try:
|
||||
await self.__voiceClient.disconnect(force=True)
|
||||
except Exception as e:
|
||||
print(f'[THREAD PLAYER -> ERROR FORCING DISCONNECT] -> {e}')
|
||||
try:
|
||||
voiceClient = self.__guild.voice_client
|
||||
if voiceClient is not None:
|
||||
await voiceClient.disconnect(force=True)
|
||||
except Exception as e:
|
||||
print(f'[THREAD PLAYER -> ERROR FORCING DISCONNECT] -> {e}')
|
||||
|
||||
self.__voiceClient = await self.__voiceChannel.connect(reconnect=True, timeout=None)
|
||||
return True
|
||||
except Exception as e:
|
||||
|
||||
@@ -46,7 +46,7 @@ class ThreadPlayerManager(Singleton, AbstractPlayersManager):
|
||||
self.__bot = bot
|
||||
self.__playersThreads: Dict[int, ThreadPlayerInfo] = {}
|
||||
|
||||
async def sendCommandToPlayer(self, command: VCommands, guild: Guild, forceCreation: bool = False, context: Union[Context, Interaction] = None):
|
||||
async def sendCommandToPlayer(self, command: VCommands, guild: Guild, context: Union[Context, Interaction], forceCreation: bool = False):
|
||||
playerInfo = self.__playersThreads[guild.id]
|
||||
player = playerInfo.getPlayer()
|
||||
if player is None and forceCreation:
|
||||
|
||||
Reference in New Issue
Block a user