mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Starting using multiprocessing module in Vulkan, now creating a new bot for each guild when played, multiple issues yet
This commit is contained in:
@@ -3,7 +3,7 @@ from typing import List
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client, Guild, ClientUser, Member
|
||||
from Config.Messages import Messages
|
||||
from Controllers.PlayerController import PlayersController
|
||||
from Controllers.PlayersController import PlayersController
|
||||
from Music.Player import Player
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Config.Configs import Configs
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import asyncio
|
||||
from Exceptions.Exceptions import DownloadingError, InvalidInput, VulkanError
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
@@ -8,6 +7,8 @@ from Controllers.ControllerResponse import ControllerResponse
|
||||
from Music.Downloader import Downloader
|
||||
from Music.Searcher import Searcher
|
||||
from Music.Song import Song
|
||||
from Parallelism.ProcessManager import ProcessManager
|
||||
from Parallelism.Commands import VCommands, VCommandsType
|
||||
|
||||
|
||||
class PlayController(AbstractController):
|
||||
@@ -25,13 +26,6 @@ class PlayController(AbstractController):
|
||||
embed = self.embeds.NO_CHANNEL()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
|
||||
if not self.__is_connected():
|
||||
success = await self.__connect()
|
||||
if not success:
|
||||
error = UnknownError()
|
||||
embed = self.embeds.UNKNOWN_ERROR()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
|
||||
try:
|
||||
musics = await self.__searcher.search(track)
|
||||
if musics is None or len(musics) == 0:
|
||||
@@ -63,7 +57,26 @@ class PlayController(AbstractController):
|
||||
embed = self.embeds.SONGS_ADDED(quant)
|
||||
response = ControllerResponse(self.ctx, embed)
|
||||
|
||||
asyncio.create_task(self.player.play(self.ctx))
|
||||
# Get the process context for the current guild
|
||||
manager = ProcessManager(self.bot)
|
||||
processContext = manager.getPlayerContext(self.guild, self.ctx)
|
||||
# Add the downloaded song to the process playlist
|
||||
# All access to shared memory should be protect by acquire the Lock
|
||||
with processContext.getLock():
|
||||
processContext.getPlaylist().add_song(song)
|
||||
|
||||
# If process already started send a command to the player process by queue
|
||||
process = processContext.getProcess()
|
||||
queue = processContext.getQueue()
|
||||
if process.is_alive():
|
||||
command = VCommands(VCommandsType.PLAY)
|
||||
queue.put(command)
|
||||
else:
|
||||
# Start the process
|
||||
command = VCommands(VCommandsType.CONTEXT, self.ctx)
|
||||
queue.put(command)
|
||||
process.start()
|
||||
|
||||
return response
|
||||
|
||||
except Exception as err:
|
||||
@@ -72,6 +85,7 @@ class PlayController(AbstractController):
|
||||
error = err
|
||||
embed = self.embeds.CUSTOM_ERROR(error)
|
||||
else:
|
||||
print(f'DEVELOPER NOTE -> PlayController Error: {err}')
|
||||
error = UnknownError()
|
||||
embed = self.embeds.UNKNOWN_ERROR()
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from multiprocessing import Process
|
||||
from typing import Dict, List, Union
|
||||
from Config.Singleton import Singleton
|
||||
from discord import Guild, Client, VoiceClient, Member
|
||||
@@ -1,8 +1,8 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client, Member
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Controllers.PlayerController import PlayersController
|
||||
from Controllers.PlayersController import PlayersController
|
||||
|
||||
|
||||
class ResetController(AbstractController):
|
||||
|
||||
Reference in New Issue
Block a user