Adding types and changing some messages from class

This commit is contained in:
Rafael Vargas
2022-03-26 21:24:03 -04:00
parent f9b46e13ff
commit b4159c7e86
16 changed files with 154 additions and 359 deletions

View File

@@ -1,9 +1,11 @@
import discord
from discord import Client
from discord import Client, Game, Status, Embed
from discord.ext.commands.errors import CommandNotFound, MissingRequiredArgument, UserInputError
from discord.ext import commands
from Config.Config import Configs
from Config.Helper import Helper
from Config.Messages import Messages
from Config.Colors import Colors
from Views.Embeds import Embeds
helper = Helper()
@@ -13,6 +15,9 @@ class Control(commands.Cog):
def __init__(self, bot: Client):
self.__bot = bot
self.__config = Configs()
self.__messages = Messages()
self.__colors = Colors()
self.__embeds = Embeds()
self.__comandos = {
'MUSIC': ['resume', 'pause', 'loop', 'stop',
'skip', 'play', 'queue', 'clear',
@@ -24,49 +29,23 @@ class Control(commands.Cog):
@commands.Cog.listener()
async def on_ready(self):
print(self.__config.STARTUP_MESSAGE)
await self.__bot.change_presence(status=discord.Status.online, activity=discord.Game(name=f"Vulkan | {self.__config.BOT_PREFIX}help"))
print(self.__config.STARTUP_COMPLETE_MESSAGE)
print(self.__messages.STARTUP_MESSAGE)
await self.__bot.change_presence(status=Status.online, activity=Game(name=f"Vulkan | {self.__config.BOT_PREFIX}help"))
print(self.__messages.STARTUP_COMPLETE_MESSAGE)
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if isinstance(error, MissingRequiredArgument):
embed = discord.Embed(
title=self.__config.ERROR_TITLE,
description=self.__config.ERROR_MISSING_ARGUMENTS,
colour=self.__config.COLOURS['black']
)
embed = self.__embeds.MISSING_ARGUMENTS()
await ctx.send(embed=embed)
elif isinstance(error, CommandNotFound):
embed = discord.Embed(
title=self.__config.ERROR_TITLE,
description=self.__config.COMMAND_NOT_FOUND,
colour=self.__config.COLOURS['black']
)
embed = self.__embeds.COMMAND_NOT_FOUND()
await ctx.send(embed=embed)
elif isinstance(error, UserInputError):
my_error = False
if len(error.args) > 0:
for arg in error.args:
if arg == self.__config.MY_ERROR_BAD_COMMAND:
embed = discord.Embed(
title=self.__config.BAD_COMMAND_TITLE,
description=self.__config.BAD_COMMAND,
colour=self.__config.COLOURS['black']
)
await ctx.send(embed=embed)
my_error = True
break
if not my_error:
raise error
else:
print(f'DEVELOPER NOTE -> Comand Error: {error}')
embed = discord.Embed(
title=self.__config.ERROR_TITLE,
description=self.__config.UNKNOWN_ERROR,
colour=self.__config.COLOURS['red']
)
embed = self.__embeds.UNKNOWN_ERROR()
await ctx.send(embed=embed)
@commands.command(name="help", help=helper.HELP_HELP, description=helper.HELP_HELP_LONG, aliases=['h', 'ajuda'])
@@ -76,19 +55,19 @@ class Control(commands.Cog):
if command.name == command_help:
txt = command.description if command.description else command.help
embedhelp = discord.Embed(
embedhelp = Embed(
title=f'**Description of {command_help}** command',
description=txt,
colour=self.__config.COLOURS['blue']
colour=self.__colors.BLUE
)
await ctx.send(embed=embedhelp)
return
embedhelp = discord.Embed(
embedhelp = Embed(
title='Command Help',
description=f'Command {command_help} Not Found',
colour=self.__config.COLOURS['red']
colour=self.__colors.RED
)
await ctx.send(embed=embedhelp)
@@ -111,10 +90,10 @@ class Control(commands.Cog):
helptxt = f'\n{help_music}\n{help_help}\n{help_random}'
helptxt += f'\n\nType {self.__config.BOT_PREFIX}help "command" for more information about the command chosen'
embedhelp = discord.Embed(
embedhelp = Embed(
title=f'**Available Commands of {self.__bot.user.name}**',
description=helptxt,
colour=self.__config.COLOURS['blue']
colour=self.__colors.BLUE
)
embedhelp.set_thumbnail(url=self.__bot.user.avatar_url)
@@ -122,14 +101,13 @@ class Control(commands.Cog):
@commands.command(name='invite', help=helper.HELP_INVITE, description=helper.HELP_INVITE_LONG)
async def invite_bot(self, ctx):
invite_url = 'https://discordapp.com/oauth2/authorize?client_id={}&scope=bot>'.format(
self.__bot.user.id)
txt = self.__config.INVITE_MESSAGE.format(invite_url)
invite_url = self.__config.INVITE_URL.format(self.__bot.user.id)
txt = self.__config.INVITE_MESSAGE.format(invite_url, invite_url)
embed = discord.Embed(
embed = Embed(
title="Invite Vulkan",
description=txt,
colour=self.__config.COLOURS['blue']
colour=self.__colors.BLUE
)
await ctx.send(embed=embed)

View File

@@ -1,30 +1,30 @@
from random import randint, random
import discord
from discord.ext import commands
from discord import Client
from discord.ext.commands import Context, command, Cog
from Config.Colors import Colors
from Config.Config import Configs
from Config.Helper import Helper
from Views.Embeds import Embeds
helper = Helper()
class Random(commands.Cog):
class Random(Cog):
def __init__(self, bot):
self.__bot = bot
def __init__(self, bot: Client):
self.__config = Configs()
self.__colors = Colors()
self.__embeds = Embeds()
@commands.command(name='random', help=helper.HELP_RANDOM, description=helper.HELP_RANDOM_LONG)
async def random(self, ctx, arg: str) -> None:
@command(name='random', help=helper.HELP_RANDOM, description=helper.HELP_RANDOM_LONG)
async def random(self, ctx: Context, arg: str) -> None:
try:
arg = int(arg)
except:
embed = discord.Embed(
description=self.__config.ERROR_NUMBER,
colour=self.__config.COLOURS['red']
)
embed = self.__embeds.ERROR_NUMBER()
await ctx.send(embed=embed)
return
return None
if arg < 1:
a = arg
@@ -34,29 +34,21 @@ class Random(commands.Cog):
b = arg
x = randint(a, b)
embed = discord.Embed(
title=f'Random number between [{a, b}]',
description=x,
colour=self.__config.COLOURS['green']
)
embed = self.__embeds.RANDOM_NUMBER(a, b, x)
await ctx.send(embed=embed)
@commands.command(name='cara', help=helper.HELP_CARA, description=helper.HELP_CARA_LONG)
async def cara(self, ctx) -> None:
@command(name='cara', help=helper.HELP_CARA, description=helper.HELP_CARA_LONG)
async def cara(self, ctx: Context) -> None:
x = random()
if x < 0.5:
result = 'cara'
else:
result = 'coroa'
embed = discord.Embed(
title='Cara Cora',
description=f'Result: {result}',
colour=self.__config.COLOURS['green']
)
embed = self.__embeds.CARA_COROA(result)
await ctx.send(embed=embed)
@commands.command(name='choose', help=helper.HELP_CHOOSE, description=helper.HELP_CHOOSE_LONG)
@command(name='choose', help=helper.HELP_CHOOSE, description=helper.HELP_CHOOSE_LONG)
async def choose(self, ctx, *args: str) -> None:
try:
user_input = " ".join(args)
@@ -64,18 +56,10 @@ class Random(commands.Cog):
index = randint(0, len(itens)-1)
embed = discord.Embed(
title='Choose something',
description=itens[index],
colour=self.__config.COLOURS['green']
)
embed = self.__embeds.CHOSEN_THING(itens[index])
await ctx.send(embed=embed)
except:
embed = discord.Embed(
title='Choose something.',
description=f'Error: Use {self.__config.BOT_PREFIX}help choose to understand this command.',
colour=self.__config.COLOURS['red']
)
embed = self.__embeds.BAD_CHOOSE_USE()
await ctx.send(embed=embed)