mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Code style upgrade
This commit is contained in:
parent
cd3eddb125
commit
3eab6176c3
@ -1,5 +1,5 @@
|
||||
from discord import Client, Game, Status, Embed
|
||||
from discord.ext.commands.errors import CommandNotFound, MissingRequiredArgument, UserInputError
|
||||
from discord.ext.commands.errors import CommandNotFound, MissingRequiredArgument
|
||||
from discord.ext import commands
|
||||
from Config.Configs import Configs
|
||||
from Config.Helper import Helper
|
||||
@ -10,7 +10,8 @@ from Views.Embeds import Embeds
|
||||
helper = Helper()
|
||||
|
||||
|
||||
class Control(commands.Cog):
|
||||
class ControlCog(commands.Cog):
|
||||
"""Class to handle discord events"""
|
||||
|
||||
def __init__(self, bot: Client):
|
||||
self.__bot = bot
|
||||
@ -99,10 +100,9 @@ class Control(commands.Cog):
|
||||
embedhelp.set_thumbnail(url=self.__bot.user.avatar_url)
|
||||
await ctx.send(embed=embedhelp)
|
||||
|
||||
@commands.command(name='invite', help=helper.HELP_INVITE, description=helper.HELP_INVITE_LONG)
|
||||
@commands.command(name='invite', help=helper.HELP_INVITE, description=helper.HELP_INVITE_LONG, aliases=['convite', 'inv', 'convidar'])
|
||||
async def invite_bot(self, ctx):
|
||||
invite_url = self.__config.INVITE_URL.format(self.__bot.user.id)
|
||||
print(invite_url)
|
||||
txt = self.__config.INVITE_MESSAGE.format(invite_url, invite_url)
|
||||
|
||||
embed = Embed(
|
||||
@ -115,4 +115,4 @@ class Control(commands.Cog):
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Control(bot))
|
||||
bot.add_cog(ControlCog(bot))
|
||||
@ -2,23 +2,23 @@ from discord import Guild, Client
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context
|
||||
from Config.Helper import Helper
|
||||
from Controllers.ClearController import ClearController
|
||||
from Controllers.MoveController import MoveController
|
||||
from Controllers.NowPlayingController import NowPlayingController
|
||||
from Controllers.PlayController import PlayController
|
||||
from Controllers.PlayersController import PlayersController
|
||||
from Controllers.PrevController import PrevController
|
||||
from Controllers.RemoveController import RemoveController
|
||||
from Controllers.ResetController import ResetController
|
||||
from Controllers.ShuffleController import ShuffleController
|
||||
from Handlers.ClearHandler import ClearHandler
|
||||
from Handlers.MoveHandler import MoveHandler
|
||||
from Handlers.NowPlayingHandler import NowPlayingHandler
|
||||
from Handlers.PlayHandler import PlayHandler
|
||||
from Handlers.PlayersController import PlayersController
|
||||
from Handlers.PrevHandler import PrevHandler
|
||||
from Handlers.RemoveHandler import RemoveHandler
|
||||
from Handlers.ResetHandler import ResetHandler
|
||||
from Handlers.ShuffleHandler import ShuffleHandler
|
||||
from Utils.Cleaner import Cleaner
|
||||
from Controllers.SkipController import SkipController
|
||||
from Controllers.PauseController import PauseController
|
||||
from Controllers.StopController import StopController
|
||||
from Controllers.ResumeController import ResumeController
|
||||
from Controllers.HistoryController import HistoryController
|
||||
from Controllers.QueueController import QueueController
|
||||
from Controllers.LoopController import LoopController
|
||||
from Handlers.SkipHandler import SkipHandler
|
||||
from Handlers.PauseHandler import PauseHandler
|
||||
from Handlers.StopHandler import StopHandler
|
||||
from Handlers.ResumeHandler import ResumeHandler
|
||||
from Handlers.HistoryHandler import HistoryHandler
|
||||
from Handlers.QueueHandler import QueueHandler
|
||||
from Handlers.LoopHandler import LoopHandler
|
||||
from Views.EmoteView import EmoteView
|
||||
from Views.EmbedView import EmbedView
|
||||
from Parallelism.ProcessManager import ProcessManager
|
||||
@ -26,10 +26,15 @@ from Parallelism.ProcessManager import ProcessManager
|
||||
helper = Helper()
|
||||
|
||||
|
||||
class Music(commands.Cog):
|
||||
class MusicCog(commands.Cog):
|
||||
"""
|
||||
Class to listen to Music commands
|
||||
It'll listen for commands from discord, when triggered will create a specific Handler for the command
|
||||
Execute the handler and then create a specific View to be showed in Discord
|
||||
"""
|
||||
|
||||
def __init__(self, bot) -> None:
|
||||
self.__bot: Client = bot
|
||||
self.__processManager = ProcessManager(bot)
|
||||
self.__cleaner = Cleaner(self.__bot)
|
||||
self.__controller = PlayersController(self.__bot)
|
||||
|
||||
@ -43,7 +48,7 @@ class Music(commands.Cog):
|
||||
|
||||
@commands.command(name="play", help=helper.HELP_PLAY, description=helper.HELP_PLAY_LONG, aliases=['p', 'tocar'])
|
||||
async def play(self, ctx: Context, *args) -> None:
|
||||
controller = PlayController(ctx, self.__bot)
|
||||
controller = PlayHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run(args)
|
||||
if response is not None:
|
||||
@ -52,17 +57,17 @@ class Music(commands.Cog):
|
||||
await view1.run()
|
||||
await view2.run()
|
||||
|
||||
@commands.command(name="queue", help=helper.HELP_QUEUE, description=helper.HELP_QUEUE_LONG, aliases=['q', 'fila'])
|
||||
@commands.command(name="queue", help=helper.HELP_QUEUE, description=helper.HELP_QUEUE_LONG, aliases=['q', 'fila', 'musicas'])
|
||||
async def queue(self, ctx: Context) -> None:
|
||||
controller = QueueController(ctx, self.__bot)
|
||||
controller = QueueHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run()
|
||||
view2 = EmbedView(response)
|
||||
await view2.run()
|
||||
|
||||
@commands.command(name="skip", help=helper.HELP_SKIP, description=helper.HELP_SKIP_LONG, aliases=['s', 'pular'])
|
||||
@commands.command(name="skip", help=helper.HELP_SKIP, description=helper.HELP_SKIP_LONG, aliases=['s', 'pular', 'next'])
|
||||
async def skip(self, ctx: Context) -> None:
|
||||
controller = SkipController(ctx, self.__bot)
|
||||
controller = SkipHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run()
|
||||
if response.success:
|
||||
@ -74,7 +79,7 @@ class Music(commands.Cog):
|
||||
|
||||
@commands.command(name='stop', help=helper.HELP_STOP, description=helper.HELP_STOP_LONG, aliases=['parar'])
|
||||
async def stop(self, ctx: Context) -> None:
|
||||
controller = StopController(ctx, self.__bot)
|
||||
controller = StopHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run()
|
||||
if response.success:
|
||||
@ -84,9 +89,9 @@ class Music(commands.Cog):
|
||||
|
||||
await view.run()
|
||||
|
||||
@commands.command(name='pause', help=helper.HELP_PAUSE, description=helper.HELP_PAUSE_LONG, aliases=['pausar'])
|
||||
@commands.command(name='pause', help=helper.HELP_PAUSE, description=helper.HELP_PAUSE_LONG, aliases=['pausar', 'pare'])
|
||||
async def pause(self, ctx: Context) -> None:
|
||||
controller = PauseController(ctx, self.__bot)
|
||||
controller = PauseHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run()
|
||||
view1 = EmoteView(response)
|
||||
@ -94,9 +99,9 @@ class Music(commands.Cog):
|
||||
await view1.run()
|
||||
await view2.run()
|
||||
|
||||
@commands.command(name='resume', help=helper.HELP_RESUME, description=helper.HELP_RESUME_LONG, aliases=['soltar'])
|
||||
@commands.command(name='resume', help=helper.HELP_RESUME, description=helper.HELP_RESUME_LONG, aliases=['soltar', 'despausar'])
|
||||
async def resume(self, ctx: Context) -> None:
|
||||
controller = ResumeController(ctx, self.__bot)
|
||||
controller = ResumeHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run()
|
||||
view1 = EmoteView(response)
|
||||
@ -104,9 +109,9 @@ class Music(commands.Cog):
|
||||
await view1.run()
|
||||
await view2.run()
|
||||
|
||||
@commands.command(name='prev', help=helper.HELP_PREV, description=helper.HELP_PREV_LONG, aliases=['anterior'])
|
||||
@commands.command(name='prev', help=helper.HELP_PREV, description=helper.HELP_PREV_LONG, aliases=['anterior', 'return', 'previous'])
|
||||
async def prev(self, ctx: Context) -> None:
|
||||
controller = PrevController(ctx, self.__bot)
|
||||
controller = PrevHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run()
|
||||
if response is not None:
|
||||
@ -115,9 +120,9 @@ class Music(commands.Cog):
|
||||
await view1.run()
|
||||
await view2.run()
|
||||
|
||||
@commands.command(name='history', help=helper.HELP_HISTORY, description=helper.HELP_HISTORY_LONG, aliases=['historico'])
|
||||
@commands.command(name='history', help=helper.HELP_HISTORY, description=helper.HELP_HISTORY_LONG, aliases=['historico', 'h'])
|
||||
async def history(self, ctx: Context) -> None:
|
||||
controller = HistoryController(ctx, self.__bot)
|
||||
controller = HistoryHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run()
|
||||
view1 = EmbedView(response)
|
||||
@ -127,7 +132,7 @@ class Music(commands.Cog):
|
||||
|
||||
@commands.command(name='loop', help=helper.HELP_LOOP, description=helper.HELP_LOOP_LONG, aliases=['l', 'repeat'])
|
||||
async def loop(self, ctx: Context, args='') -> None:
|
||||
controller = LoopController(ctx, self.__bot)
|
||||
controller = LoopHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run(args)
|
||||
view1 = EmoteView(response)
|
||||
@ -137,15 +142,15 @@ class Music(commands.Cog):
|
||||
|
||||
@commands.command(name='clear', help=helper.HELP_CLEAR, description=helper.HELP_CLEAR_LONG, aliases=['c', 'limpar'])
|
||||
async def clear(self, ctx: Context) -> None:
|
||||
controller = ClearController(ctx, self.__bot)
|
||||
controller = ClearHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run()
|
||||
view = EmoteView(response)
|
||||
await view.run()
|
||||
|
||||
@commands.command(name='np', help=helper.HELP_NP, description=helper.HELP_NP_LONG, aliases=['playing', 'now'])
|
||||
@commands.command(name='np', help=helper.HELP_NP, description=helper.HELP_NP_LONG, aliases=['playing', 'now', 'this'])
|
||||
async def now_playing(self, ctx: Context) -> None:
|
||||
controller = NowPlayingController(ctx, self.__bot)
|
||||
controller = NowPlayingHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run()
|
||||
view1 = EmbedView(response)
|
||||
@ -155,7 +160,7 @@ class Music(commands.Cog):
|
||||
|
||||
@commands.command(name='shuffle', help=helper.HELP_SHUFFLE, description=helper.HELP_SHUFFLE_LONG, aliases=['aleatorio'])
|
||||
async def shuffle(self, ctx: Context) -> None:
|
||||
controller = ShuffleController(ctx, self.__bot)
|
||||
controller = ShuffleHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run()
|
||||
view1 = EmbedView(response)
|
||||
@ -165,7 +170,7 @@ class Music(commands.Cog):
|
||||
|
||||
@commands.command(name='move', help=helper.HELP_MOVE, description=helper.HELP_MOVE_LONG, aliases=['m', 'mover'])
|
||||
async def move(self, ctx: Context, pos1, pos2='1') -> None:
|
||||
controller = MoveController(ctx, self.__bot)
|
||||
controller = MoveHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run(pos1, pos2)
|
||||
view1 = EmbedView(response)
|
||||
@ -175,7 +180,7 @@ class Music(commands.Cog):
|
||||
|
||||
@commands.command(name='remove', help=helper.HELP_REMOVE, description=helper.HELP_REMOVE_LONG, aliases=['remover'])
|
||||
async def remove(self, ctx: Context, position) -> None:
|
||||
controller = RemoveController(ctx, self.__bot)
|
||||
controller = RemoveHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run(position)
|
||||
view1 = EmbedView(response)
|
||||
@ -185,7 +190,7 @@ class Music(commands.Cog):
|
||||
|
||||
@commands.command(name='reset', help=helper.HELP_RESET, description=helper.HELP_RESET_LONG, aliases=['resetar'])
|
||||
async def reset(self, ctx: Context) -> None:
|
||||
controller = ResetController(ctx, self.__bot)
|
||||
controller = ResetHandler(ctx, self.__bot)
|
||||
|
||||
response = await controller.run()
|
||||
view1 = EmbedView(response)
|
||||
@ -195,4 +200,4 @@ class Music(commands.Cog):
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Music(bot))
|
||||
bot.add_cog(MusicCog(bot))
|
||||
@ -1,22 +1,19 @@
|
||||
from random import randint, random
|
||||
from discord import Client
|
||||
from discord.ext.commands import Context, command, Cog
|
||||
from Config.Colors import Colors
|
||||
from Config.Configs import Configs
|
||||
from Config.Helper import Helper
|
||||
from Views.Embeds import Embeds
|
||||
|
||||
helper = Helper()
|
||||
|
||||
|
||||
class Random(Cog):
|
||||
class RandomCog(Cog):
|
||||
"""Class to listen to commands of type Random"""
|
||||
|
||||
def __init__(self, bot: Client):
|
||||
self.__config = Configs()
|
||||
self.__colors = Colors()
|
||||
self.__embeds = Embeds()
|
||||
|
||||
@command(name='random', help=helper.HELP_RANDOM, description=helper.HELP_RANDOM_LONG)
|
||||
@command(name='random', help=helper.HELP_RANDOM, description=helper.HELP_RANDOM_LONG, aliases=['rand', 'aleatorio'])
|
||||
async def random(self, ctx: Context, arg: str) -> None:
|
||||
try:
|
||||
arg = int(arg)
|
||||
@ -37,7 +34,7 @@ class Random(Cog):
|
||||
embed = self.__embeds.RANDOM_NUMBER(a, b, x)
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@command(name='cara', help=helper.HELP_CARA, description=helper.HELP_CARA_LONG)
|
||||
@command(name='cara', help=helper.HELP_CARA, description=helper.HELP_CARA_LONG, aliases=['coroa'])
|
||||
async def cara(self, ctx: Context) -> None:
|
||||
x = random()
|
||||
if x < 0.5:
|
||||
@ -48,7 +45,7 @@ class Random(Cog):
|
||||
embed = self.__embeds.CARA_COROA(result)
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@command(name='choose', help=helper.HELP_CHOOSE, description=helper.HELP_CHOOSE_LONG)
|
||||
@command(name='choose', help=helper.HELP_CHOOSE, description=helper.HELP_CHOOSE_LONG, aliases=['escolha', 'pick'])
|
||||
async def choose(self, ctx, *args: str) -> None:
|
||||
try:
|
||||
user_input = " ".join(args)
|
||||
@ -64,4 +61,4 @@ class Random(Cog):
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Random(bot))
|
||||
bot.add_cog(RandomCog(bot))
|
||||
@ -3,15 +3,15 @@ from typing import List
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client, Guild, ClientUser, Member
|
||||
from Config.Messages import Messages
|
||||
from Controllers.PlayersController import PlayersController
|
||||
from Handlers.PlayersController import PlayersController
|
||||
from Music.Player import Player
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Config.Configs import Configs
|
||||
from Config.Helper import Helper
|
||||
from Views.Embeds import Embeds
|
||||
|
||||
|
||||
class AbstractController(ABC):
|
||||
class AbstractHandler(ABC):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
self.__bot: Client = bot
|
||||
self.__controller = PlayersController(self.__bot)
|
||||
@ -27,7 +27,7 @@ class AbstractController(ABC):
|
||||
self.__bot_member: Member = self.__get_member()
|
||||
|
||||
@abstractmethod
|
||||
async def run(self) -> ControllerResponse:
|
||||
async def run(self) -> HandlerResponse:
|
||||
pass
|
||||
|
||||
@property
|
||||
@ -1,15 +1,15 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Parallelism.ProcessManager import ProcessManager
|
||||
|
||||
|
||||
class ClearController(AbstractController):
|
||||
class ClearHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
async def run(self) -> HandlerResponse:
|
||||
# Get the current process of the guild
|
||||
processManager = ProcessManager()
|
||||
processContext = processManager.getRunningPlayerContext(self.guild)
|
||||
@ -19,4 +19,4 @@ class ClearController(AbstractController):
|
||||
with processContext.getLock():
|
||||
playlist.clear()
|
||||
|
||||
return ControllerResponse(self.ctx)
|
||||
return HandlerResponse(self.ctx)
|
||||
@ -1,10 +1,10 @@
|
||||
from typing import Union
|
||||
from discord.ext.commands import Context
|
||||
from Exceptions.Exceptions import VulkanError
|
||||
from Config.Exceptions import VulkanError
|
||||
from discord import Embed
|
||||
|
||||
|
||||
class ControllerResponse:
|
||||
class HandlerResponse:
|
||||
def __init__(self, ctx: Context, embed: Embed = None, error: VulkanError = None) -> None:
|
||||
self.__ctx: Context = ctx
|
||||
self.__error: VulkanError = error
|
||||
@ -1,15 +1,15 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Utils.Utils import Utils
|
||||
|
||||
|
||||
class HistoryController(AbstractController):
|
||||
class HistoryHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
async def run(self) -> HandlerResponse:
|
||||
history = self.player.playlist.getSongsHistory()
|
||||
|
||||
if len(history) == 0:
|
||||
@ -21,4 +21,4 @@ class HistoryController(AbstractController):
|
||||
text += f"**`{pos}` - ** {song.title} - `{Utils.format_time(song.duration)}`\n"
|
||||
|
||||
embed = self.embeds.HISTORY(text)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
@ -1,39 +1,39 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Exceptions.Exceptions import BadCommandUsage
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Config.Exceptions import BadCommandUsage
|
||||
|
||||
|
||||
class LoopController(AbstractController):
|
||||
class LoopHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self, args: str) -> ControllerResponse:
|
||||
async def run(self, args: str) -> HandlerResponse:
|
||||
if args == '' or args is None:
|
||||
self.player.playlist.loop_all()
|
||||
embed = self.embeds.LOOP_ALL_ACTIVATED()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
args = args.lower()
|
||||
if self.player.playlist.getCurrentSong() is None:
|
||||
embed = self.embeds.NOT_PLAYING()
|
||||
error = BadCommandUsage()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
if args == 'one':
|
||||
self.player.playlist.loop_one()
|
||||
embed = self.embeds.LOOP_ONE_ACTIVATED()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
elif args == 'all':
|
||||
self.player.playlist.loop_all()
|
||||
embed = self.embeds.LOOP_ALL_ACTIVATED()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
elif args == 'off':
|
||||
self.player.playlist.loop_off()
|
||||
embed = self.embeds.LOOP_DISABLE()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
else:
|
||||
error = BadCommandUsage()
|
||||
embed = self.embeds.BAD_LOOP_USE()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
@ -1,30 +1,30 @@
|
||||
from typing import Union
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Exceptions.Exceptions import BadCommandUsage, VulkanError, InvalidInput, NumberRequired, UnknownError
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Config.Exceptions import BadCommandUsage, VulkanError, InvalidInput, NumberRequired, UnknownError
|
||||
from Music.Playlist import Playlist
|
||||
from Parallelism.ProcessManager import ProcessManager
|
||||
|
||||
|
||||
class MoveController(AbstractController):
|
||||
class MoveHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self, pos1: str, pos2: str) -> ControllerResponse:
|
||||
async def run(self, pos1: str, pos2: str) -> HandlerResponse:
|
||||
processManager = ProcessManager()
|
||||
processContext = processManager.getRunningPlayerContext(self.guild)
|
||||
if not processContext:
|
||||
embed = self.embeds.NOT_PLAYING()
|
||||
error = BadCommandUsage()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
with processContext.getLock():
|
||||
error = self.__validateInput(pos1, pos2)
|
||||
if error:
|
||||
embed = self.embeds.ERROR_EMBED(error.message)
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
playlist = processContext.getPlaylist()
|
||||
pos1, pos2 = self.__sanitizeInput(playlist, pos1, pos2)
|
||||
@ -32,17 +32,17 @@ class MoveController(AbstractController):
|
||||
if not playlist.validate_position(pos1) or not playlist.validate_position(pos2):
|
||||
error = InvalidInput()
|
||||
embed = self.embeds.PLAYLIST_RANGE_ERROR()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
try:
|
||||
song = playlist.move_songs(pos1, pos2)
|
||||
|
||||
song_name = song.title if song.title else song.identifier
|
||||
embed = self.embeds.SONG_MOVED(song_name, pos1, pos2)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
except:
|
||||
embed = self.embeds.ERROR_MOVING()
|
||||
error = UnknownError()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
def __validateInput(self, pos1: str, pos2: str) -> Union[VulkanError, None]:
|
||||
try:
|
||||
@ -1,19 +1,19 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Utils.Cleaner import Cleaner
|
||||
|
||||
|
||||
class NowPlayingController(AbstractController):
|
||||
class NowPlayingHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
self.__cleaner = Cleaner()
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
async def run(self) -> HandlerResponse:
|
||||
if not self.player.playing:
|
||||
embed = self.embeds.NOT_PLAYING()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
if self.player.playlist.isLoopingOne():
|
||||
title = self.messages.ONE_SONG_LOOPING
|
||||
@ -23,4 +23,4 @@ class NowPlayingController(AbstractController):
|
||||
|
||||
info = self.player.playlist.getCurrentSong().info
|
||||
embed = self.embeds.SONG_INFO(info, title)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
@ -1,16 +1,16 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Parallelism.ProcessManager import ProcessManager
|
||||
from Parallelism.Commands import VCommands, VCommandsType
|
||||
|
||||
|
||||
class PauseController(AbstractController):
|
||||
class PauseHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
async def run(self) -> HandlerResponse:
|
||||
processManager = ProcessManager()
|
||||
processContext = processManager.getRunningPlayerContext(self.guild)
|
||||
if processContext:
|
||||
@ -19,4 +19,4 @@ class PauseController(AbstractController):
|
||||
queue = processContext.getQueue()
|
||||
queue.put(command)
|
||||
|
||||
return ControllerResponse(self.ctx)
|
||||
return HandlerResponse(self.ctx)
|
||||
@ -1,9 +1,9 @@
|
||||
from Exceptions.Exceptions import DownloadingError, InvalidInput, VulkanError
|
||||
from Config.Exceptions import DownloadingError, InvalidInput, VulkanError
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Exceptions.Exceptions import ImpossibleMove, UnknownError
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Config.Exceptions import ImpossibleMove, UnknownError
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Music.Downloader import Downloader
|
||||
from Music.Searcher import Searcher
|
||||
from Music.Song import Song
|
||||
@ -11,20 +11,20 @@ from Parallelism.ProcessManager import ProcessManager
|
||||
from Parallelism.Commands import VCommands, VCommandsType
|
||||
|
||||
|
||||
class PlayController(AbstractController):
|
||||
class PlayHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
self.__searcher = Searcher()
|
||||
self.__down = Downloader()
|
||||
|
||||
async def run(self, args: str) -> ControllerResponse:
|
||||
async def run(self, args: str) -> HandlerResponse:
|
||||
track = " ".join(args)
|
||||
requester = self.ctx.author.name
|
||||
|
||||
if not self.__isUserConnected():
|
||||
error = ImpossibleMove()
|
||||
embed = self.embeds.NO_CHANNEL()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
try:
|
||||
musics = await self.__searcher.search(track)
|
||||
@ -45,17 +45,17 @@ class PlayController(AbstractController):
|
||||
if song.problematic:
|
||||
embed = self.embeds.SONG_PROBLEMATIC()
|
||||
error = DownloadingError()
|
||||
response = ControllerResponse(self.ctx, embed, error)
|
||||
response = HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
elif not self.player.playing:
|
||||
embed = self.embeds.SONG_ADDED(song.title)
|
||||
response = ControllerResponse(self.ctx, embed)
|
||||
response = HandlerResponse(self.ctx, embed)
|
||||
else:
|
||||
embed = self.embeds.SONG_ADDED_TWO(song.info, pos)
|
||||
response = ControllerResponse(self.ctx, embed)
|
||||
response = HandlerResponse(self.ctx, embed)
|
||||
else:
|
||||
embed = self.embeds.SONGS_ADDED(quant)
|
||||
response = ControllerResponse(self.ctx, embed)
|
||||
response = HandlerResponse(self.ctx, embed)
|
||||
|
||||
# Get the process context for the current guild
|
||||
manager = ProcessManager(self.bot)
|
||||
@ -87,7 +87,7 @@ class PlayController(AbstractController):
|
||||
error = UnknownError()
|
||||
embed = self.embeds.UNKNOWN_ERROR()
|
||||
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
def __isUserConnected(self) -> bool:
|
||||
if self.ctx.author.voice:
|
||||
@ -1,4 +1,3 @@
|
||||
from multiprocessing import Process
|
||||
from typing import Dict, List, Union
|
||||
from Config.Singleton import Singleton
|
||||
from discord import Guild, Client, VoiceClient, Member
|
||||
@ -1,36 +1,36 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Exceptions.Exceptions import BadCommandUsage, ImpossibleMove, UnknownError
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Config.Exceptions import BadCommandUsage, ImpossibleMove, UnknownError
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
|
||||
|
||||
class PrevController(AbstractController):
|
||||
class PrevHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
async def run(self) -> HandlerResponse:
|
||||
if len(self.player.playlist.history()) == 0:
|
||||
error = ImpossibleMove()
|
||||
embed = self.embeds.NOT_PREVIOUS_SONG()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
if not self.__user_connected():
|
||||
error = ImpossibleMove()
|
||||
embed = self.embeds.NO_CHANNEL()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(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)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
if self.player.playlist.isLoopingAll() or self.player.playlist.isLoopingOne():
|
||||
error = BadCommandUsage()
|
||||
embed = self.embeds.FAIL_DUE_TO_LOOP_ON()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
await self.player.play_prev(self.ctx)
|
||||
|
||||
@ -1,25 +1,25 @@
|
||||
import asyncio
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Music.Downloader import Downloader
|
||||
from Utils.Utils import Utils
|
||||
from Parallelism.ProcessManager import ProcessManager
|
||||
|
||||
|
||||
class QueueController(AbstractController):
|
||||
class QueueHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
self.__down = Downloader()
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
async def run(self) -> HandlerResponse:
|
||||
# Retrieve the process of the guild
|
||||
process = ProcessManager()
|
||||
processContext = process.getRunningPlayerContext(self.guild)
|
||||
if not processContext: # If no process return empty list
|
||||
embed = self.embeds.EMPTY_QUEUE()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
# Acquire the Lock to manipulate the playlist
|
||||
with processContext.getLock():
|
||||
@ -28,12 +28,12 @@ class QueueController(AbstractController):
|
||||
if playlist.isLoopingOne():
|
||||
song = playlist.getCurrentSong()
|
||||
embed = self.embeds.ONE_SONG_LOOPING(song.info)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
songs_preload = playlist.getSongsToPreload()
|
||||
if len(songs_preload) == 0:
|
||||
embed = self.embeds.EMPTY_QUEUE()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
|
||||
asyncio.create_task(self.__down.preload(songs_preload))
|
||||
|
||||
@ -53,4 +53,4 @@ class QueueController(AbstractController):
|
||||
text += f"**`{pos}` - ** {song_name} - `{Utils.format_time(song.duration)}`\n"
|
||||
|
||||
embed = self.embeds.QUEUE(title, text)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
@ -1,42 +1,42 @@
|
||||
from typing import Union
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Exceptions.Exceptions import BadCommandUsage, VulkanError, ErrorRemoving, InvalidInput, NumberRequired
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Config.Exceptions import BadCommandUsage, VulkanError, ErrorRemoving, InvalidInput, NumberRequired
|
||||
|
||||
|
||||
class RemoveController(AbstractController):
|
||||
class RemoveHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self, position: str) -> ControllerResponse:
|
||||
async def run(self, position: str) -> HandlerResponse:
|
||||
if not self.player.playlist:
|
||||
embed = self.embeds.NOT_PLAYING()
|
||||
error = BadCommandUsage()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
error = self.__validate_input(position)
|
||||
if error:
|
||||
embed = self.embeds.ERROR_EMBED(error.message)
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
position = self.__sanitize_input(position)
|
||||
if not self.player.playlist.validate_position(position):
|
||||
error = InvalidInput()
|
||||
embed = self.embeds.PLAYLIST_RANGE_ERROR()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
try:
|
||||
song = self.player.playlist.remove_song(position)
|
||||
name = song.title if song.title else song.identifier
|
||||
|
||||
embed = self.embeds.SONG_REMOVED(name)
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
except:
|
||||
error = ErrorRemoving()
|
||||
embed = self.embeds.ERROR_REMOVING()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
def __validate_input(self, position: str) -> Union[VulkanError, None]:
|
||||
try:
|
||||
@ -1,20 +1,20 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Controllers.PlayersController import PlayersController
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Handlers.PlayersController import PlayersController
|
||||
|
||||
|
||||
class ResetController(AbstractController):
|
||||
class ResetHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
self.__controller = PlayersController(self.bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
async def run(self) -> HandlerResponse:
|
||||
try:
|
||||
await self.player.force_stop()
|
||||
await self.bot_member.move_to(None)
|
||||
self.__controller.reset_player(self.guild)
|
||||
return ControllerResponse(self.ctx)
|
||||
return HandlerResponse(self.ctx)
|
||||
except Exception as e:
|
||||
print(f'DEVELOPER NOTE -> Reset Error: {e}')
|
||||
@ -1,16 +1,16 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Parallelism.ProcessManager import ProcessManager
|
||||
from Parallelism.Commands import VCommands, VCommandsType
|
||||
|
||||
|
||||
class ResumeController(AbstractController):
|
||||
class ResumeHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
async def run(self) -> HandlerResponse:
|
||||
processManager = ProcessManager()
|
||||
processContext = processManager.getRunningPlayerContext(self.guild)
|
||||
if processContext:
|
||||
@ -19,4 +19,4 @@ class ResumeController(AbstractController):
|
||||
queue = processContext.getQueue()
|
||||
queue.put(command)
|
||||
|
||||
return ControllerResponse(self.ctx)
|
||||
return HandlerResponse(self.ctx)
|
||||
@ -1,27 +1,27 @@
|
||||
import asyncio
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Exceptions.Exceptions import UnknownError
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Config.Exceptions import UnknownError
|
||||
from Music.Downloader import Downloader
|
||||
|
||||
|
||||
class ShuffleController(AbstractController):
|
||||
class ShuffleHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
self.__down = Downloader()
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
async def run(self) -> HandlerResponse:
|
||||
try:
|
||||
self.player.playlist.shuffle()
|
||||
songs = self.player.playlist.getSongsToPreload()
|
||||
|
||||
asyncio.create_task(self.__down.preload(songs))
|
||||
embed = self.embeds.SONGS_SHUFFLED()
|
||||
return ControllerResponse(self.ctx, embed)
|
||||
return HandlerResponse(self.ctx, embed)
|
||||
except Exception as e:
|
||||
print(f'DEVELOPER NOTE -> Error Shuffling: {e}')
|
||||
error = UnknownError()
|
||||
embed = self.embeds.ERROR_SHUFFLING()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
@ -1,17 +1,17 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Exceptions.Exceptions import BadCommandUsage
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Config.Exceptions import BadCommandUsage
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Parallelism.ProcessManager import ProcessManager
|
||||
from Parallelism.Commands import VCommands, VCommandsType
|
||||
|
||||
|
||||
class SkipController(AbstractController):
|
||||
class SkipHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
async def run(self) -> HandlerResponse:
|
||||
processManager = ProcessManager()
|
||||
processContext = processManager.getRunningPlayerContext(self.guild)
|
||||
if processContext: # Verify if there is a running process
|
||||
@ -19,10 +19,10 @@ class SkipController(AbstractController):
|
||||
if playlist.isLoopingOne():
|
||||
embed = self.embeds.ERROR_DUE_LOOP_ONE_ON()
|
||||
error = BadCommandUsage()
|
||||
return ControllerResponse(self.ctx, embed, error)
|
||||
return HandlerResponse(self.ctx, embed, error)
|
||||
|
||||
# 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)
|
||||
return HandlerResponse(self.ctx)
|
||||
@ -1,16 +1,16 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.AbstractHandler import AbstractHandler
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from Parallelism.ProcessManager import ProcessManager
|
||||
from Parallelism.Commands import VCommands, VCommandsType
|
||||
|
||||
|
||||
class StopController(AbstractController):
|
||||
class StopHandler(AbstractHandler):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
async def run(self) -> HandlerResponse:
|
||||
processManager = ProcessManager()
|
||||
processContext = processManager.getRunningPlayerContext(self.guild)
|
||||
if processContext:
|
||||
@ -19,4 +19,4 @@ class StopController(AbstractController):
|
||||
queue = processContext.getQueue()
|
||||
queue.put(command)
|
||||
|
||||
return ControllerResponse(self.ctx)
|
||||
return HandlerResponse(self.ctx)
|
||||
@ -1,5 +1,5 @@
|
||||
import deezer
|
||||
from Exceptions.Exceptions import DeezerError
|
||||
from Config.Exceptions import DeezerError
|
||||
from Config.Messages import DeezerMessages
|
||||
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ from Music.Song import Song
|
||||
from Utils.Utils import Utils, run_async
|
||||
|
||||
|
||||
class Downloader():
|
||||
class Downloader:
|
||||
config = Configs()
|
||||
__YDL_OPTIONS = {'format': 'bestaudio/best',
|
||||
'default_search': 'auto',
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from Exceptions.Exceptions import DeezerError, InvalidInput, SpotifyError, YoutubeError
|
||||
from Config.Exceptions import DeezerError, InvalidInput, SpotifyError, YoutubeError
|
||||
from Music.Downloader import Downloader
|
||||
from Music.Types import Provider
|
||||
from Music.Spotify import SpotifySearch
|
||||
from Music.SpotifySearcher import SpotifySearch
|
||||
from Music.DeezerSearcher import DeezerSearcher
|
||||
from Utils.Utils import Utils
|
||||
from Utils.UrlAnalyzer import URLAnalyzer
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from spotipy import Spotify
|
||||
from spotipy.oauth2 import SpotifyClientCredentials
|
||||
from spotipy.exceptions import SpotifyException
|
||||
from Exceptions.Exceptions import SpotifyError
|
||||
from Config.Exceptions import SpotifyError
|
||||
from Config.Configs import Configs
|
||||
from Config.Messages import SpotifyMessages
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
@ -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__')
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from Tests.TestBase import VulkanTesterBase
|
||||
from Exceptions.Exceptions import DeezerError
|
||||
from Config.Exceptions import DeezerError
|
||||
|
||||
|
||||
class VulkanDeezerTest(VulkanTesterBase):
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from Tests.TestBase import VulkanTesterBase
|
||||
from Exceptions.Exceptions import SpotifyError
|
||||
from Config.Exceptions import SpotifyError
|
||||
|
||||
|
||||
class VulkanSpotifyTest(VulkanTesterBase):
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Embed
|
||||
|
||||
|
||||
class Sender:
|
||||
@classmethod
|
||||
async def send_embed(cls, ctx: Context, embed: Embed) -> None:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
async def send_message(cls, ctx: Context, message: Embed) -> None:
|
||||
pass
|
||||
@ -1,18 +1,18 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client, Message
|
||||
|
||||
|
||||
class AbstractView(ABC):
|
||||
def __init__(self, response: ControllerResponse) -> None:
|
||||
self.__response: ControllerResponse = response
|
||||
def __init__(self, response: HandlerResponse) -> None:
|
||||
self.__response: HandlerResponse = response
|
||||
self.__context: Context = response.ctx
|
||||
self.__message: Message = response.ctx.message
|
||||
self.__bot: Client = response.ctx.bot
|
||||
|
||||
@property
|
||||
def response(self) -> ControllerResponse:
|
||||
def response(self) -> HandlerResponse:
|
||||
return self.__response
|
||||
|
||||
@property
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
from Views.AbstractView import AbstractView
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
|
||||
|
||||
class EmbedView(AbstractView):
|
||||
def __init__(self, response: ControllerResponse) -> None:
|
||||
def __init__(self, response: HandlerResponse) -> None:
|
||||
super().__init__(response)
|
||||
|
||||
async def run(self) -> None:
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from Config.Messages import Messages
|
||||
from Exceptions.Exceptions import VulkanError
|
||||
from Config.Exceptions import VulkanError
|
||||
from discord import Embed
|
||||
from Config.Configs import Configs
|
||||
from Config.Colors import Colors
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
from Views.AbstractView import AbstractView
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Handlers.HandlerResponse import HandlerResponse
|
||||
|
||||
|
||||
class EmoteView(AbstractView):
|
||||
|
||||
def __init__(self, response: ControllerResponse) -> None:
|
||||
def __init__(self, response: HandlerResponse) -> None:
|
||||
super().__init__(response)
|
||||
|
||||
async def run(self) -> None:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user