mirror of
https://github.com/weyne85/discord_music_bot.git
synced 2025-10-29 16:58:27 +00:00
Modifying clear and skip commands to work with process
This commit is contained in:
@@ -2,6 +2,7 @@ from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Parallelism.ProcessManager import ProcessManager
|
||||
|
||||
|
||||
class ClearController(AbstractController):
|
||||
@@ -9,5 +10,13 @@ class ClearController(AbstractController):
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
self.player.playlist.clear()
|
||||
# Get the current process of the guild
|
||||
processManager = ProcessManager()
|
||||
processContext = processManager.getRunningPlayerContext(self.guild)
|
||||
if processContext:
|
||||
# Clear the playlist
|
||||
playlist = processContext.getPlaylist()
|
||||
with processContext.getLock():
|
||||
playlist.clear()
|
||||
|
||||
return ControllerResponse(self.ctx)
|
||||
|
||||
@@ -3,6 +3,8 @@ from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Exceptions.Exceptions import BadCommandUsage
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Parallelism.ProcessManager import ProcessManager
|
||||
from Parallelism.Commands import VCommands, VCommandsType
|
||||
|
||||
|
||||
class SkipController(AbstractController):
|
||||
@@ -10,14 +12,17 @@ class SkipController(AbstractController):
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
if self.player.playlist.isLoopingOne():
|
||||
embed = self.embeds.ERROR_DUE_LOOP_ONE_ON()
|
||||
error = BadCommandUsage()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
processManager = ProcessManager()
|
||||
processContext = processManager.getRunningPlayerContext(self.guild)
|
||||
if processContext: # Verify if there is a running process
|
||||
playlist = processContext.getPlaylist()
|
||||
if playlist.isLoopingOne():
|
||||
embed = self.embeds.ERROR_DUE_LOOP_ONE_ON()
|
||||
error = BadCommandUsage()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
|
||||
voice = self.controller.get_guild_voice(self.guild)
|
||||
if voice is None:
|
||||
return ControllerResponse(self.ctx)
|
||||
else:
|
||||
voice.stop()
|
||||
return ControllerResponse(self.ctx)
|
||||
# Send a command to the player process to skip the music
|
||||
command = VCommands(VCommandsType.SKIP, None)
|
||||
queue = processContext.getQueue()
|
||||
queue.put(command)
|
||||
return ControllerResponse(self.ctx)
|
||||
|
||||
Reference in New Issue
Block a user