diff --git a/DiscordCogs/MusicCog.py b/DiscordCogs/MusicCog.py index 74a27c5..05d5d10 100644 --- a/DiscordCogs/MusicCog.py +++ b/DiscordCogs/MusicCog.py @@ -23,7 +23,8 @@ from Messages.Responses.EmbedCogResponse import EmbedCommandResponse from Music.VulkanBot import VulkanBot from Config.Configs import VConfigs from Config.Embeds import VEmbeds -from Parallelism.ProcessManager import ProcessPlayerManager +from Parallelism.ProcessPlayerManager import ProcessPlayerManager +from Parallelism.ThreadPlayerManager import ThreadPlayerManager helper = Helper() @@ -38,7 +39,11 @@ class MusicCog(Cog): def __init__(self, bot: VulkanBot) -> None: self.__bot: VulkanBot = bot self.__embeds = VEmbeds() - VConfigs().setPlayersManager(ProcessPlayerManager(bot)) + configs = VConfigs() + if configs.SHOULD_AUTO_DISCONNECT_WHEN_ALONE: + configs.setPlayersManager(ProcessPlayerManager(bot)) + else: + configs.setPlayersManager(ThreadPlayerManager(bot)) @command(name="play", help=helper.HELP_PLAY, description=helper.HELP_PLAY_LONG, aliases=['p', 'tocar']) async def play(self, ctx: Context, *args) -> None: diff --git a/Parallelism/ProcessExecutor.py b/Parallelism/ProcessExecutor.py index 1b2c80b..8d8f007 100644 --- a/Parallelism/ProcessExecutor.py +++ b/Parallelism/ProcessExecutor.py @@ -30,7 +30,6 @@ class ProcessCommandsExecutor: self.__emojis = VEmojis() async def sendNowPlaying(self, playlist: Playlist, channel: TextChannel, song: Song) -> None: - print('B') # Get the lock of the playlist if playlist.isLoopingOne(): title = self.__messages.ONE_SONG_LOOPING diff --git a/Parallelism/ProcessManager.py b/Parallelism/ProcessPlayerManager.py similarity index 98% rename from Parallelism/ProcessManager.py rename to Parallelism/ProcessPlayerManager.py index fd88f5b..6f302cc 100644 --- a/Parallelism/ProcessManager.py +++ b/Parallelism/ProcessPlayerManager.py @@ -143,9 +143,7 @@ class ProcessPlayerManager(Singleton, AbstractPlayersManager): def __createProcessPlayerInfo(self, guild: Guild, context: Context) -> PlayerProcessInfo: guildID: int = context.guild.id - textID: int = context.channel.id voiceID: int = context.author.voice.channel.id - authorID: int = context.author.id playlist: Playlist = self.__manager.Playlist() lock = Lock() @@ -270,9 +268,9 @@ class ProcessPlayerManager(Singleton, AbstractPlayersManager): async def showNowPlaying(self, guildID: int, song: Song) -> None: commandExecutor = self.__playersCommandsExecutor[guildID] processInfo = self.__playersProcess[guildID] - print('A') - await commandExecutor.sendNowPlaying(processInfo, song) - print('C') + playlist = processInfo.getPlaylist() + channel = processInfo.getTextChannel() + await commandExecutor.sendNowPlaying(playlist, channel, song) class VManager(BaseManager): diff --git a/Parallelism/ThreadPlayerManager.py b/Parallelism/ThreadPlayerManager.py index b23a6a2..aaabec3 100644 --- a/Parallelism/ThreadPlayerManager.py +++ b/Parallelism/ThreadPlayerManager.py @@ -11,7 +11,7 @@ from Music.VulkanBot import VulkanBot from Parallelism.PlayerThread import PlayerThread -class PlayerThreadInfo: +class ThreadPlayerInfo: """ Class to store the reference to all structures to maintain a player thread """ @@ -43,7 +43,7 @@ class ThreadPlayerManager(Singleton, AbstractPlayersManager): def __init__(self, bot: VulkanBot = None) -> None: if not super().created: self.__bot = bot - self.__playersThreads: Dict[int, PlayerThreadInfo] = {} + self.__playersThreads: Dict[int, ThreadPlayerInfo] = {} def sendCommandToPlayer(self, command: VCommands, guild: Guild, forceCreation: bool = False, context: Union[Context, Interaction] = None): return super().sendCommandToPlayer(command, guild, forceCreation, context) @@ -86,14 +86,14 @@ class ThreadPlayerManager(Singleton, AbstractPlayersManager): newPlayerInfo.getQueueToPlayer().put(playCommand) self.__playersThreads[guild.id] = newPlayerInfo - def __getRunningPlayerInfo(self, guild: Guild) -> PlayerThreadInfo: + def __getRunningPlayerInfo(self, guild: Guild) -> ThreadPlayerInfo: if guild.id not in self.__playersThreads.keys(): print('Process Info not found') return None return self.__playersThreads[guild.id] - def __createPlayerThreadInfo(self, context: Union[Context, Interaction]) -> PlayerThreadInfo: + def __createPlayerThreadInfo(self, context: Union[Context, Interaction]) -> ThreadPlayerInfo: guildID: int = context.guild.id if isinstance(context, Interaction): voiceID: int = context.user.voice.channel.id @@ -103,12 +103,12 @@ class ThreadPlayerManager(Singleton, AbstractPlayersManager): playlist = Playlist() lock = Lock() player = PlayerThread(context.guild.name, playlist, lock, guildID, voiceID) - playerInfo = PlayerThreadInfo(player, playlist, lock, context.channel) + playerInfo = ThreadPlayerInfo(player, playlist, lock, context.channel) player.start() return playerInfo - def __recreateThread(self, guild: Guild, context: Union[Context, Interaction]) -> PlayerThreadInfo: + def __recreateThread(self, guild: Guild, context: Union[Context, Interaction]) -> ThreadPlayerInfo: self.__stopPossiblyRunningProcess(guild) guildID: int = context.guild.id @@ -120,7 +120,7 @@ class ThreadPlayerManager(Singleton, AbstractPlayersManager): playlist = self.__playersThreads[guildID].getPlaylist() lock = Lock() player = PlayerThread(context.guild.name, playlist, lock, guildID, voiceID) - playerInfo = PlayerThreadInfo(player, playlist, lock, context.channel) + playerInfo = ThreadPlayerInfo(player, playlist, lock, context.channel) player.start() return playerInfo