mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Chaging the folders and creating a separeted class for messages
This commit is contained in:
57
Controllers/AbstractController.py
Normal file
57
Controllers/AbstractController.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client, Guild
|
||||
from Controllers.PlayerController import PlayersController
|
||||
from Music.Player import Player
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Config.Config import Configs
|
||||
from Config.Helper import Helper
|
||||
from Views.Embeds import Embeds
|
||||
|
||||
|
||||
class AbstractController(ABC):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
self.__bot: Client = bot
|
||||
self.__controller = PlayersController(self.__bot)
|
||||
self.__player: Player = self.__controller.get_player(ctx.guild)
|
||||
self.__guild: Guild = ctx.guild
|
||||
self.__ctx: Context = ctx
|
||||
self.__config = Configs()
|
||||
self.__helper = Helper()
|
||||
self.__embeds = Embeds()
|
||||
|
||||
@abstractmethod
|
||||
async def run(self) -> ControllerResponse:
|
||||
pass
|
||||
|
||||
@property
|
||||
def guild(self) -> Guild:
|
||||
return self.__guild
|
||||
|
||||
@property
|
||||
def player(self) -> Player:
|
||||
return self.__player
|
||||
|
||||
@property
|
||||
def controller(self) -> PlayersController:
|
||||
return self.__controller
|
||||
|
||||
@property
|
||||
def bot(self) -> Client:
|
||||
return self.__bot
|
||||
|
||||
@property
|
||||
def config(self) -> Configs:
|
||||
return self.__config
|
||||
|
||||
@property
|
||||
def helper(self) -> Helper:
|
||||
return self.__helper
|
||||
|
||||
@property
|
||||
def ctx(self) -> Context:
|
||||
return self.__ctx
|
||||
|
||||
@property
|
||||
def embeds(self) -> Embeds:
|
||||
return self.__embeds
|
||||
27
Controllers/ControllerResponse.py
Normal file
27
Controllers/ControllerResponse.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from typing import Union
|
||||
from discord.ext.commands import Context
|
||||
from Exceptions.Exceptions import Error
|
||||
from discord import Embed
|
||||
|
||||
|
||||
class ControllerResponse:
|
||||
def __init__(self, ctx: Context, embed: Embed = None, error: Error = None) -> None:
|
||||
self.__ctx: Context = ctx
|
||||
self.__error: Error = error
|
||||
self.__embed: Embed = embed
|
||||
self.__success = False if error else True
|
||||
|
||||
@property
|
||||
def ctx(self) -> Context:
|
||||
return self.__ctx
|
||||
|
||||
@property
|
||||
def embed(self) -> Union[Embed, None]:
|
||||
return self.__embed
|
||||
|
||||
def error(self) -> Union[Error, None]:
|
||||
return self.__error
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return self.__success
|
||||
44
Controllers/PlayerController.py
Normal file
44
Controllers/PlayerController.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from typing import Dict, List, Union
|
||||
from Config.Singleton import Singleton
|
||||
from discord import Guild, Client, VoiceClient
|
||||
from Music.Player import Player
|
||||
|
||||
|
||||
class PlayersController(Singleton):
|
||||
def __init__(self, bot: Client = None) -> None:
|
||||
if not super().created:
|
||||
self.__bot: Client = bot
|
||||
if bot is not None:
|
||||
self.__players: Dict[Guild, Player] = self.__create_players()
|
||||
|
||||
def set_bot(self, bot: Client) -> None:
|
||||
self.__bot: Client = bot
|
||||
self.__players: Dict[Guild, Player] = self.__create_players()
|
||||
|
||||
def get_player(self, guild: Guild) -> Player:
|
||||
if guild not in self.__players.keys():
|
||||
player = Player(self.__bot, guild)
|
||||
self.__players[guild] = player
|
||||
|
||||
return self.__players[guild]
|
||||
|
||||
def reset_player(self, guild: Guild) -> None:
|
||||
if isinstance(guild, Guild):
|
||||
player = Player(self.__bot, guild)
|
||||
self.__players[guild] == player
|
||||
|
||||
def get_guild_voice(self, guild: Guild) -> Union[VoiceClient, None]:
|
||||
if guild.voice_client is None:
|
||||
return None
|
||||
else:
|
||||
return guild.voice_client
|
||||
|
||||
def __create_players(self) -> Dict[Guild, Player]:
|
||||
list_guilds: List[Guild] = self.__bot.guilds
|
||||
players: Dict[Guild, Player] = {}
|
||||
|
||||
for guild in list_guilds:
|
||||
player = Player(self.__bot, guild)
|
||||
players[guild] = player
|
||||
|
||||
return players
|
||||
26
Controllers/SkipController.py
Normal file
26
Controllers/SkipController.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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
|
||||
|
||||
|
||||
class SkipController(AbstractController):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> ControllerResponse:
|
||||
if self.player.playlist.looping_one:
|
||||
embed = self.__embeds.FAIL_DUE_TO_LOOP_ON
|
||||
error = BadCommandUsage('', '')
|
||||
response = ControllerResponse(self.ctx, embed, error)
|
||||
return response
|
||||
|
||||
voice = self.controller.get_guild_voice(self.guild)
|
||||
if voice is None:
|
||||
response = ControllerResponse(self.ctx)
|
||||
return response
|
||||
else:
|
||||
voice.stop()
|
||||
response = ControllerResponse(self.ctx)
|
||||
return response
|
||||
Reference in New Issue
Block a user