mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Upgrading clean code
This commit is contained in:
parent
7e9a6d45c0
commit
c826af229c
@ -1,13 +1,13 @@
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
from discord.ext.commands import Context
|
from discord.ext.commands import Context
|
||||||
from Exceptions.Exceptions import Error
|
from Exceptions.Exceptions import VulkanError
|
||||||
from discord import Embed
|
from discord import Embed
|
||||||
|
|
||||||
|
|
||||||
class ControllerResponse:
|
class ControllerResponse:
|
||||||
def __init__(self, ctx: Context, embed: Embed = None, error: Error = None) -> None:
|
def __init__(self, ctx: Context, embed: Embed = None, error: VulkanError = None) -> None:
|
||||||
self.__ctx: Context = ctx
|
self.__ctx: Context = ctx
|
||||||
self.__error: Error = error
|
self.__error: VulkanError = error
|
||||||
self.__embed: Embed = embed
|
self.__embed: Embed = embed
|
||||||
self.__success = False if error else True
|
self.__success = False if error else True
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ class ControllerResponse:
|
|||||||
def embed(self) -> Union[Embed, None]:
|
def embed(self) -> Union[Embed, None]:
|
||||||
return self.__embed
|
return self.__embed
|
||||||
|
|
||||||
def error(self) -> Union[Error, None]:
|
def error(self) -> Union[VulkanError, None]:
|
||||||
return self.__error
|
return self.__error
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@ -3,7 +3,7 @@ from discord.ext.commands import Context
|
|||||||
from discord import Client
|
from discord import Client
|
||||||
from Controllers.AbstractController import AbstractController
|
from Controllers.AbstractController import AbstractController
|
||||||
from Controllers.ControllerResponse import ControllerResponse
|
from Controllers.ControllerResponse import ControllerResponse
|
||||||
from Exceptions.Exceptions import BadCommandUsage, Error, InvalidInput, NumberRequired, UnknownError, WrongLength
|
from Exceptions.Exceptions import BadCommandUsage, VulkanError, InvalidInput, NumberRequired, UnknownError
|
||||||
from Music.Downloader import Downloader
|
from Music.Downloader import Downloader
|
||||||
|
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class MoveController(AbstractController):
|
|||||||
error = UnknownError()
|
error = UnknownError()
|
||||||
return ControllerResponse(self.ctx, embed, error)
|
return ControllerResponse(self.ctx, embed, error)
|
||||||
|
|
||||||
def __validate_input(self, pos1: str, pos2: str) -> Union[Error, None]:
|
def __validate_input(self, pos1: str, pos2: str) -> Union[VulkanError, None]:
|
||||||
try:
|
try:
|
||||||
pos1 = int(pos1)
|
pos1 = int(pos1)
|
||||||
pos2 = int(pos2)
|
pos2 = int(pos2)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from Exceptions.Exceptions import DownloadingError, Error
|
from Exceptions.Exceptions import DownloadingError, VulkanError
|
||||||
from discord.ext.commands import Context
|
from discord.ext.commands import Context
|
||||||
from discord import Client
|
from discord import Client
|
||||||
from Controllers.AbstractController import AbstractController
|
from Controllers.AbstractController import AbstractController
|
||||||
@ -64,7 +64,7 @@ class PlayController(AbstractController):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
if isinstance(err, Error):
|
if isinstance(err, VulkanError): # If error was already processed
|
||||||
print(f'DEVELOPER NOTE -> PlayController Error: {err.message}')
|
print(f'DEVELOPER NOTE -> PlayController Error: {err.message}')
|
||||||
error = err
|
error = err
|
||||||
embed = self.embeds.CUSTOM_ERROR(error)
|
embed = self.embeds.CUSTOM_ERROR(error)
|
||||||
|
|||||||
@ -3,7 +3,7 @@ from discord.ext.commands import Context
|
|||||||
from discord import Client
|
from discord import Client
|
||||||
from Controllers.AbstractController import AbstractController
|
from Controllers.AbstractController import AbstractController
|
||||||
from Controllers.ControllerResponse import ControllerResponse
|
from Controllers.ControllerResponse import ControllerResponse
|
||||||
from Exceptions.Exceptions import BadCommandUsage, Error, ErrorRemoving, InvalidInput, NumberRequired, UnknownError
|
from Exceptions.Exceptions import BadCommandUsage, VulkanError, ErrorRemoving, InvalidInput, NumberRequired
|
||||||
|
|
||||||
|
|
||||||
class RemoveController(AbstractController):
|
class RemoveController(AbstractController):
|
||||||
@ -38,7 +38,7 @@ class RemoveController(AbstractController):
|
|||||||
embed = self.embeds.ERROR_REMOVING()
|
embed = self.embeds.ERROR_REMOVING()
|
||||||
return ControllerResponse(self.ctx, embed, error)
|
return ControllerResponse(self.ctx, embed, error)
|
||||||
|
|
||||||
def __validate_input(self, position: str) -> Union[Error, None]:
|
def __validate_input(self, position: str) -> Union[VulkanError, None]:
|
||||||
try:
|
try:
|
||||||
position = int(position)
|
position = int(position)
|
||||||
except:
|
except:
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
from Config.Configs import Configs
|
|
||||||
from Config.Messages import Messages
|
from Config.Messages import Messages
|
||||||
|
|
||||||
|
|
||||||
class Error(Exception):
|
class VulkanError(Exception):
|
||||||
def __init__(self, message='', title='', *args: object) -> None:
|
def __init__(self, message='', title='', *args: object) -> None:
|
||||||
self.__message = message
|
self.__message = message
|
||||||
self.__title = title
|
self.__title = title
|
||||||
@ -17,7 +16,7 @@ class Error(Exception):
|
|||||||
return self.__title
|
return self.__title
|
||||||
|
|
||||||
|
|
||||||
class ImpossibleMove(Error):
|
class ImpossibleMove(VulkanError):
|
||||||
def __init__(self, message='', title='', *args: object) -> None:
|
def __init__(self, message='', title='', *args: object) -> None:
|
||||||
message = Messages()
|
message = Messages()
|
||||||
if title == '':
|
if title == '':
|
||||||
@ -25,56 +24,56 @@ class ImpossibleMove(Error):
|
|||||||
super().__init__(message, title, *args)
|
super().__init__(message, title, *args)
|
||||||
|
|
||||||
|
|
||||||
class MusicUnavailable(Error):
|
class MusicUnavailable(VulkanError):
|
||||||
def __init__(self, message='', title='', *args: object) -> None:
|
def __init__(self, message='', title='', *args: object) -> None:
|
||||||
super().__init__(message, title, *args)
|
super().__init__(message, title, *args)
|
||||||
|
|
||||||
|
|
||||||
class YoutubeError(Error):
|
class YoutubeError(VulkanError):
|
||||||
def __init__(self, message='', title='', *args: object) -> None:
|
def __init__(self, message='', title='', *args: object) -> None:
|
||||||
super().__init__(message, title, *args)
|
super().__init__(message, title, *args)
|
||||||
|
|
||||||
|
|
||||||
class BadCommandUsage(Error):
|
class BadCommandUsage(VulkanError):
|
||||||
def __init__(self, message='', title='', *args: object) -> None:
|
def __init__(self, message='', title='', *args: object) -> None:
|
||||||
super().__init__(message, title, *args)
|
super().__init__(message, title, *args)
|
||||||
|
|
||||||
|
|
||||||
class DownloadingError(Error):
|
class DownloadingError(VulkanError):
|
||||||
def __init__(self, message='', title='', *args: object) -> None:
|
def __init__(self, message='', title='', *args: object) -> None:
|
||||||
super().__init__(message, title, *args)
|
super().__init__(message, title, *args)
|
||||||
|
|
||||||
|
|
||||||
class SpotifyError(Error):
|
class SpotifyError(VulkanError):
|
||||||
def __init__(self, message='', title='', *args: object) -> None:
|
def __init__(self, message='', title='', *args: object) -> None:
|
||||||
super().__init__(message, title, *args)
|
super().__init__(message, title, *args)
|
||||||
|
|
||||||
|
|
||||||
class UnknownError(Error):
|
class UnknownError(VulkanError):
|
||||||
def __init__(self, message='', title='', *args: object) -> None:
|
def __init__(self, message='', title='', *args: object) -> None:
|
||||||
super().__init__(message, title, *args)
|
super().__init__(message, title, *args)
|
||||||
|
|
||||||
|
|
||||||
class InvalidInput(Error):
|
class InvalidInput(VulkanError):
|
||||||
def __init__(self, message='', title='', *args: object) -> None:
|
def __init__(self, message='', title='', *args: object) -> None:
|
||||||
super().__init__(message, title, *args)
|
super().__init__(message, title, *args)
|
||||||
|
|
||||||
|
|
||||||
class WrongLength(Error):
|
class WrongLength(VulkanError):
|
||||||
def __init__(self, message='', title='', *args: object) -> None:
|
def __init__(self, message='', title='', *args: object) -> None:
|
||||||
super().__init__(message, title, *args)
|
super().__init__(message, title, *args)
|
||||||
|
|
||||||
|
|
||||||
class ErrorMoving(Error):
|
class ErrorMoving(VulkanError):
|
||||||
def __init__(self, message='', title='', *args: object) -> None:
|
def __init__(self, message='', title='', *args: object) -> None:
|
||||||
super().__init__(message, title, *args)
|
super().__init__(message, title, *args)
|
||||||
|
|
||||||
|
|
||||||
class ErrorRemoving(Error):
|
class ErrorRemoving(VulkanError):
|
||||||
def __init__(self, message='', title='', *args: object) -> None:
|
def __init__(self, message='', title='', *args: object) -> None:
|
||||||
super().__init__(message, title, *args)
|
super().__init__(message, title, *args)
|
||||||
|
|
||||||
|
|
||||||
class NumberRequired(Error):
|
class NumberRequired(VulkanError):
|
||||||
def __init__(self, message='', title='', *args: object) -> None:
|
def __init__(self, message='', title='', *args: object) -> None:
|
||||||
super().__init__(message, title, *args)
|
super().__init__(message, title, *args)
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
from requests import HTTPError
|
|
||||||
from Music.Spotify import SpotifySearch
|
|
||||||
from Tests.TestBase import VulkanTesterBase
|
from Tests.TestBase import VulkanTesterBase
|
||||||
from Exceptions.Exceptions import SpotifyError
|
from Exceptions.Exceptions import SpotifyError
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from Config.Messages import Messages
|
from Config.Messages import Messages
|
||||||
from Exceptions.Exceptions import Error
|
from Exceptions.Exceptions import VulkanError
|
||||||
from discord import Embed
|
from discord import Embed
|
||||||
from Config.Configs import Configs
|
from Config.Configs import Configs
|
||||||
from Config.Colors import Colors
|
from Config.Colors import Colors
|
||||||
@ -130,7 +130,7 @@ class Embeds:
|
|||||||
)
|
)
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
def CUSTOM_ERROR(self, error: Error) -> Embed:
|
def CUSTOM_ERROR(self, error: VulkanError) -> Embed:
|
||||||
embed = Embed(
|
embed = Embed(
|
||||||
title=error.title,
|
title=error.title,
|
||||||
description=error.message,
|
description=error.message,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user