Code style upgrade

This commit is contained in:
Rafael Vargas
2022-07-23 09:52:20 -03:00
parent cd3eddb125
commit 3eab6176c3
36 changed files with 221 additions and 220 deletions

View File

@@ -28,7 +28,7 @@ class TimeoutClock:
class PlayerProcess(Process):
"""Process that will play songs, receive commands by a received Queue"""
"""Process that will play songs, receive commands from the main process by a Queue"""
def __init__(self, playlist: Playlist, lock: Lock, queue: Queue, guildID: int, textID: int, voiceID: int, authorID: int) -> None:
"""
@@ -173,7 +173,9 @@ class PlayerProcess(Process):
await self.__guild.voice_client.disconnect()
def __resume(self) -> None:
pass
if self.__guild.voice_client is not None:
if self.__guild.voice_client.is_paused():
self.__guild.voice_client.resume()
def __skip(self) -> None:
if self.__guild.voice_client is not None:

View File

@@ -2,7 +2,11 @@ from multiprocessing import Process, Queue, Lock
from Music.Playlist import Playlist
class ProcessContext:
class ProcessInfo:
"""
Class to store the reference to all structures to maintain a player process
"""
def __init__(self, process: Process, queue: Queue, playlist: Playlist, lock: Lock) -> None:
self.__process = process
self.__queue = queue

View File

@@ -2,27 +2,31 @@ from multiprocessing import Queue, Lock
from multiprocessing.managers import BaseManager, NamespaceProxy
from typing import Dict
from Config.Singleton import Singleton
from discord import Guild, Client
from discord import Guild
from discord.ext.commands import Context
from Parallelism.PlayerProcess import PlayerProcess
from Music.Playlist import Playlist
from Parallelism.ProcessContext import ProcessContext
from Parallelism.ProcessInfo import ProcessInfo
class ProcessManager(Singleton):
def __init__(self, bot: Client = None) -> None:
if not super().created:
Manager.register('Playlist', Playlist)
self.__manager = Manager()
self.__manager.start()
if bot is not None:
self.__bot: Client = bot
self.__playersProcess: Dict[Guild, ProcessContext] = {}
"""
Manage all running player process, creating and storing them for future calls
Deal with the creation of shared memory
"""
def setPlayerContext(self, guild: Guild, context: ProcessContext):
def __init__(self) -> None:
if not super().created:
VManager.register('Playlist', Playlist)
self.__manager = VManager()
self.__manager.start()
self.__playersProcess: Dict[Guild, ProcessInfo] = {}
def setPlayerContext(self, guild: Guild, context: ProcessInfo):
self.__playersProcess[guild] = context
def getPlayerContext(self, guild: Guild, context: Context) -> ProcessContext:
def getPlayerContext(self, guild: Guild, context: Context) -> ProcessInfo:
"""Return the process info for the guild, if not, create one"""
try:
if guild not in self.__playersProcess.keys():
self.__playersProcess[guild] = self.__createProcess(context)
@@ -34,7 +38,8 @@ class ProcessManager(Singleton):
except Exception as e:
print(f'[Error In GetPlayerContext] -> {e}')
def getRunningPlayerContext(self, guild: Guild) -> ProcessContext:
def getRunningPlayerContext(self, guild: Guild) -> ProcessInfo:
"""Return the process info for the guild, if not, return None"""
if guild not in self.__playersProcess.keys():
return None
@@ -50,13 +55,14 @@ class ProcessManager(Singleton):
lock = Lock()
queue = Queue()
process = PlayerProcess(playlist, lock, queue, guildID, textID, voiceID, authorID)
processContext = ProcessContext(process, queue, playlist, lock)
processContext = ProcessInfo(process, queue, playlist, lock)
return processContext
class Manager(BaseManager):
class VManager(BaseManager):
pass
class ProxyBase(NamespaceProxy):
class VProxy(NamespaceProxy):
_exposed_ = ('__getattribute__', '__setattr__', '__delattr__')