mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Fixing error in sending commands to closed process queue
This commit is contained in:
parent
5b61947904
commit
4fd23c56b6
@ -4,6 +4,7 @@ from discord.ext.commands import Context
|
||||
from Music.VulkanBot import VulkanBot
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Parallelism.ProcessInfo import ProcessInfo
|
||||
|
||||
|
||||
class ClearHandler(AbstractHandler):
|
||||
@ -13,7 +14,7 @@ class ClearHandler(AbstractHandler):
|
||||
async def run(self) -> HandlerResponse:
|
||||
# Get the current process of the guild
|
||||
processManager = self.config.getProcessManager()
|
||||
processInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
processInfo: ProcessInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
if processInfo:
|
||||
# Clear the playlist
|
||||
playlist = processInfo.getPlaylist()
|
||||
|
||||
@ -2,6 +2,7 @@ from discord.ext.commands import Context
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Parallelism.Commands import VCommands, VCommandsType
|
||||
from Parallelism.ProcessInfo import ProcessInfo, ProcessStatus
|
||||
from Music.VulkanBot import VulkanBot
|
||||
from typing import Union
|
||||
from discord import Interaction
|
||||
@ -13,8 +14,12 @@ class PauseHandler(AbstractHandler):
|
||||
|
||||
async def run(self) -> HandlerResponse:
|
||||
processManager = self.config.getProcessManager()
|
||||
processInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
processInfo: ProcessInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
if processInfo:
|
||||
if processInfo.getStatus() == ProcessStatus.SLEEPING:
|
||||
embed = self.embeds.NOT_PLAYING()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
# Send Pause command to be execute by player process
|
||||
command = VCommands(VCommandsType.PAUSE, None)
|
||||
queue = processInfo.getQueueToPlayer()
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
from discord.ext.commands import Context
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Parallelism.ProcessInfo import ProcessInfo, ProcessStatus
|
||||
from Parallelism.Commands import VCommands, VCommandsType
|
||||
from Music.VulkanBot import VulkanBot
|
||||
from typing import Union
|
||||
@ -14,8 +15,12 @@ class ResetHandler(AbstractHandler):
|
||||
async def run(self) -> HandlerResponse:
|
||||
# Get the current process of the guild
|
||||
processManager = self.config.getProcessManager()
|
||||
processInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
processInfo: ProcessInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
if processInfo:
|
||||
if processInfo.getStatus() == ProcessStatus.SLEEPING:
|
||||
embed = self.embeds.NOT_PLAYING()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
command = VCommands(VCommandsType.RESET, None)
|
||||
queue = processInfo.getQueueToPlayer()
|
||||
queue.put(command)
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
from discord.ext.commands import Context
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Parallelism.ProcessInfo import ProcessInfo, ProcessStatus
|
||||
from Parallelism.Commands import VCommands, VCommandsType
|
||||
from Music.VulkanBot import VulkanBot
|
||||
from typing import Union
|
||||
@ -13,8 +14,12 @@ class ResumeHandler(AbstractHandler):
|
||||
|
||||
async def run(self) -> HandlerResponse:
|
||||
processManager = self.config.getProcessManager()
|
||||
processInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
processInfo: ProcessInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
if processInfo:
|
||||
if processInfo.getStatus() == ProcessStatus.SLEEPING:
|
||||
embed = self.embeds.NOT_PLAYING()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
# Send Resume command to be execute by player process
|
||||
command = VCommands(VCommandsType.RESUME, None)
|
||||
queue = processInfo.getQueueToPlayer()
|
||||
|
||||
@ -3,6 +3,7 @@ from Handlers.AbstractHandler import AbstractHandler
|
||||
from Config.Exceptions import BadCommandUsage, ImpossibleMove
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Music.VulkanBot import VulkanBot
|
||||
from Parallelism.ProcessInfo import ProcessInfo, ProcessStatus
|
||||
from Parallelism.Commands import VCommands, VCommandsType
|
||||
from typing import Union
|
||||
from discord import Interaction
|
||||
@ -19,8 +20,12 @@ class SkipHandler(AbstractHandler):
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
processManager = self.config.getProcessManager()
|
||||
processInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
processInfo: ProcessInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
if processInfo: # Verify if there is a running process
|
||||
if processInfo.getStatus() == ProcessStatus.SLEEPING:
|
||||
embed = self.embeds.NOT_PLAYING()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
playlist = processInfo.getPlaylist()
|
||||
if playlist.isLoopingOne():
|
||||
embed = self.embeds.ERROR_DUE_LOOP_ONE_ON()
|
||||
|
||||
@ -2,6 +2,7 @@ from discord.ext.commands import Context
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Music.VulkanBot import VulkanBot
|
||||
from Parallelism.ProcessInfo import ProcessInfo, ProcessStatus
|
||||
from Parallelism.Commands import VCommands, VCommandsType
|
||||
from typing import Union
|
||||
from discord import Interaction
|
||||
@ -13,8 +14,12 @@ class StopHandler(AbstractHandler):
|
||||
|
||||
async def run(self) -> HandlerResponse:
|
||||
processManager = self.config.getProcessManager()
|
||||
processInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
processInfo: ProcessInfo = processManager.getRunningPlayerInfo(self.guild)
|
||||
if processInfo:
|
||||
if processInfo.getStatus() == ProcessStatus.SLEEPING:
|
||||
embed = self.embeds.NOT_PLAYING()
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
# Send command to player process stop
|
||||
command = VCommands(VCommandsType.STOP, None)
|
||||
queue = processInfo.getQueueToPlayer()
|
||||
|
||||
@ -247,6 +247,7 @@ class PlayerProcess(Process):
|
||||
if self.__guild.voice_client.is_connected():
|
||||
with self.__playlistLock:
|
||||
self.__playlist.loop_off()
|
||||
self.__playlist.clear()
|
||||
|
||||
# Send a command to the main process put this to sleep
|
||||
sleepCommand = VCommands(VCommandsType.SLEEPING)
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
from enum import Enum
|
||||
from multiprocessing import Process, Queue, Lock
|
||||
from discord import TextChannel
|
||||
from Music.Playlist import Playlist
|
||||
|
||||
|
||||
class ProcessStatus(Enum):
|
||||
RUNNING = 'Running'
|
||||
SLEEPING = 'Sleeping'
|
||||
|
||||
|
||||
class ProcessInfo:
|
||||
"""
|
||||
Class to store the reference to all structures to maintain a player process
|
||||
@ -15,10 +21,17 @@ class ProcessInfo:
|
||||
self.__playlist = playlist
|
||||
self.__lock = lock
|
||||
self.__textChannel = textChannel
|
||||
self.__status = ProcessStatus.RUNNING
|
||||
|
||||
def setProcess(self, newProcess: Process) -> None:
|
||||
self.__process = newProcess
|
||||
|
||||
def getStatus(self) -> ProcessStatus:
|
||||
return self.__status
|
||||
|
||||
def setStatus(self, status: ProcessStatus) -> None:
|
||||
self.__status = status
|
||||
|
||||
def getProcess(self) -> Process:
|
||||
return self.__process
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ from Music.MessagesController import MessagesController
|
||||
from Music.Song import Song
|
||||
from Parallelism.PlayerProcess import PlayerProcess
|
||||
from Music.Playlist import Playlist
|
||||
from Parallelism.ProcessInfo import ProcessInfo
|
||||
from Parallelism.ProcessInfo import ProcessInfo, ProcessStatus
|
||||
from Parallelism.Commands import VCommands, VCommandsType
|
||||
from Music.VulkanBot import VulkanBot
|
||||
|
||||
@ -170,6 +170,8 @@ class ProcessManager(Singleton):
|
||||
queue1.join_thread()
|
||||
queue2.close()
|
||||
queue2.join_thread()
|
||||
# Set the status of this process as sleeping, only the playlist object remains
|
||||
self.__playersProcess[guildID].setStatus(ProcessStatus.SLEEPING)
|
||||
|
||||
async def showNowPlaying(self, guildID: int, song: Song) -> None:
|
||||
messagesController = self.__playersMessages[guildID]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user