diff --git a/vulkan/commands/Control.py b/vulkan/commands/Control.py index 9ddf769..14bf07a 100644 --- a/vulkan/commands/Control.py +++ b/vulkan/commands/Control.py @@ -3,6 +3,7 @@ from discord import Client from discord.ext.commands.errors import CommandNotFound, MissingRequiredArgument from discord.ext import commands from config import config +from config import help class Control(commands.Cog): @@ -11,11 +12,12 @@ class Control(commands.Cog): def __init__(self, bot: Client): self.__bot = bot self.__comandos = { - 'MUSIC': ['resume', 'pause', 'loop', 'stop', 'skip', 'play', 'queue', 'clear', 'np', 'shuffle', 'move', 'remove', 'reset'], - 'WARFRAME': ['warframe'], - 'RANDOM': ['escolha', 'cara', 'random'], - 'HELP': ['help'], - 'OTHERS': ['frase'] + 'MUSIC': ['resume', 'pause', 'loop', 'stop', + 'skip', 'play', 'queue', 'clear', + 'np', 'shuffle', 'move', 'remove', + 'reset', 'prev', 'history'], + 'RANDOM': ['choose', 'cara', 'random'] + } @commands.Cog.listener() @@ -42,6 +44,7 @@ class Control(commands.Cog): ) await ctx.send(embed=embed) else: + print(error) embed = discord.Embed( title=config.ERROR_TITLE, description=config.UNKNOWN_ERROR, @@ -49,37 +52,70 @@ class Control(commands.Cog): ) await ctx.send(embed=embed) - @commands.command(name="help", help=config.HELP_HELP, aliases=['h', 'ajuda']) - async def help_msg(self, ctx): - helptxt = '' - help_music = '🎧 `MUSIC`\n' - help_random = '🎲 `RANDOM`\n' - help_warframe = '🎮 `WARFRAME`\n' - help_help = '👾 `HELP`\n' - help_others = '🕹️ `OTHERS`\n' + @commands.command(name="help", help=help.HELP_HELP, description=help.HELP_HELP_LONG, aliases=['h', 'ajuda']) + async def help_msg(self, ctx, command_help=''): + if command_help != '': + for command in self.__bot.commands: + if command.name == command_help: + txt = command.description if command.description else command.help - for command in self.__bot.commands: - if command.name in self.__comandos['MUSIC']: - help_music += f'**{command}** - {command.help}\n' - elif command.name in self.__comandos['HELP']: - help_help += f'**{command}** - {command.help}\n' - elif command.name in self.__comandos['OTHERS']: - help_others += f'**{command}** - {command.help}\n' - elif command.name in self.__comandos['WARFRAME']: - help_warframe += f'**{command}** - {command.help}\n' - else: - help_random += f'**{command}** - {command.help}\n' + embedhelp = discord.Embed( + title=f'**Description of {command_help}** command', + description=txt, + colour=config.COLOURS['blue'] + ) - helptxt = f'{help_music}\n{help_warframe}\n{help_random}\n{help_others}\n{help_help}' + await ctx.send(embed=embedhelp) + return - embedhelp = discord.Embed( - title=f'**Available Commands of {self.__bot.user.name}**', - description=helptxt, + embedhelp = discord.Embed( + title='Command Help', + description=f'Command {command_help} Not Found', + colour=config.COLOURS['red'] + ) + + await ctx.send(embed=embedhelp) + else: + + helptxt = '' + help_music = '🎧 `MUSIC`\n' + help_random = '🎲 `RANDOM`\n' + help_help = '👾 `HELP`\n' + + for command in self.__bot.commands: + if command.name in self.__comandos['MUSIC']: + help_music += f'**{command}** - {command.help}\n' + + elif command.name in self.__comandos['RANDOM']: + help_random += f'**{command}** - {command.help}\n' + + else: + help_help += f'**{command}** - {command.help}\n' + + helptxt = f'\n{help_music}\n{help_help}\n{help_random}' + + embedhelp = discord.Embed( + title=f'**Available Commands of {self.__bot.user.name}**', + description=helptxt, + colour=config.COLOURS['blue'] + ) + + embedhelp.set_thumbnail(url=self.__bot.user.avatar_url) + await ctx.send(embed=embedhelp) + + @commands.command(name='invite', help=help.HELP_INVITE, description=help.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 = config.INVITE_MESSAGE.format(invite_url) + + embed = discord.Embed( + title="Invite Vulkan", + description=txt, colour=config.COLOURS['blue'] ) - embedhelp.set_thumbnail(url=self.__bot.user.avatar_url) - await ctx.send(embed=embedhelp) + await ctx.send(embed=embed) def setup(bot): diff --git a/vulkan/commands/Music.py b/vulkan/commands/Music.py index e7935b8..9b893d4 100644 --- a/vulkan/commands/Music.py +++ b/vulkan/commands/Music.py @@ -2,6 +2,7 @@ import discord from discord.ext import commands from config import config +from config import help from vulkan.music.Player import Player from vulkan.music.utils import * @@ -13,10 +14,25 @@ class Music(commands.Cog): @commands.Cog.listener() async def on_ready(self) -> None: + """Load a player for each guild that the Bot are""" for guild in self.__bot.guilds: self.__guilds[guild] = Player(self.__bot, guild) + print(f'Player for guild {guild.name} created') - @commands.command(name="play", help=config.HELP_PLAY, aliases=['p', 'tocar']) + @commands.Cog.listener() + async def on_guild_join(self, guild) -> None: + """Load a player when joining a guild""" + self.__guilds[guild] = Player(self.__bot, guild) + print(f'Player for guild {guild.name} created') + + @commands.Cog.listener() + async def on_guild_remove(self, guild) -> None: + """Removes the player of the guild if banned""" + if guild in self.__guilds.keys(): + self.__guilds.pop(guild, None) + print(f'Player for guild {guild.name} destroyed') + + @commands.command(name="play", help=help.HELP_PLAY, description=help.HELP_PLAY_LONG, aliases=['p', 'tocar']) async def play(self, ctx, *args) -> None: track = " ".join(args) requester = ctx.author.name @@ -29,12 +45,12 @@ class Music(commands.Cog): if is_connected(ctx) == None: success = await player.connect(ctx) if success == False: - await self.__send_embed(ctx, config.ERROR_TITLE, config.NO_CHANNEL, 'red') + await self.__send_embed(ctx, config.IMPOSSIBLE_MOVE, config.NO_CHANNEL, 'red') return await player.play(ctx, track, requester) - @commands.command(name="queue", help=config.HELP_QUEUE, aliases=['q', 'fila']) + @commands.command(name="queue", help=help.HELP_QUEUE, description=help.HELP_QUEUE_LONG, aliases=['q', 'fila']) async def queue(self, ctx) -> None: player = self.__get_player(ctx) if player == None: @@ -43,7 +59,7 @@ class Music(commands.Cog): embed = await player.queue() await ctx.send(embed=embed) - @commands.command(name="skip", help=config.HELP_SKIP, aliases=['s', 'pular']) + @commands.command(name="skip", help=help.HELP_SKIP, description=help.HELP_SKIP_LONG, aliases=['s', 'pular']) async def skip(self, ctx) -> None: player = self.__get_player(ctx) if player == None: @@ -51,7 +67,7 @@ class Music(commands.Cog): else: await player.skip(ctx) - @commands.command(name='stop', help=config.HELP_STOP, aliases=['parar']) + @commands.command(name='stop', help=help.HELP_STOP, description=help.HELP_STOP_LONG, aliases=['parar']) async def stop(self, ctx) -> None: player = self.__get_player(ctx) if player == None: @@ -59,7 +75,7 @@ class Music(commands.Cog): else: await player.stop() - @commands.command(name='pause', help=config.HELP_PAUSE, aliases=['pausar']) + @commands.command(name='pause', help=help.HELP_PAUSE, description=help.HELP_PAUSE_LONG, aliases=['pausar']) async def pause(self, ctx) -> None: player = self.__get_player(ctx) if player == None: @@ -69,7 +85,7 @@ class Music(commands.Cog): if success: await self.__send_embed(ctx, config.SONG_PLAYER, config.SONG_PAUSED, 'blue') - @commands.command(name='resume', help=config.HELP_RESUME, aliases=['soltar']) + @commands.command(name='resume', help=help.HELP_RESUME, description=help.HELP_RESUME_LONG, aliases=['soltar']) async def resume(self, ctx) -> None: player = self.__get_player(ctx) if player == None: @@ -79,7 +95,7 @@ class Music(commands.Cog): if success: await self.__send_embed(ctx, config.SONG_PLAYER, config.SONG_RESUMED, 'blue') - @commands.command(name='prev', help=config.HELP_PREV, aliases=['anterior']) + @commands.command(name='prev', help=help.HELP_PREV, description=help.HELP_PREV_LONG, aliases=['anterior']) async def prev(self, ctx) -> None: player = self.__get_player(ctx) if player == None: @@ -88,12 +104,12 @@ class Music(commands.Cog): if is_connected(ctx) == None: success = await player.connect(ctx) if success == False: - await self.__send_embed(ctx, config.ERROR_TITLE, config.NO_CHANNEL, 'red') + await self.__send_embed(ctx, config.IMPOSSIBLE_MOVE, config.NO_CHANNEL, 'red') return await player.play_prev(ctx) - @commands.command(name='history', help=config.HELP_HISTORY, aliases=['historico']) + @commands.command(name='history', help=help.HELP_HISTORY, description=help.HELP_HISTORY_LONG, aliases=['historico']) async def history(self, ctx) -> None: player = self.__get_player(ctx) if player == None: @@ -102,7 +118,7 @@ class Music(commands.Cog): embed = player.history() await ctx.send(embed=embed) - @commands.command(name='loop', help=config.HELP_LOOP, aliases=['l', 'repeat']) + @commands.command(name='loop', help=help.HELP_LOOP, description=help.HELP_LOOP_LONG, aliases=['l', 'repeat']) async def loop(self, ctx, args: str) -> None: player = self.__get_player(ctx) if player == None: @@ -111,7 +127,7 @@ class Music(commands.Cog): description = await player.loop(args) await self.__send_embed(ctx, config.SONG_PLAYER, description, 'blue') - @commands.command(name='clear', help=config.HELP_CLEAR, aliases=['c', 'limpar']) + @commands.command(name='clear', help=help.HELP_CLEAR, description=help.HELP_CLEAR_LONG, aliases=['c', 'limpar']) async def clear(self, ctx) -> None: player = self.__get_player(ctx) if player == None: @@ -119,7 +135,7 @@ class Music(commands.Cog): else: await player.clear() - @commands.command(name='np', help=config.HELP_NP, aliases=['playing', 'now']) + @commands.command(name='np', help=help.HELP_NP, description=help.HELP_NP_LONG, aliases=['playing', 'now']) async def now_playing(self, ctx) -> None: player = self.__get_player(ctx) if player == None: @@ -129,7 +145,7 @@ class Music(commands.Cog): await self.__clean_messages(ctx) await ctx.send(embed=embed) - @commands.command(name='shuffle', help=config.HELP_SHUFFLE, aliases=['aleatorio']) + @commands.command(name='shuffle', help=help.HELP_SHUFFLE, description=help.HELP_SHUFFLE_LONG, aliases=['aleatorio']) async def shuffle(self, ctx) -> None: player = self.__get_player(ctx) if player == None: @@ -138,7 +154,7 @@ class Music(commands.Cog): description = await player.shuffle() await self.__send_embed(ctx, config.SONG_PLAYER, description, 'blue') - @commands.command(name='move', help=config.HELP_MOVE, aliases=['m', 'mover']) + @commands.command(name='move', help=help.HELP_MOVE, description=help.HELP_MOVE_LONG, aliases=['m', 'mover']) async def move(self, ctx, pos1, pos2='1') -> None: player = self.__get_player(ctx) if player == None: @@ -147,7 +163,7 @@ class Music(commands.Cog): description = await player.move(pos1, pos2) await self.__send_embed(ctx, config.SONG_PLAYER, description, 'blue') - @commands.command(name='remove', help=config.HELP_REMOVE, aliases=['remover']) + @commands.command(name='remove', help=help.HELP_REMOVE, description=help.HELP_REMOVE_LONG, aliases=['remover']) async def remove(self, ctx, position) -> None: player = self.__get_player(ctx) if player == None: @@ -156,7 +172,7 @@ class Music(commands.Cog): description = await player.remove(position) await self.__send_embed(ctx, config.SONG_PLAYER, description, 'blue') - @commands.command(name='reset', help=config.HELP_RESET, aliases=['resetar']) + @commands.command(name='reset', help=help.HELP_RESET, description=help.HELP_RESET_LONG, aliases=['resetar']) async def reset(self, ctx) -> None: player = self.__get_player(ctx) if player != None: @@ -185,7 +201,9 @@ class Music(commands.Cog): if message.author == self.__bot.user: if len(message.embeds) > 0: embed = message.embeds[0] - if embed.title in config.SONGS_PLAYING_TITLES: + fields = embed.fields + + if fields != discord.Embed.EmptyEmbed: await message.delete() except: continue diff --git a/vulkan/commands/Random.py b/vulkan/commands/Random.py index 546fefa..2f7ac34 100644 --- a/vulkan/commands/Random.py +++ b/vulkan/commands/Random.py @@ -2,6 +2,7 @@ from random import randint, random import discord from discord.ext import commands from config import config +from config import help class Random(commands.Cog): @@ -10,14 +11,14 @@ class Random(commands.Cog): def __init__(self, bot): self.__bot = bot - @commands.command(name='random', help=config.HELP_RANDOM) - async def random(self, ctx, arg: str): + @commands.command(name='random', help=help.HELP_RANDOM, description=help.HELP_RANDOM_LONG) + async def random(self, ctx, arg: str) -> None: try: arg = int(arg) - except Exception as e: + except: embed = discord.Embed( - description='Manda um número aí ow animal', + description=config.ERROR_NUMBER, colour=config.COLOURS['red'] ) await ctx.send(embed=embed) @@ -32,14 +33,14 @@ class Random(commands.Cog): x = randint(a, b) embed = discord.Embed( - title=f'Número Aleatório entre {a, b}', + title=f'Random number between [{a, b}]', description=x, colour=config.COLOURS['green'] ) await ctx.send(embed=embed) - @commands.command(name='cara', help=config.HELP_CARA) - async def cara(self, ctx): + @commands.command(name='cara', help=help.HELP_CARA, description=help.HELP_CARA_LONG) + async def cara(self, ctx) -> None: x = random() if x < 0.5: result = 'cara' @@ -48,13 +49,13 @@ class Random(commands.Cog): embed = discord.Embed( title='Cara Cora', - description=f'Resultado: {result}', + description=f'Result: {result}', colour=config.COLOURS['green'] ) await ctx.send(embed=embed) - @commands.command(name='escolha', help=config.HELP_ESCOLHA) - async def escolher(self, ctx, *args: str): + @commands.command(name='choose', help=help.HELP_CHOOSE, description=help.HELP_CHOOSE_LONG) + async def choose(self, ctx, *args: str) -> None: try: user_input = " ".join(args) itens = user_input.split(sep=',') @@ -62,16 +63,16 @@ class Random(commands.Cog): index = randint(0, len(itens)-1) embed = discord.Embed( - title='Escolha de algo', + title='Choose something', description=itens[index], colour=config.COLOURS['green'] ) await ctx.send(embed=embed) - except Exception as e: + except: embed = discord.Embed( - title='Escolha de algo', - description='Erro: Envie várias coisas separadas por vírgula', - colour=config.COLOURS['green'] + title='Choose something.', + description=f'Error: Use {config.BOT_PREFIX}help choose to understand this command.', + colour=config.COLOURS['red'] ) await ctx.send(embed=embed)