mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Upgrading messages sended mananger and refactoring Buttons logic
This commit is contained in:
79
Parallelism/ProcessExecutor.py
Normal file
79
Parallelism/ProcessExecutor.py
Normal file
@@ -0,0 +1,79 @@
|
||||
from typing import List
|
||||
from discord import Button, TextChannel
|
||||
from discord.ui import View
|
||||
from Config.Emojis import VEmojis
|
||||
from Messages.MessagesCategory import MessagesCategory
|
||||
from Music.VulkanBot import VulkanBot
|
||||
from Parallelism.ProcessInfo import ProcessInfo
|
||||
from Config.Messages import Messages
|
||||
from Music.Song import Song
|
||||
from Config.Embeds import VEmbeds
|
||||
from UI.Buttons.HandlerButton import HandlerButton
|
||||
from UI.Views.BasicView import BasicView
|
||||
from Messages.MessagesManager import MessagesManager
|
||||
from Handlers.PrevHandler import PrevHandler
|
||||
from Handlers.PauseHandler import PauseHandler
|
||||
from Handlers.SkipHandler import SkipHandler
|
||||
from Handlers.StopHandler import StopHandler
|
||||
from Handlers.ResumeHandler import ResumeHandler
|
||||
from Handlers.LoopHandler import LoopHandler
|
||||
from Handlers.QueueHandler import QueueHandler
|
||||
|
||||
|
||||
class ProcessCommandsExecutor:
|
||||
def __init__(self, bot: VulkanBot, guildID: int) -> None:
|
||||
self.__bot = bot
|
||||
self.__guildID = guildID
|
||||
self.__messagesManager = MessagesManager()
|
||||
self.__messages = Messages()
|
||||
self.__embeds = VEmbeds()
|
||||
self.__emojis = VEmojis()
|
||||
|
||||
async def sendNowPlaying(self, processInfo: ProcessInfo, song: Song) -> None:
|
||||
# Get the lock of the playlist
|
||||
playlist = processInfo.getPlaylist()
|
||||
if playlist.isLoopingOne():
|
||||
title = self.__messages.ONE_SONG_LOOPING
|
||||
else:
|
||||
title = self.__messages.SONG_PLAYING
|
||||
|
||||
# Create View and Embed
|
||||
embed = self.__embeds.SONG_INFO(song.info, title)
|
||||
channel = processInfo.getTextChannel()
|
||||
view = self.__getPlayerView(channel)
|
||||
# Send Message and add to the MessagesManager
|
||||
message = await channel.send(embed=embed, view=view)
|
||||
await self.__messagesManager.addMessageAndClearPrevious(self.__guildID, MessagesCategory.NOW_PLAYING, message)
|
||||
|
||||
# Set in the view the message witch contains the view
|
||||
view.set_message(message=message)
|
||||
|
||||
def __getPlayerView(self, channel: TextChannel) -> View:
|
||||
buttons = self.__getPlayerButtons(channel)
|
||||
view = BasicView(self.__bot, buttons)
|
||||
return view
|
||||
|
||||
def __getPlayerButtons(self, textChannel: TextChannel) -> List[Button]:
|
||||
"""Create the Buttons to be inserted in the Player View"""
|
||||
buttons: List[Button] = []
|
||||
|
||||
buttons.append(HandlerButton(self.__bot, PrevHandler, self.__emojis.BACK,
|
||||
textChannel, self.__guildID, MessagesCategory.PLAYER, "Back"))
|
||||
buttons.append(HandlerButton(self.__bot, PauseHandler, self.__emojis.PAUSE,
|
||||
textChannel, self.__guildID, MessagesCategory.PLAYER, "Pause"))
|
||||
buttons.append(HandlerButton(self.__bot, ResumeHandler, self.__emojis.PLAY,
|
||||
textChannel, self.__guildID, MessagesCategory.PLAYER, "Play"))
|
||||
buttons.append(HandlerButton(self.__bot, StopHandler, self.__emojis.STOP,
|
||||
textChannel, self.__guildID, MessagesCategory.PLAYER, "Stop"))
|
||||
buttons.append(HandlerButton(self.__bot, SkipHandler, self.__emojis.SKIP,
|
||||
textChannel, self.__guildID, MessagesCategory.PLAYER, "Skip"))
|
||||
buttons.append(HandlerButton(self.__bot, QueueHandler, self.__emojis.QUEUE,
|
||||
textChannel, self.__guildID, MessagesCategory.QUEUE, "Songs"))
|
||||
buttons.append(HandlerButton(self.__bot, LoopHandler, self.__emojis.LOOP_ONE,
|
||||
textChannel, self.__guildID, MessagesCategory.LOOP, "Loop One", 'One'))
|
||||
buttons.append(HandlerButton(self.__bot, LoopHandler, self.__emojis.LOOP_OFF,
|
||||
textChannel, self.__guildID, MessagesCategory.LOOP, "Loop Off", 'Off'))
|
||||
buttons.append(HandlerButton(self.__bot, LoopHandler, self.__emojis.LOOP_ALL,
|
||||
textChannel, self.__guildID, MessagesCategory.LOOP, "Loop All", 'All'))
|
||||
|
||||
return buttons
|
||||
@@ -7,7 +7,7 @@ from typing import Dict, Tuple, Union
|
||||
from Config.Singleton import Singleton
|
||||
from discord import Guild, Interaction
|
||||
from discord.ext.commands import Context
|
||||
from Music.MessagesController import MessagesController
|
||||
from Parallelism.ProcessExecutor import ProcessCommandsExecutor
|
||||
from Music.Song import Song
|
||||
from Parallelism.PlayerProcess import PlayerProcess
|
||||
from Music.Playlist import Playlist
|
||||
@@ -30,7 +30,7 @@ class ProcessManager(Singleton):
|
||||
self.__manager.start()
|
||||
self.__playersProcess: Dict[Guild, ProcessInfo] = {}
|
||||
self.__playersListeners: Dict[Guild, Tuple[Thread, bool]] = {}
|
||||
self.__playersMessages: Dict[Guild, MessagesController] = {}
|
||||
self.__playersCommandsExecutor: Dict[Guild, ProcessCommandsExecutor] = {}
|
||||
|
||||
def setPlayerInfo(self, guild: Guild, info: ProcessInfo):
|
||||
self.__playersProcess[guild.id] = info
|
||||
@@ -91,7 +91,7 @@ class ProcessManager(Singleton):
|
||||
thread.start()
|
||||
|
||||
# Create a Message Controller for this player
|
||||
self.__playersMessages[guildID] = MessagesController(self.__bot)
|
||||
self.__playersCommandsExecutor[guildID] = ProcessCommandsExecutor(self.__bot, guildID)
|
||||
|
||||
return processInfo
|
||||
|
||||
@@ -157,7 +157,7 @@ class ProcessManager(Singleton):
|
||||
def __terminateProcess(self, guildID: int) -> None:
|
||||
# Delete all structures associated with the Player
|
||||
del self.__playersProcess[guildID]
|
||||
del self.__playersMessages[guildID]
|
||||
del self.__playersCommandsExecutor[guildID]
|
||||
threadListening = self.__playersListeners[guildID]
|
||||
threadListening._stop()
|
||||
del self.__playersListeners[guildID]
|
||||
@@ -174,9 +174,9 @@ class ProcessManager(Singleton):
|
||||
self.__playersProcess[guildID].setStatus(ProcessStatus.SLEEPING)
|
||||
|
||||
async def showNowPlaying(self, guildID: int, song: Song) -> None:
|
||||
messagesController = self.__playersMessages[guildID]
|
||||
commandExecutor = self.__playersCommandsExecutor[guildID]
|
||||
processInfo = self.__playersProcess[guildID]
|
||||
await messagesController.sendNowPlaying(processInfo, song)
|
||||
await commandExecutor.sendNowPlaying(processInfo, song)
|
||||
|
||||
|
||||
class VManager(BaseManager):
|
||||
|
||||
Reference in New Issue
Block a user