mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Changing folders names and adding more concrete classes of controllers and viewers
This commit is contained in:
57
vulkan/controllers/AbstractController.py
Normal file
57
vulkan/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 Vulkan.Controllers.PlayerController import PlayersController
|
||||
from Vulkan.Music.Player import Player
|
||||
from Vulkan.Controllers.ControllerResponse import ControllerResponse
|
||||
from Config.Config import Config
|
||||
from Config.Helper import Helper
|
||||
from Vulkan.Views.Embeds.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 = Config()
|
||||
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) -> Config:
|
||||
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
|
||||
@@ -1,34 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client, Guild
|
||||
from vulkan.controllers.PlayerController import PlayersController
|
||||
from vulkan.music.Player import Player
|
||||
from vulkan.results.AbstractResult import AbstractResult
|
||||
|
||||
|
||||
class AbstractHandler(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
|
||||
|
||||
@abstractmethod
|
||||
async def run(self) -> AbstractResult:
|
||||
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
|
||||
27
vulkan/controllers/ControllerResponse.py
Normal file
27
vulkan/controllers/ControllerResponse.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from typing import Union
|
||||
from discord.ext.commands import Context
|
||||
from Vulkan.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
|
||||
@@ -1,26 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class Error(Exception, ABC):
|
||||
@abstractmethod
|
||||
def message():
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def title():
|
||||
pass
|
||||
|
||||
|
||||
class MusicUnavailable(Error):
|
||||
def __init__(self, message: str) -> None:
|
||||
self.__message = message
|
||||
super().__init__(message)
|
||||
|
||||
def message():
|
||||
pass
|
||||
|
||||
def title():
|
||||
pass
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.__message
|
||||
@@ -1,7 +1,7 @@
|
||||
from typing import Dict, List, Union
|
||||
from config.Singleton import Singleton
|
||||
from Config.Singleton import Singleton
|
||||
from discord import Guild, Client, VoiceClient
|
||||
from vulkan.music.Player import Player
|
||||
from Vulkan.Music.Player import Player
|
||||
|
||||
|
||||
class PlayersController(Singleton):
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from vulkan.controllers.AbstractHandler import AbstractHandler
|
||||
from Vulkan.Controllers.AbstractController import AbstractController
|
||||
from Vulkan.Exceptions.Exceptions import BadCommandUsage
|
||||
from Vulkan.Controllers.ControllerResponse import ControllerResponse
|
||||
|
||||
|
||||
class SkipHandler(AbstractHandler):
|
||||
class SkipController(AbstractController):
|
||||
def __init__(self, ctx: Context, bot: Client) -> None:
|
||||
super().__init__(ctx, bot)
|
||||
|
||||
async def run(self) -> None:
|
||||
async def run(self) -> ControllerResponse:
|
||||
if self.player.playlist.looping_one:
|
||||
""" embed = Embed(
|
||||
title=config.SONG_PLAYER,
|
||||
description=config.LOOP_ON,
|
||||
colour=config.COLOURS['blue']
|
||||
)
|
||||
await ctx.send(embed=embed)
|
||||
return False
|
||||
"""
|
||||
return None
|
||||
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:
|
||||
return None
|
||||
response = ControllerResponse(self.ctx)
|
||||
return response
|
||||
else:
|
||||
voice.stop()
|
||||
response = ControllerResponse(self.ctx)
|
||||
return response
|
||||
|
||||
Reference in New Issue
Block a user