Chaging config and help to class

This commit is contained in:
Rafael Vargas
2022-03-21 21:51:40 -04:00
parent 5c4d09bf9d
commit 14705569c1
12 changed files with 287 additions and 264 deletions

View File

@@ -2,8 +2,10 @@ import discord
from discord import Client
from discord.ext.commands.errors import CommandNotFound, MissingRequiredArgument, UserInputError
from discord.ext import commands
from config import config
from config import help
from config.Config import Config
from config.Helper import Helper
helper = Helper()
class Control(commands.Cog):
@@ -11,6 +13,7 @@ class Control(commands.Cog):
def __init__(self, bot: Client):
self.__bot = bot
self.__config = Config()
self.__comandos = {
'MUSIC': ['resume', 'pause', 'loop', 'stop',
'skip', 'play', 'queue', 'clear',
@@ -22,36 +25,36 @@ class Control(commands.Cog):
@commands.Cog.listener()
async def on_ready(self):
print(config.STARTUP_MESSAGE)
await self.__bot.change_presence(status=discord.Status.online, activity=discord.Game(name=f"Vulkan | {config.BOT_PREFIX}help"))
print(config.STARTUP_COMPLETE_MESSAGE)
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)
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if isinstance(error, MissingRequiredArgument):
embed = discord.Embed(
title=config.ERROR_TITLE,
description=config.ERROR_MISSING_ARGUMENTS,
colour=config.COLOURS['black']
title=self.__config.ERROR_TITLE,
description=self.__config.ERROR_MISSING_ARGUMENTS,
colour=self.__config.COLOURS['black']
)
await ctx.send(embed=embed)
elif isinstance(error, CommandNotFound):
embed = discord.Embed(
title=config.ERROR_TITLE,
description=config.COMMAND_NOT_FOUND,
colour=config.COLOURS['black']
title=self.__config.ERROR_TITLE,
description=self.__config.COMMAND_NOT_FOUND,
colour=self.__config.COLOURS['black']
)
await ctx.send(embed=embed)
elif isinstance(error, UserInputError):
my_error = False
if len(error.args) > 0:
for arg in error.args:
if arg == config.MY_ERROR_BAD_COMMAND:
if arg == self.__config.MY_ERROR_BAD_COMMAND:
embed = discord.Embed(
title=config.BAD_COMMAND_TITLE,
description=config.BAD_COMMAND,
colour=config.COLOURS['black']
title=self.__config.BAD_COMMAND_TITLE,
description=self.__config.BAD_COMMAND,
colour=self.__config.COLOURS['black']
)
await ctx.send(embed=embed)
my_error = True
@@ -61,13 +64,13 @@ class Control(commands.Cog):
else:
print(f'DEVELOPER NOTE -> Comand Error: {error}')
embed = discord.Embed(
title=config.ERROR_TITLE,
description=config.UNKNOWN_ERROR,
colour=config.COLOURS['red']
title=self.__config.ERROR_TITLE,
description=self.__config.UNKNOWN_ERROR,
colour=self.__config.COLOURS['red']
)
await ctx.send(embed=embed)
@commands.command(name="help", help=help.HELP_HELP, description=help.HELP_HELP_LONG, aliases=['h', 'ajuda'])
@commands.command(name="help", help=helper.HELP_HELP, description=helper.HELP_HELP_LONG, aliases=['h', 'ajuda'])
async def help_msg(self, ctx, command_help=''):
if command_help != '':
for command in self.__bot.commands:
@@ -77,7 +80,7 @@ class Control(commands.Cog):
embedhelp = discord.Embed(
title=f'**Description of {command_help}** command',
description=txt,
colour=config.COLOURS['blue']
colour=self.__config.COLOURS['blue']
)
await ctx.send(embed=embedhelp)
@@ -86,7 +89,7 @@ class Control(commands.Cog):
embedhelp = discord.Embed(
title='Command Help',
description=f'Command {command_help} Not Found',
colour=config.COLOURS['red']
colour=self.__config.COLOURS['red']
)
await ctx.send(embed=embedhelp)
@@ -108,26 +111,26 @@ class Control(commands.Cog):
help_help += f'**{command}** - {command.help}\n'
helptxt = f'\n{help_music}\n{help_help}\n{help_random}'
helptxt += f'\n\nType {config.BOT_PREFIX}help "command" for more information about the command chosen'
helptxt += f'\n\nType {self.__config.BOT_PREFIX}help "command" for more information about the command chosen'
embedhelp = discord.Embed(
title=f'**Available Commands of {self.__bot.user.name}**',
description=helptxt,
colour=config.COLOURS['blue']
colour=self.__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)
@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 = config.INVITE_MESSAGE.format(invite_url)
txt = self.__config.INVITE_MESSAGE.format(invite_url)
embed = discord.Embed(
title="Invite Vulkan",
description=txt,
colour=config.COLOURS['blue']
colour=self.__config.COLOURS['blue']
)
await ctx.send(embed=embed)

View File

@@ -2,17 +2,20 @@ 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 config.Config import Config
from config.Helper import Helper
from vulkan.music.Player import Player
from vulkan.music.utils import is_connected
from vulkan.controllers.SkipController import SkipHandler
helper = Helper()
class Music(commands.Cog):
def __init__(self, bot) -> None:
self.__guilds: Dict[Guild, Player] = {}
self.__bot: Client = bot
self.__config = Config()
@commands.Cog.listener()
async def on_ready(self) -> None:
@@ -37,25 +40,25 @@ class Music(commands.Cog):
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'])
@commands.command(name="play", help=helper.HELP_PLAY, description=helper.HELP_PLAY_LONG, aliases=['p', 'tocar'])
async def play(self, ctx: Context, *args) -> None:
track = " ".join(args)
requester = ctx.author.name
player = self.__get_player(ctx)
if player is None:
await self.__send_embed(ctx, config.ERROR_TITLE, config.NO_GUILD, 'red')
await self.__send_embed(ctx, self.__config.ERROR_TITLE, self.__config.NO_GUILD, 'red')
return
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')
await self.__send_embed(ctx, self.__config.IMPOSSIBLE_MOVE, self.__config.NO_CHANNEL, 'red')
return
await player.play(ctx, track, requester)
@commands.command(name="queue", help=help.HELP_QUEUE, description=help.HELP_QUEUE_LONG, aliases=['q', 'fila'])
@commands.command(name="queue", help=helper.HELP_QUEUE, description=helper.HELP_QUEUE_LONG, aliases=['q', 'fila'])
async def queue(self, ctx: Context) -> None:
player = self.__get_player(ctx)
if player is None:
@@ -64,24 +67,20 @@ class Music(commands.Cog):
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'])
@commands.command(name="skip", help=helper.HELP_SKIP, description=helper.HELP_SKIP_LONG, aliases=['s', 'pular'])
async def skip(self, ctx: Context) -> None:
print(ctx.bot == self.__bot)
handler = SkipHandler(ctx, self.__bot)
await handler.run()
@commands.command(name='stop', help=help.HELP_STOP, description=help.HELP_STOP_LONG, aliases=['parar'])
@commands.command(name='stop', help=helper.HELP_STOP, description=helper.HELP_STOP_LONG, aliases=['parar'])
async def stop(self, ctx: Context) -> None:
print(ctx.bot == self.__bot)
player = self.__get_player(ctx)
if player is None:
return
else:
await player.stop()
@commands.command(name='pause', help=help.HELP_PAUSE, description=help.HELP_PAUSE_LONG, aliases=['pausar'])
@commands.command(name='pause', help=helper.HELP_PAUSE, description=helper.HELP_PAUSE_LONG, aliases=['pausar'])
async def pause(self, ctx: Context) -> None:
player = self.__get_player(ctx)
if player is None:
@@ -89,9 +88,9 @@ class Music(commands.Cog):
else:
success = await player.pause()
if success:
await self.__send_embed(ctx, config.SONG_PLAYER, config.SONG_PAUSED, 'blue')
await self.__send_embed(ctx, self.__config.SONG_PLAYER, self.__config.SONG_PAUSED, 'blue')
@commands.command(name='resume', help=help.HELP_RESUME, description=help.HELP_RESUME_LONG, aliases=['soltar'])
@commands.command(name='resume', help=helper.HELP_RESUME, description=helper.HELP_RESUME_LONG, aliases=['soltar'])
async def resume(self, ctx: Context) -> None:
player = self.__get_player(ctx)
if player is None:
@@ -99,9 +98,9 @@ class Music(commands.Cog):
else:
success = await player.resume()
if success:
await self.__send_embed(ctx, config.SONG_PLAYER, config.SONG_RESUMED, 'blue')
await self.__send_embed(ctx, self.__config.SONG_PLAYER, self.__config.SONG_RESUMED, 'blue')
@commands.command(name='prev', help=help.HELP_PREV, description=help.HELP_PREV_LONG, aliases=['anterior'])
@commands.command(name='prev', help=helper.HELP_PREV, description=helper.HELP_PREV_LONG, aliases=['anterior'])
async def prev(self, ctx: Context) -> None:
player = self.__get_player(ctx)
if player is None:
@@ -110,12 +109,12 @@ class Music(commands.Cog):
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')
await self.__send_embed(ctx, self.__config.IMPOSSIBLE_MOVE, self.__config.NO_CHANNEL, 'red')
return
await player.play_prev(ctx)
@commands.command(name='history', help=help.HELP_HISTORY, description=help.HELP_HISTORY_LONG, aliases=['historico'])
@commands.command(name='history', help=helper.HELP_HISTORY, description=helper.HELP_HISTORY_LONG, aliases=['historico'])
async def history(self, ctx: Context) -> None:
player = self.__get_player(ctx)
if player is None:
@@ -124,16 +123,16 @@ class Music(commands.Cog):
embed = player.history()
await ctx.send(embed=embed)
@commands.command(name='loop', help=help.HELP_LOOP, description=help.HELP_LOOP_LONG, aliases=['l', 'repeat'])
@commands.command(name='loop', help=helper.HELP_LOOP, description=helper.HELP_LOOP_LONG, aliases=['l', 'repeat'])
async def loop(self, ctx: Context, args: str) -> None:
player = self.__get_player(ctx)
if player is None:
return
else:
description = await player.loop(args)
await self.__send_embed(ctx, config.SONG_PLAYER, description, 'blue')
await self.__send_embed(ctx, self.__config.SONG_PLAYER, description, 'blue')
@commands.command(name='clear', help=help.HELP_CLEAR, description=help.HELP_CLEAR_LONG, aliases=['c', 'limpar'])
@commands.command(name='clear', help=helper.HELP_CLEAR, description=helper.HELP_CLEAR_LONG, aliases=['c', 'limpar'])
async def clear(self, ctx: Context) -> None:
player = self.__get_player(ctx)
if player is None:
@@ -141,7 +140,7 @@ class Music(commands.Cog):
else:
await player.clear()
@commands.command(name='np', help=help.HELP_NP, description=help.HELP_NP_LONG, aliases=['playing', 'now'])
@commands.command(name='np', help=helper.HELP_NP, description=helper.HELP_NP_LONG, aliases=['playing', 'now'])
async def now_playing(self, ctx: Context) -> None:
player = self.__get_player(ctx)
if player is None:
@@ -151,34 +150,34 @@ class Music(commands.Cog):
await self.__clean_messages(ctx)
await ctx.send(embed=embed)
@commands.command(name='shuffle', help=help.HELP_SHUFFLE, description=help.HELP_SHUFFLE_LONG, aliases=['aleatorio'])
@commands.command(name='shuffle', help=helper.HELP_SHUFFLE, description=helper.HELP_SHUFFLE_LONG, aliases=['aleatorio'])
async def shuffle(self, ctx: Context) -> None:
player = self.__get_player(ctx)
if player is None:
return
else:
description = await player.shuffle()
await self.__send_embed(ctx, config.SONG_PLAYER, description, 'blue')
await self.__send_embed(ctx, self.__config.SONG_PLAYER, description, 'blue')
@commands.command(name='move', help=help.HELP_MOVE, description=help.HELP_MOVE_LONG, aliases=['m', 'mover'])
@commands.command(name='move', help=helper.HELP_MOVE, description=helper.HELP_MOVE_LONG, aliases=['m', 'mover'])
async def move(self, ctx: Context, pos1, pos2='1') -> None:
player = self.__get_player(ctx)
if player is None:
return
else:
description = await player.move(pos1, pos2)
await self.__send_embed(ctx, config.SONG_PLAYER, description, 'blue')
await self.__send_embed(ctx, self.__config.SONG_PLAYER, description, 'blue')
@commands.command(name='remove', help=help.HELP_REMOVE, description=help.HELP_REMOVE_LONG, aliases=['remover'])
@commands.command(name='remove', help=helper.HELP_REMOVE, description=helper.HELP_REMOVE_LONG, aliases=['remover'])
async def remove(self, ctx: Context, position) -> None:
player = self.__get_player(ctx)
if player is None:
return
else:
description = await player.remove(position)
await self.__send_embed(ctx, config.SONG_PLAYER, description, 'blue')
await self.__send_embed(ctx, self.__config.SONG_PLAYER, description, 'blue')
@commands.command(name='reset', help=help.HELP_RESET, description=help.HELP_RESET_LONG, aliases=['resetar'])
@commands.command(name='reset', help=helper.HELP_RESET, description=helper.HELP_RESET_LONG, aliases=['resetar'])
async def reset(self, ctx: Context) -> None:
player = self.__get_player(ctx)
try:
@@ -196,9 +195,9 @@ class Music(commands.Cog):
async def __send_embed(self, ctx: Context, title='', description='', colour='grey') -> None:
try:
colour = config.COLOURS[colour]
colour = self.__config.COLOURS[colour]
except:
colour = config.COLOURS['grey']
colour = self.__config.COLOURS['grey']
embedvc = Embed(
title=title,

View File

@@ -1,8 +1,10 @@
from random import randint, random
import discord
from discord.ext import commands
from config import config
from config import help
from config.Config import Config
from config.Helper import Helper
helper = Helper()
class Random(commands.Cog):
@@ -10,16 +12,17 @@ class Random(commands.Cog):
def __init__(self, bot):
self.__bot = bot
self.__config = Config()
@commands.command(name='random', help=help.HELP_RANDOM, description=help.HELP_RANDOM_LONG)
@commands.command(name='random', help=helper.HELP_RANDOM, description=helper.HELP_RANDOM_LONG)
async def random(self, ctx, arg: str) -> None:
try:
arg = int(arg)
except:
embed = discord.Embed(
description=config.ERROR_NUMBER,
colour=config.COLOURS['red']
description=self.__config.ERROR_NUMBER,
colour=self.__config.COLOURS['red']
)
await ctx.send(embed=embed)
return
@@ -35,11 +38,11 @@ class Random(commands.Cog):
embed = discord.Embed(
title=f'Random number between [{a, b}]',
description=x,
colour=config.COLOURS['green']
colour=self.__config.COLOURS['green']
)
await ctx.send(embed=embed)
@commands.command(name='cara', help=help.HELP_CARA, description=help.HELP_CARA_LONG)
@commands.command(name='cara', help=helper.HELP_CARA, description=helper.HELP_CARA_LONG)
async def cara(self, ctx) -> None:
x = random()
if x < 0.5:
@@ -50,11 +53,11 @@ class Random(commands.Cog):
embed = discord.Embed(
title='Cara Cora',
description=f'Result: {result}',
colour=config.COLOURS['green']
colour=self.__config.COLOURS['green']
)
await ctx.send(embed=embed)
@commands.command(name='choose', help=help.HELP_CHOOSE, description=help.HELP_CHOOSE_LONG)
@commands.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)
@@ -65,14 +68,14 @@ class Random(commands.Cog):
embed = discord.Embed(
title='Choose something',
description=itens[index],
colour=config.COLOURS['green']
colour=self.__config.COLOURS['green']
)
await ctx.send(embed=embed)
except:
embed = discord.Embed(
title='Choose something.',
description=f'Error: Use {config.BOT_PREFIX}help choose to understand this command.',
colour=config.COLOURS['red']
description=f'Error: Use {self.__config.BOT_PREFIX}help choose to understand this command.',
colour=self.__config.COLOURS['red']
)
await ctx.send(embed=embed)

View File

@@ -1,6 +1,6 @@
import asyncio
from typing import List
from config import config
from config.Config import Config
from yt_dlp import YoutubeDL
from concurrent.futures import ThreadPoolExecutor
from vulkan.music.Song import Song
@@ -9,6 +9,7 @@ from vulkan.music.utils import is_url, run_async
class Downloader():
"""Download musics direct URL and title or Source from Youtube using a music name or Youtube URL"""
config = Config()
__YDL_OPTIONS = {'format': 'bestaudio/best',
'default_search': 'auto',
'playliststart': 0,
@@ -30,6 +31,7 @@ class Downloader():
__BASE_URL = 'https://www.youtube.com/watch?v={}'
def __init__(self) -> None:
self.__config = Config()
self.__music_keys_only = ['resolution', 'fps', 'quality']
self.__not_extracted_keys_only = ['ie_key']
self.__not_extracted_not_keys = ['entries']
@@ -127,7 +129,7 @@ class Downloader():
# Creating a loop task to download each song
loop = asyncio.get_event_loop()
executor = ThreadPoolExecutor(max_workers=config.MAX_PRELOAD_SONGS)
executor = ThreadPoolExecutor(max_workers=self.__config.MAX_PRELOAD_SONGS)
fs = {loop.run_in_executor(executor, __download_func, song)}
await asyncio.wait(fs=fs, return_when=asyncio.ALL_COMPLETED)

View File

@@ -1,5 +1,5 @@
from discord.ext import commands
from config import config
from config.Config import Config
from discord import Client, Guild, FFmpegPCMAudio, Embed
from discord.ext.commands import Context
from datetime import timedelta
@@ -21,6 +21,7 @@ class Player(commands.Cog):
self.__timer = Timer(self.__timeout_handler)
self.__playing = False
self.__config = Config.Config()
# Flag to control if the player should stop totally the playing
self.__force_stop = False
@@ -79,9 +80,9 @@ class Player(commands.Cog):
links, provider = self.__searcher.search(track)
if provider == Provider.Unknown or links == None:
embed = Embed(
title=config.ERROR_TITLE,
description=config.INVALID_INPUT,
colours=config.COLOURS['blue'])
title=self.__config.ERROR_TITLE,
description=self.__config.INVALID_INPUT,
colours=self.__config.COLOURS['blue'])
await ctx.send(embed=embed)
return None
@@ -90,9 +91,9 @@ class Player(commands.Cog):
if len(links) == 0:
embed = Embed(
title=config.ERROR_TITLE,
title=self.__config.ERROR_TITLE,
description="This video is unavailable",
colours=config.COLOURS['blue'])
colours=self.__config.COLOURS['blue'])
await ctx.send(embed=embed)
return None
@@ -106,9 +107,9 @@ class Player(commands.Cog):
except Exception as e:
print(f'DEVELOPER NOTE -> Error while Downloading in Player: {e}')
embed = Embed(
title=config.ERROR_TITLE,
description=config.DOWNLOADING_ERROR,
colours=config.COLOURS['blue'])
title=self.__config.ERROR_TITLE,
description=self.__config.DOWNLOADING_ERROR,
colours=self.__config.COLOURS['blue'])
await ctx.send(embed=embed)
return
@@ -118,25 +119,25 @@ class Player(commands.Cog):
if song.problematic:
embed = Embed(
title=config.ERROR_TITLE,
description=config.DOWNLOADING_ERROR,
colours=config.COLOURS['blue'])
title=self.__config.ERROR_TITLE,
description=self.__config.DOWNLOADING_ERROR,
colours=self.__config.COLOURS['blue'])
await ctx.send(embed=embed)
return None
elif not self.__playing:
embed = Embed(
title=config.SONG_PLAYER,
description=config.SONG_ADDED.format(song.title),
colour=config.COLOURS['blue'])
title=self.__config.SONG_PLAYER,
description=self.__config.SONG_ADDED.format(song.title),
colour=self.__config.COLOURS['blue'])
await ctx.send(embed=embed)
else:
embed = self.__format_embed(song.info, config.SONG_ADDED_TWO, pos)
embed = self.__format_embed(song.info, self.__config.SONG_ADDED_TWO, pos)
await ctx.send(embed=embed)
else:
embed = Embed(
title=config.SONG_PLAYER,
description=config.SONGS_ADDED.format(songs_quant),
colour=config.COLOURS['blue'])
title=self.__config.SONG_PLAYER,
description=self.__config.SONGS_ADDED.format(songs_quant),
colour=self.__config.COLOURS['blue'])
await ctx.send(embed=embed)
if not self.__playing:
@@ -147,9 +148,9 @@ class Player(commands.Cog):
"""Stop the currently playing cycle, load the previous song and play"""
if self.__playlist.looping_one or self.__playlist.looping_all: # Do not allow play if loop
embed = Embed(
title=config.SONG_PLAYER,
description=config.LOOP_ON,
colour=config.COLOURS['blue']
title=self.__config.SONG_PLAYER,
description=self.__config.LOOP_ON,
colour=self.__config.COLOURS['blue']
)
await ctx.send(embed=embed)
return None
@@ -157,9 +158,9 @@ class Player(commands.Cog):
song = self.__playlist.prev_song() # Prepare the prev song to play again
if song == None:
embed = Embed(
title=config.SONG_PLAYER,
description=config.NOT_PREVIOUS,
colour=config.COLOURS['blue']
title=self.__config.SONG_PLAYER,
description=self.__config.NOT_PREVIOUS,
colour=self.__config.COLOURS['blue']
)
await ctx.send(embed=embed)
else:
@@ -174,20 +175,20 @@ class Player(commands.Cog):
async def queue(self) -> Embed:
if self.__playlist.looping_one:
info = self.__playlist.current.info
title = config.ONE_SONG_LOOPING
title = self.__config.ONE_SONG_LOOPING
return self.__format_embed(info, title)
songs_preload = self.__playlist.songs_to_preload
if len(songs_preload) == 0:
title = config.SONG_PLAYER
text = config.EMPTY_QUEUE
title = self.__config.SONG_PLAYER
text = self.__config.EMPTY_QUEUE
else:
if self.__playlist.looping_all:
title = config.ALL_SONGS_LOOPING
title = self.__config.ALL_SONGS_LOOPING
else:
title = config.QUEUE_TITLE
title = self.__config.QUEUE_TITLE
await self.__down.preload(songs_preload)
@@ -198,13 +199,13 @@ class Player(commands.Cog):
text = f'📜 Queue length: {total_songs} | ⌛ Duration: `{total_time}` downloaded \n\n'
for pos, song in enumerate(songs_preload, start=1):
song_name = song.title if song.title else config.SONG_DOWNLOADING
song_name = song.title if song.title else self.__config.SONG_DOWNLOADING
text += f"**`{pos}` - ** {song_name} - `{format_time(song.duration)}`\n"
embed = Embed(
title=title,
description=text,
colour=config.COLOURS['blue']
colour=self.__config.COLOURS['blue']
)
return embed
@@ -212,9 +213,9 @@ class Player(commands.Cog):
async def skip(self, ctx: Context) -> bool:
if self.__playlist.looping_one:
embed = Embed(
title=config.SONG_PLAYER,
description=config.LOOP_ON,
colour=config.COLOURS['blue']
title=self.__config.SONG_PLAYER,
description=self.__config.LOOP_ON,
colour=self.__config.COLOURS['blue']
)
await ctx.send(embed=embed)
return False
@@ -229,17 +230,17 @@ class Player(commands.Cog):
history = self.__playlist.songs_history
if len(history) == 0:
text = config.HISTORY_EMPTY
text = self.__config.HISTORY_EMPTY
else:
text = f'\n📜 History Length: {len(history)} | Max: {config.MAX_SONGS_HISTORY}\n'
text = f'\n📜 History Length: {len(history)} | Max: {self.__config.MAX_SONGS_HISTORY}\n'
for pos, song in enumerate(history, start=1):
text += f"**`{pos}` - ** {song.title} - `{format_time(song.duration)}`\n"
embed = Embed(
title=config.HISTORY_TITLE,
title=self.__config.HISTORY_TITLE,
description=text,
colour=config.COLOURS['blue']
colour=self.__config.COLOURS['blue']
)
return embed
@@ -285,7 +286,7 @@ class Player(commands.Cog):
async def loop(self, args: str) -> str:
args = args.lower()
if self.__playlist.current == None:
return config.PLAYER_NOT_PLAYING
return self.__config.PLAYER_NOT_PLAYING
if args == 'one':
description = self.__playlist.loop_one()
@@ -294,7 +295,7 @@ class Player(commands.Cog):
elif args == 'off':
description = self.__playlist.loop_off()
else:
raise commands.UserInputError(config.MY_ERROR_BAD_COMMAND)
raise commands.UserInputError(self.__config.MY_ERROR_BAD_COMMAND)
return description
@@ -304,16 +305,16 @@ class Player(commands.Cog):
async def now_playing(self) -> Embed:
if not self.__playing:
embed = Embed(
title=config.SONG_PLAYER,
description=config.PLAYER_NOT_PLAYING,
colour=config.COLOURS['blue']
title=self.__config.SONG_PLAYER,
description=self.__config.PLAYER_NOT_PLAYING,
colour=self.__config.COLOURS['blue']
)
return embed
if self.__playlist.looping_one:
title = config.ONE_SONG_LOOPING
title = self.__config.ONE_SONG_LOOPING
else:
title = config.SONG_PLAYING
title = self.__config.SONG_PLAYING
current_song = self.__playlist.current
embed = self.__format_embed(current_song.info, title)
@@ -326,20 +327,20 @@ class Player(commands.Cog):
songs = self.__playlist.songs_to_preload
await self.__down.preload(songs)
return config.SONGS_SHUFFLED
return self.__config.SONGS_SHUFFLED
except:
return config.ERROR_SHUFFLING
return self.__config.ERROR_SHUFFLING
async def move(self, pos1, pos2='1') -> str:
if not self.__playing:
return config.PLAYER_NOT_PLAYING
return self.__config.PLAYER_NOT_PLAYING
try:
pos1 = int(pos1)
pos2 = int(pos2)
except:
return config.ERROR_NUMBER
return self.__config.ERROR_NUMBER
result = self.__playlist.move_songs(pos1, pos2)
@@ -350,13 +351,13 @@ class Player(commands.Cog):
async def remove(self, position) -> str:
"""Remove a song from the queue in the position"""
if not self.__playing:
return config.PLAYER_NOT_PLAYING
return self.__config.PLAYER_NOT_PLAYING
try:
position = int(position)
except:
return config.ERROR_NUMBER
return self.__config.ERROR_NUMBER
result = self.__playlist.remove_song(position)
return result
@@ -366,14 +367,14 @@ class Player(commands.Cog):
embedvc = Embed(
title=title,
description=f"[{info['title']}]({info['original_url']})",
color=config.COLOURS['blue']
color=self.__config.COLOURS['blue']
)
embedvc.add_field(name=config.SONGINFO_UPLOADER,
embedvc.add_field(name=self.__config.SONGINFO_UPLOADER,
value=info['uploader'],
inline=False)
embedvc.add_field(name=config.SONGINFO_REQUESTER,
embedvc.add_field(name=self.__config.SONGINFO_REQUESTER,
value=info['requester'],
inline=True)
@@ -382,15 +383,15 @@ class Player(commands.Cog):
if 'duration' in info.keys():
duration = str(timedelta(seconds=info['duration']))
embedvc.add_field(name=config.SONGINFO_DURATION,
embedvc.add_field(name=self.__config.SONGINFO_DURATION,
value=f"{duration}",
inline=True)
else:
embedvc.add_field(name=config.SONGINFO_DURATION,
value=config.SONGINFO_UNKNOWN_DURATION,
embedvc.add_field(name=self.__config.SONGINFO_DURATION,
value=self.__config.SONGINFO_UNKNOWN_DURATION,
inline=True)
embedvc.add_field(name=config.SONGINFO_POSITION,
embedvc.add_field(name=self.__config.SONGINFO_POSITION,
value=position,
inline=True)

View File

@@ -1,6 +1,6 @@
from collections import deque
from typing import List
from config import config
from config.Config import Config
import random
from vulkan.music.Interfaces import IPlaylist
@@ -11,6 +11,7 @@ class Playlist(IPlaylist):
"""Class to manage and control the songs to play and played"""
def __init__(self) -> None:
self.__config = Config()
self.__queue = deque() # Store the musics to play
self.__songs_history = deque() # Store the musics played
@@ -37,7 +38,7 @@ class Playlist(IPlaylist):
@property
def songs_to_preload(self) -> List[Song]:
return list(self.__queue)[:config.MAX_PRELOAD_SONGS]
return list(self.__queue)[:self.__config.MAX_PRELOAD_SONGS]
def __len__(self) -> int:
return len(self.__queue)
@@ -55,7 +56,7 @@ class Playlist(IPlaylist):
if played_song.problematic == False:
self.__songs_history.appendleft(played_song)
if len(self.__songs_history) > config.MAX_SONGS_HISTORY:
if len(self.__songs_history) > self.__config.MAX_SONGS_HISTORY:
self.__songs_history.pop() # Remove the older
elif self.__looping_one: # Insert the current song to play again
@@ -107,13 +108,13 @@ class Playlist(IPlaylist):
Return: Embed descrition to show to user
"""
if self.__looping_all == True:
return config.LOOP_ALL_ON
return self.__config.LOOP_ALL_ON
elif self.__looping_one == True:
return config.LOOP_ONE_ALREADY_ON
return self.__config.LOOP_ONE_ALREADY_ON
else:
self.__looping_one = True
return config.LOOP_ONE_ACTIVATE
return self.__config.LOOP_ONE_ACTIVATE
def loop_all(self) -> str:
"""Try to start the loop of all songs
@@ -121,23 +122,23 @@ class Playlist(IPlaylist):
Return: Embed descrition to show to user
"""
if self.__looping_one == True:
return config.LOOP_ONE_ON
return self.__config.LOOP_ONE_ON
elif self.__looping_all == True:
return config.LOOP_ALL_ALREADY_ON
return self.__config.LOOP_ALL_ALREADY_ON
else:
self.__looping_all = True
return config.LOOP_ALL_ACTIVATE
return self.__config.LOOP_ALL_ACTIVATE
def loop_off(self) -> str:
"""Disable both types of loop"""
if self.__looping_all == False and self.__looping_one == False:
return config.LOOP_ALREADY_DISABLE
return self.__config.LOOP_ALREADY_DISABLE
self.__looping_all = False
self.__looping_one = False
return config.LOOP_DISABLE
return self.__config.LOOP_DISABLE
def destroy_song(self, song_destroy: Song) -> None:
"""Destroy a song object from the queue"""
@@ -158,7 +159,7 @@ class Playlist(IPlaylist):
pos2 = len(self.__queue)
if pos2 not in range(1, len(self.__queue) + 1) or pos1 not in range(1, len(self.__queue) + 1):
return config.LENGTH_ERROR
return self.__config.LENGTH_ERROR
try:
song = self.__queue[pos1-1]
@@ -167,23 +168,23 @@ class Playlist(IPlaylist):
song1_name = song.title if song.title else song.identifier
return config.SONG_MOVED_SUCCESSFULLY.format(song1_name, pos1, pos2)
return self.__config.SONG_MOVED_SUCCESSFULLY.format(song1_name, pos1, pos2)
except:
return config.ERROR_MOVING
return self.__config.ERROR_MOVING
def remove_song(self, position) -> str:
if position == -1:
position = len(self.__queue)
if position not in range(1, len(self.__queue) + 1):
return config.LENGTH_ERROR
return self.__config.LENGTH_ERROR
else:
song = self.__queue[position-1]
self.__queue.remove(song)
song_name = song.title if song.title else song.identifier
return config.SONG_REMOVED_SUCCESSFULLY.format(song_name)
return self.__config.SONG_REMOVED_SUCCESSFULLY.format(song_name)
def history(self) -> list:
"""Return a list with the song title of all played songs"""

View File

@@ -1,6 +1,6 @@
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
from config import config
from config.Config import Config
class SpotifySearch():
@@ -9,6 +9,7 @@ class SpotifySearch():
def __init__(self) -> None:
self.__connected = False
self.__connect()
self.__config = Config()
@property
def connected(self):
@@ -18,7 +19,7 @@ class SpotifySearch():
try:
# Initialize the connection with Spotify API
self.__api = spotipy.Spotify(auth_manager=SpotifyClientCredentials(
client_id=config.SPOTIFY_ID, client_secret=config.SPOTIFY_SECRET))
client_id=Config.SPOTIFY_ID, client_secret=self.__config.SPOTIFY_SECRET))
self.__connected = True
return True
except:

View File

@@ -1,7 +1,8 @@
import re
import asyncio
from config import config
from config.Config import Config
from functools import wraps, partial
config = Config()
def is_connected(ctx):