Fixing error

This commit is contained in:
Rafael Vargas
2023-02-19 11:53:58 -03:00
parent 72043c4475
commit 7d53840f87
4 changed files with 17 additions and 15 deletions

View File

@@ -23,7 +23,8 @@ from Messages.Responses.EmbedCogResponse import EmbedCommandResponse
from Music.VulkanBot import VulkanBot from Music.VulkanBot import VulkanBot
from Config.Configs import VConfigs from Config.Configs import VConfigs
from Config.Embeds import VEmbeds from Config.Embeds import VEmbeds
from Parallelism.ProcessManager import ProcessPlayerManager from Parallelism.ProcessPlayerManager import ProcessPlayerManager
from Parallelism.ThreadPlayerManager import ThreadPlayerManager
helper = Helper() helper = Helper()
@@ -38,7 +39,11 @@ class MusicCog(Cog):
def __init__(self, bot: VulkanBot) -> None: def __init__(self, bot: VulkanBot) -> None:
self.__bot: VulkanBot = bot self.__bot: VulkanBot = bot
self.__embeds = VEmbeds() 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']) @command(name="play", help=helper.HELP_PLAY, description=helper.HELP_PLAY_LONG, aliases=['p', 'tocar'])
async def play(self, ctx: Context, *args) -> None: async def play(self, ctx: Context, *args) -> None:

View File

@@ -30,7 +30,6 @@ class ProcessCommandsExecutor:
self.__emojis = VEmojis() self.__emojis = VEmojis()
async def sendNowPlaying(self, playlist: Playlist, channel: TextChannel, song: Song) -> None: async def sendNowPlaying(self, playlist: Playlist, channel: TextChannel, song: Song) -> None:
print('B')
# Get the lock of the playlist # Get the lock of the playlist
if playlist.isLoopingOne(): if playlist.isLoopingOne():
title = self.__messages.ONE_SONG_LOOPING title = self.__messages.ONE_SONG_LOOPING

View File

@@ -143,9 +143,7 @@ class ProcessPlayerManager(Singleton, AbstractPlayersManager):
def __createProcessPlayerInfo(self, guild: Guild, context: Context) -> PlayerProcessInfo: def __createProcessPlayerInfo(self, guild: Guild, context: Context) -> PlayerProcessInfo:
guildID: int = context.guild.id guildID: int = context.guild.id
textID: int = context.channel.id
voiceID: int = context.author.voice.channel.id voiceID: int = context.author.voice.channel.id
authorID: int = context.author.id
playlist: Playlist = self.__manager.Playlist() playlist: Playlist = self.__manager.Playlist()
lock = Lock() lock = Lock()
@@ -270,9 +268,9 @@ class ProcessPlayerManager(Singleton, AbstractPlayersManager):
async def showNowPlaying(self, guildID: int, song: Song) -> None: async def showNowPlaying(self, guildID: int, song: Song) -> None:
commandExecutor = self.__playersCommandsExecutor[guildID] commandExecutor = self.__playersCommandsExecutor[guildID]
processInfo = self.__playersProcess[guildID] processInfo = self.__playersProcess[guildID]
print('A') playlist = processInfo.getPlaylist()
await commandExecutor.sendNowPlaying(processInfo, song) channel = processInfo.getTextChannel()
print('C') await commandExecutor.sendNowPlaying(playlist, channel, song)
class VManager(BaseManager): class VManager(BaseManager):

View File

@@ -11,7 +11,7 @@ from Music.VulkanBot import VulkanBot
from Parallelism.PlayerThread import PlayerThread from Parallelism.PlayerThread import PlayerThread
class PlayerThreadInfo: class ThreadPlayerInfo:
""" """
Class to store the reference to all structures to maintain a player thread 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: def __init__(self, bot: VulkanBot = None) -> None:
if not super().created: if not super().created:
self.__bot = bot 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): def sendCommandToPlayer(self, command: VCommands, guild: Guild, forceCreation: bool = False, context: Union[Context, Interaction] = None):
return super().sendCommandToPlayer(command, guild, forceCreation, context) return super().sendCommandToPlayer(command, guild, forceCreation, context)
@@ -86,14 +86,14 @@ class ThreadPlayerManager(Singleton, AbstractPlayersManager):
newPlayerInfo.getQueueToPlayer().put(playCommand) newPlayerInfo.getQueueToPlayer().put(playCommand)
self.__playersThreads[guild.id] = newPlayerInfo 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(): if guild.id not in self.__playersThreads.keys():
print('Process Info not found') print('Process Info not found')
return None return None
return self.__playersThreads[guild.id] 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 guildID: int = context.guild.id
if isinstance(context, Interaction): if isinstance(context, Interaction):
voiceID: int = context.user.voice.channel.id voiceID: int = context.user.voice.channel.id
@@ -103,12 +103,12 @@ class ThreadPlayerManager(Singleton, AbstractPlayersManager):
playlist = Playlist() playlist = Playlist()
lock = Lock() lock = Lock()
player = PlayerThread(context.guild.name, playlist, lock, guildID, voiceID) 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() player.start()
return playerInfo 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) self.__stopPossiblyRunningProcess(guild)
guildID: int = context.guild.id guildID: int = context.guild.id
@@ -120,7 +120,7 @@ class ThreadPlayerManager(Singleton, AbstractPlayersManager):
playlist = self.__playersThreads[guildID].getPlaylist() playlist = self.__playersThreads[guildID].getPlaylist()
lock = Lock() lock = Lock()
player = PlayerThread(context.guild.name, playlist, lock, guildID, voiceID) 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() player.start()
return playerInfo return playerInfo