mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Adding some typing to the project and rebuilding the Downloader
This commit is contained in:
@@ -59,7 +59,7 @@ class Control(commands.Cog):
|
||||
if not my_error:
|
||||
raise error
|
||||
else:
|
||||
print(error)
|
||||
print(f'DEVELOPER NOTE -> Comand Error: {error}')
|
||||
embed = discord.Embed(
|
||||
title=config.ERROR_TITLE,
|
||||
description=config.UNKNOWN_ERROR,
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import discord
|
||||
from typing import Dict
|
||||
from discord import Guild, Client, Embed
|
||||
from discord.ext import commands
|
||||
|
||||
from discord.ext.commands import Context
|
||||
from config import config
|
||||
from config import help
|
||||
from vulkan.music.Player import Player
|
||||
from vulkan.music.utils import *
|
||||
from vulkan.music.utils import is_connected
|
||||
|
||||
|
||||
class Music(commands.Cog):
|
||||
def __init__(self, bot) -> None:
|
||||
self.__guilds = {}
|
||||
self.__bot: discord.Client = bot
|
||||
self.__guilds: Dict[Guild, Player] = {}
|
||||
self.__bot: Client = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self) -> None:
|
||||
@@ -23,29 +24,29 @@ class Music(commands.Cog):
|
||||
print(f'Player for guild {guild.name} created')
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_join(self, guild) -> None:
|
||||
async def on_guild_join(self, guild: 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:
|
||||
async def on_guild_remove(self, guild: 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:
|
||||
async def play(self, ctx: Context, *args) -> None:
|
||||
track = " ".join(args)
|
||||
requester = ctx.author.name
|
||||
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
await self.__send_embed(ctx, config.ERROR_TITLE, config.NO_GUILD, 'red')
|
||||
return
|
||||
|
||||
if is_connected(ctx) == None:
|
||||
if is_connected(ctx) is None:
|
||||
success = await player.connect(ctx)
|
||||
if success == False:
|
||||
await self.__send_embed(ctx, config.IMPOSSIBLE_MOVE, config.NO_CHANNEL, 'red')
|
||||
@@ -54,34 +55,34 @@ class Music(commands.Cog):
|
||||
await player.play(ctx, track, requester)
|
||||
|
||||
@commands.command(name="queue", help=help.HELP_QUEUE, description=help.HELP_QUEUE_LONG, aliases=['q', 'fila'])
|
||||
async def queue(self, ctx) -> None:
|
||||
async def queue(self, ctx: Context) -> None:
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
return
|
||||
|
||||
embed = await player.queue()
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@commands.command(name="skip", help=help.HELP_SKIP, description=help.HELP_SKIP_LONG, aliases=['s', 'pular'])
|
||||
async def skip(self, ctx) -> None:
|
||||
async def skip(self, ctx: Context) -> None:
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
return
|
||||
else:
|
||||
await player.skip(ctx)
|
||||
|
||||
@commands.command(name='stop', help=help.HELP_STOP, description=help.HELP_STOP_LONG, aliases=['parar'])
|
||||
async def stop(self, ctx) -> None:
|
||||
async def stop(self, ctx: Context) -> None:
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
return
|
||||
else:
|
||||
await player.stop()
|
||||
|
||||
@commands.command(name='pause', help=help.HELP_PAUSE, description=help.HELP_PAUSE_LONG, aliases=['pausar'])
|
||||
async def pause(self, ctx) -> None:
|
||||
async def pause(self, ctx: Context) -> None:
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
return
|
||||
else:
|
||||
success = await player.pause()
|
||||
@@ -89,9 +90,9 @@ class Music(commands.Cog):
|
||||
await self.__send_embed(ctx, config.SONG_PLAYER, config.SONG_PAUSED, 'blue')
|
||||
|
||||
@commands.command(name='resume', help=help.HELP_RESUME, description=help.HELP_RESUME_LONG, aliases=['soltar'])
|
||||
async def resume(self, ctx) -> None:
|
||||
async def resume(self, ctx: Context) -> None:
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
return
|
||||
else:
|
||||
success = await player.resume()
|
||||
@@ -99,12 +100,12 @@ class Music(commands.Cog):
|
||||
await self.__send_embed(ctx, config.SONG_PLAYER, config.SONG_RESUMED, 'blue')
|
||||
|
||||
@commands.command(name='prev', help=help.HELP_PREV, description=help.HELP_PREV_LONG, aliases=['anterior'])
|
||||
async def prev(self, ctx) -> None:
|
||||
async def prev(self, ctx: Context) -> None:
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
return
|
||||
|
||||
if is_connected(ctx) == None:
|
||||
if is_connected(ctx) is None:
|
||||
success = await player.connect(ctx)
|
||||
if success == False:
|
||||
await self.__send_embed(ctx, config.IMPOSSIBLE_MOVE, config.NO_CHANNEL, 'red')
|
||||
@@ -113,35 +114,35 @@ class Music(commands.Cog):
|
||||
await player.play_prev(ctx)
|
||||
|
||||
@commands.command(name='history', help=help.HELP_HISTORY, description=help.HELP_HISTORY_LONG, aliases=['historico'])
|
||||
async def history(self, ctx) -> None:
|
||||
async def history(self, ctx: Context) -> None:
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
return
|
||||
else:
|
||||
embed = player.history()
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@commands.command(name='loop', help=help.HELP_LOOP, description=help.HELP_LOOP_LONG, aliases=['l', 'repeat'])
|
||||
async def loop(self, ctx, args: str) -> None:
|
||||
async def loop(self, ctx: Context, args: str) -> None:
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
return
|
||||
else:
|
||||
description = await player.loop(args)
|
||||
await self.__send_embed(ctx, config.SONG_PLAYER, description, 'blue')
|
||||
|
||||
@commands.command(name='clear', help=help.HELP_CLEAR, description=help.HELP_CLEAR_LONG, aliases=['c', 'limpar'])
|
||||
async def clear(self, ctx) -> None:
|
||||
async def clear(self, ctx: Context) -> None:
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
return
|
||||
else:
|
||||
await player.clear()
|
||||
|
||||
@commands.command(name='np', help=help.HELP_NP, description=help.HELP_NP_LONG, aliases=['playing', 'now'])
|
||||
async def now_playing(self, ctx) -> None:
|
||||
async def now_playing(self, ctx: Context) -> None:
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
return
|
||||
else:
|
||||
embed = await player.now_playing()
|
||||
@@ -149,34 +150,34 @@ class Music(commands.Cog):
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@commands.command(name='shuffle', help=help.HELP_SHUFFLE, description=help.HELP_SHUFFLE_LONG, aliases=['aleatorio'])
|
||||
async def shuffle(self, ctx) -> None:
|
||||
async def shuffle(self, ctx: Context) -> None:
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
return
|
||||
else:
|
||||
description = await player.shuffle()
|
||||
await self.__send_embed(ctx, config.SONG_PLAYER, description, 'blue')
|
||||
|
||||
@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:
|
||||
async def move(self, ctx: Context, pos1, pos2='1') -> None:
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
return
|
||||
else:
|
||||
description = await player.move(pos1, pos2)
|
||||
await self.__send_embed(ctx, config.SONG_PLAYER, description, 'blue')
|
||||
|
||||
@commands.command(name='remove', help=help.HELP_REMOVE, description=help.HELP_REMOVE_LONG, aliases=['remover'])
|
||||
async def remove(self, ctx, position) -> None:
|
||||
async def remove(self, ctx: Context, position) -> None:
|
||||
player = self.__get_player(ctx)
|
||||
if player == None:
|
||||
if player is None:
|
||||
return
|
||||
else:
|
||||
description = await player.remove(position)
|
||||
await self.__send_embed(ctx, config.SONG_PLAYER, description, 'blue')
|
||||
|
||||
@commands.command(name='reset', help=help.HELP_RESET, description=help.HELP_RESET_LONG, aliases=['resetar'])
|
||||
async def reset(self, ctx) -> None:
|
||||
async def reset(self, ctx: Context) -> None:
|
||||
player = self.__get_player(ctx)
|
||||
try:
|
||||
await player.force_stop()
|
||||
@@ -191,20 +192,20 @@ class Music(commands.Cog):
|
||||
player = self.__get_player(ctx)
|
||||
print(f'Player for guild {ctx.guild} created')
|
||||
|
||||
async def __send_embed(self, ctx, title='', description='', colour='grey') -> None:
|
||||
async def __send_embed(self, ctx: Context, title='', description='', colour='grey') -> None:
|
||||
try:
|
||||
colour = config.COLOURS[colour]
|
||||
except:
|
||||
colour = config.COLOURS['grey']
|
||||
|
||||
embedvc = discord.Embed(
|
||||
embedvc = Embed(
|
||||
title=title,
|
||||
description=description,
|
||||
colour=colour
|
||||
)
|
||||
await ctx.send(embed=embedvc)
|
||||
|
||||
async def __clean_messages(self, ctx) -> None:
|
||||
async def __clean_messages(self, ctx: Context) -> None:
|
||||
last_messages = await ctx.channel.history(limit=5).flatten()
|
||||
|
||||
for message in last_messages:
|
||||
@@ -219,7 +220,7 @@ class Music(commands.Cog):
|
||||
except:
|
||||
continue
|
||||
|
||||
def __get_player(self, ctx) -> Player:
|
||||
def __get_player(self, ctx: Context) -> Player:
|
||||
try:
|
||||
return self.__guilds[ctx.guild]
|
||||
except:
|
||||
|
||||
Reference in New Issue
Block a user