Upgrading clean code

This commit is contained in:
Rafael Vargas
2022-07-10 14:27:40 -03:00
parent 7e9a6d45c0
commit c826af229c
7 changed files with 25 additions and 28 deletions

View File

@@ -1,13 +1,13 @@
from typing import Union
from discord.ext.commands import Context
from Exceptions.Exceptions import Error
from Exceptions.Exceptions import VulkanError
from discord import Embed
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.__error: Error = error
self.__error: VulkanError = error
self.__embed: Embed = embed
self.__success = False if error else True
@@ -19,7 +19,7 @@ class ControllerResponse:
def embed(self) -> Union[Embed, None]:
return self.__embed
def error(self) -> Union[Error, None]:
def error(self) -> Union[VulkanError, None]:
return self.__error
@property

View File

@@ -3,7 +3,7 @@ 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, Error, InvalidInput, NumberRequired, UnknownError, WrongLength
from Exceptions.Exceptions import BadCommandUsage, VulkanError, InvalidInput, NumberRequired, UnknownError
from Music.Downloader import Downloader
@@ -44,7 +44,7 @@ class MoveController(AbstractController):
error = UnknownError()
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:
pos1 = int(pos1)
pos2 = int(pos2)

View File

@@ -1,5 +1,5 @@
import asyncio
from Exceptions.Exceptions import DownloadingError, Error
from Exceptions.Exceptions import DownloadingError, VulkanError
from discord.ext.commands import Context
from discord import Client
from Controllers.AbstractController import AbstractController
@@ -64,7 +64,7 @@ class PlayController(AbstractController):
return response
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}')
error = err
embed = self.embeds.CUSTOM_ERROR(error)

View File

@@ -3,7 +3,7 @@ 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, Error, ErrorRemoving, InvalidInput, NumberRequired, UnknownError
from Exceptions.Exceptions import BadCommandUsage, VulkanError, ErrorRemoving, InvalidInput, NumberRequired
class RemoveController(AbstractController):
@@ -38,7 +38,7 @@ class RemoveController(AbstractController):
embed = self.embeds.ERROR_REMOVING()
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:
position = int(position)
except: