From 14705569c1ee729e07c43e4b483b079745ffc4b7 Mon Sep 17 00:00:00 2001 From: Rafael Vargas Date: Mon, 21 Mar 2022 21:51:40 -0400 Subject: [PATCH] Chaging config and help to class --- config/Helper.py | 51 ++++++++++++++ config/config.py | 141 +++++++++++++++++++------------------ config/help.py | 45 ------------ main.py | 3 +- vulkan/commands/Control.py | 55 ++++++++------- vulkan/commands/Music.py | 63 ++++++++--------- vulkan/commands/Random.py | 27 +++---- vulkan/music/Downloader.py | 6 +- vulkan/music/Player.py | 119 +++++++++++++++---------------- vulkan/music/Playlist.py | 33 ++++----- vulkan/music/Spotify.py | 5 +- vulkan/music/utils.py | 3 +- 12 files changed, 287 insertions(+), 264 deletions(-) create mode 100644 config/Helper.py delete mode 100644 config/help.py diff --git a/config/Helper.py b/config/Helper.py new file mode 100644 index 0000000..2275ac9 --- /dev/null +++ b/config/Helper.py @@ -0,0 +1,51 @@ +from config.Singleton import Singleton +from config.Config import Config + + +class Helper(Singleton): + def __init__(self) -> None: + if not super().created: + config = Config() + self.HELP_SKIP = 'Skip the current playing song.' + self.HELP_SKIP_LONG = 'Skip the playing of the current song, does not work if loop one is activated. \n\nArguments: None.' + self.HELP_RESUME = 'Resumes the song player.' + self.HELP_RESUME_LONG = 'If the player if paused, return the playing. \n\nArguments: None.' + self.HELP_CLEAR = 'Clear the queue and songs history.' + self.HELP_CLEAR_LONG = 'Clear the songs queue and songs history. \n\nArguments: None.' + self.HELP_STOP = 'Stop the song player.' + self.HELP_STOP_LONG = 'Stop the song player, clear queue and history and remove Vulkan from voice channel.\n\nArguments: None.' + self.HELP_LOOP = 'Control the loop of songs.' + self.HELP_LOOP_LONG = """Control the loop of songs.\n\n Require: A song being played.\nArguments: + One - Start looping the current song. + All - Start looping all songs in queue. + Off - Disable loop.""" + self.HELP_NP = 'Show the info of the current song.' + self.HELP_NP_LONG = 'Show the information of the song being played.\n\nRequire: A song being played.\nArguments: None.' + self.HELP_QUEUE = f'Show the first {config.MAX_PRELOAD_SONGS} songs in queue.' + self.HELP_QUEUE_LONG = f'Show the first {config.MAX_PRELOAD_SONGS} song in the queue.\n\nArguments: None.' + self.HELP_PAUSE = 'Pauses the song player.' + self.HELP_PAUSE_LONG = 'If playing, pauses the song player.\n\nArguments: None' + self.HELP_PREV = 'Play the previous song.' + self.HELP_PREV_LONG = 'Play the previous song. If playing, the current song will return to queue.\n\nRequire: Loop to be disable.\nArguments: None.' + self.HELP_SHUFFLE = 'Shuffle the songs playing.' + self.HELP_SHUFFLE_LONG = 'Randomly shuffle the songs in the queue.\n\nArguments: None.' + self.HELP_PLAY = 'Plays a song.' + self.HELP_PLAY_LONG = 'Play a song in discord. \n\nRequire: You to be connected to a voice channel.\nArguments: Youtube or Spotify song/playlist link or the title of the song to be searched in Youtube.' + self.HELP_HISTORY = f'Show the history of played songs.' + self.HELP_HISTORY_LONG = f'Show the last {config.MAX_SONGS_HISTORY} played songs' + self.HELP_MOVE = 'Moves a song from position x to y in queue.' + self.HELP_MOVE_LONG = 'Moves a song from position x to position y in queue.\n\nRequire: Positions to be both valid numbers.\nArguments: 1º Number => Initial position, 2º Number => Destination position. Both numbers could be -1 to refer to the last song in queue.\nDefault: By default, if the second number is not passed, it will be 1, moving the selected song to 1º position.' + self.HELP_REMOVE = 'Remove a song in position x.' + self.HELP_REMOVE_LONG = 'Remove a song from queue in the position passed.\n\nRequire: Position to be a valid number.\nArguments: 1º self.Number => Position in queue of the song.' + self.HELP_RESET = 'Reset the Player of the server.' + self.HELP_RESET_LONG = 'Reset the Player of the server. Recommended if you find any type of error.\n\nArguments: None' + self.HELP_HELP = f'Use {config.BOT_PREFIX}help "command" for more info.' + self.HELP_HELP_LONG = f'Use {config.BOT_PREFIX}help command for more info about the command selected.' + self.HELP_INVITE = 'Send the invite URL to call Vulkan to your server.' + self.HELP_INVITE_LONG = 'Send an message in text channel with a URL to be used to invite Vulkan to your own server.\n\nArguments: None.' + self.HELP_RANDOM = 'Return a random number between 1 and x.' + self.HELP_RANDOM_LONG = 'Send a randomly selected number between 1 and the number you pass.\n\nRequired: Number to be a valid number.\nArguments: 1º Any number to be used as range.' + self.HELP_CHOOSE = 'Choose randomly one item passed.' + self.HELP_CHOOSE_LONG = 'Choose randomly one item passed in this command.\n\nRequire: Itens to be separated by comma.\nArguments: As much as you want.' + self.HELP_CARA = 'Return cara or coroa.' + self.HELP_CARA_LONG = 'Return cara or coroa.' diff --git a/config/config.py b/config/config.py index 36cc162..e967d65 100644 --- a/config/config.py +++ b/config/config.py @@ -1,82 +1,87 @@ from decouple import config +from config.Singleton import Singleton -BOT_TOKEN = config('BOT_TOKEN') -SPOTIFY_ID = config('SPOTIFY_ID') -SPOTIFY_SECRET = config('SPOTIFY_SECRET') -BOT_PREFIX = '$' -VC_TIMEOUT = 600 +class Config(Singleton): + def __init__(self) -> None: + if not super().created: + self.BOT_TOKEN = config('BOT_TOKEN') + self.SPOTIFY_ID = config('SPOTIFY_ID') + self.SPOTIFY_SECRET = config('SPOTIFY_SECRET') -STARTUP_MESSAGE = 'Starting Vulkan...' -STARTUP_COMPLETE_MESSAGE = 'Vulkan is now operating.' + self.BOT_PREFIX = '$' + self.VC_TIMEOUT = 600 -MAX_PLAYLIST_LENGTH = 50 -MAX_PRELOAD_SONGS = 10 -MAX_SONGS_HISTORY = 15 + self.STARTUP_MESSAGE = 'Starting Vulkan...' + self.STARTUP_COMPLETE_MESSAGE = 'Vulkan is now operating.' -INVITE_MESSAGE = 'To invite Vulkan to your own server, click [here]({})' + self.MAX_PLAYLIST_LENGTH = 50 + self.MAX_PRELOAD_SONGS = 10 + self.MAX_SONGS_HISTORY = 15 -SONGINFO_UPLOADER = "Uploader: " -SONGINFO_DURATION = "Duration: " -SONGINFO_REQUESTER = 'Requester: ' -SONGINFO_POSITION = 'Position: ' + self.INVITE_MESSAGE = 'To invite Vulkan to your own server, click [here]({})' -SONGS_ADDED = 'You added {} songs to the queue' -SONG_ADDED = 'You added the song `{}` to the queue' -SONG_ADDED_TWO = '🎧 Song added to the queue' -SONG_PLAYING = '🎧 Song playing now' -SONG_PLAYER = '🎧 Song Player' -QUEUE_TITLE = '🎧 Songs in Queue' -ONE_SONG_LOOPING = '🎧 Looping One Song' -ALL_SONGS_LOOPING = '🎧 Looping All Songs' -SONG_PAUSED = '⏸️ Song paused' -SONG_RESUMED = '▶️ Song playing' -EMPTY_QUEUE = f'📜 Song queue is empty, use {BOT_PREFIX}play to add new songs' -SONG_DOWNLOADING = '📥 Downloading...' + self.SONGINFO_UPLOADER = "Uploader: " + self.SONGINFO_DURATION = "Duration: " + self.SONGINFO_REQUESTER = 'Requester: ' + self.SONGINFO_POSITION = 'Position: ' -HISTORY_TITLE = '🎧 Played Songs' -HISTORY_EMPTY = '📜 There is no musics in history' + self.SONGS_ADDED = 'You added {} songs to the queue' + self.SONG_ADDED = 'You added the song `{}` to the queue' + self.SONG_ADDED_TWO = '🎧 Song added to the queue' + self.SONG_PLAYING = '🎧 Song playing now' + self.SONG_PLAYER = '🎧 Song Player' + self.QUEUE_TITLE = '🎧 Songs in Queue' + self.ONE_SONG_LOOPING = '🎧 Looping One Song' + self.ALL_SONGS_LOOPING = '🎧 Looping All Songs' + self.SONG_PAUSED = '⏸️ Song paused' + self.SONG_RESUMED = '▶️ Song playing' + self.EMPTY_QUEUE = f'📜 Song queue is empty, use {self.BOT_PREFIX}play to add new songs' + self.SONG_DOWNLOADING = '📥 Downloading...' -SONG_MOVED_SUCCESSFULLY = 'Song `{}` in position `{}` moved to the position `{}` successfully' -SONG_REMOVED_SUCCESSFULLY = 'Song `{}` removed successfully' + self.HISTORY_TITLE = '🎧 Played Songs' + self.HISTORY_EMPTY = '📜 There is no musics in history' -LOOP_ALL_ON = f'❌ Vulkan is looping all songs, use {BOT_PREFIX}loop off to disable this loop first' -LOOP_ONE_ON = f'❌ Vulkan is looping one song, use {BOT_PREFIX}loop off to disable this loop first' -LOOP_ALL_ALREADY_ON = '🔁 Vulkan is already looping all songs' -LOOP_ONE_ALREADY_ON = '🔂 Vulkan is already looping the current song' -LOOP_ALL_ACTIVATE = '🔁 Looping all songs' -LOOP_ONE_ACTIVATE = '🔂 Looping the current song' -LOOP_DISABLE = '➡️ Loop disabled' -LOOP_ALREADY_DISABLE = '❌ Loop is already disabled' -LOOP_ON = f'❌ This command cannot be invoked with any loop activated. Use {BOT_PREFIX}loop off to disable loop' + self.SONG_MOVED_SUCCESSFULLY = 'Song `{}` in position `{}` moved to the position `{}` successfully' + self.SONG_REMOVED_SUCCESSFULLY = 'Song `{}` removed successfully' -SONGS_SHUFFLED = '🔀 Songs shuffled successfully' -ERROR_SHUFFLING = '❌ Error while shuffling the songs' -ERROR_MOVING = '❌ Error while moving the songs' -LENGTH_ERROR = '❌ Numbers must be between 1 and queue length, use -1 for the last song' -ERROR_NUMBER = '❌ This command require a number' -ERROR_PLAYING = '❌ Error while playing songs' -COMMAND_NOT_FOUND = f'❌ Command not found, type {BOT_PREFIX}help to see all commands' -UNKNOWN_ERROR = f'❌ Unknown Error, if needed, use {BOT_PREFIX}reset to reset the player of your server' -ERROR_MISSING_ARGUMENTS = f'❌ Missing arguments in this command. Type {BOT_PREFIX}help "command" to see more info about this command' -NOT_PREVIOUS = '❌ There is none previous song to play' -PLAYER_NOT_PLAYING = f'❌ No song playing. Use {BOT_PREFIX}play to start the player' -IMPOSSIBLE_MOVE = 'That is impossible :(' -ERROR_TITLE = 'Error :-(' -NO_CHANNEL = 'To play some music, connect to any voice channel first.' -NO_GUILD = f'This server does not has a Player, try {BOT_PREFIX}reset' -INVALID_INPUT = f'This type of input was too strange, try something better or type {BOT_PREFIX}help play' -DOWNLOADING_ERROR = '❌ An error occurred while downloading' -EXTRACTING_ERROR = '❌ An error ocurred while searching for the songs' + self.LOOP_ALL_ON = f'❌ Vulkan is looping all songs, use {self.BOT_PREFIX}loop off to disable this loop first' + self.LOOP_ONE_ON = f'❌ Vulkan is looping one song, use {self.BOT_PREFIX}loop off to disable this loop first' + self.LOOP_ALL_ALREADY_ON = '🔁 Vulkan is already looping all songs' + self.LOOP_ONE_ALREADY_ON = '🔂 Vulkan is already looping the current song' + self.LOOP_ALL_ACTIVATE = '🔁 Looping all songs' + self.LOOP_ONE_ACTIVATE = '🔂 Looping the current song' + self.LOOP_DISABLE = '➡️ Loop disabled' + self.LOOP_ALREADY_DISABLE = '❌ Loop is already disabled' + self.LOOP_ON = f'❌ This command cannot be invoked with any loop activated. Use {self.BOT_PREFIX}loop off to disable loop' -MY_ERROR_BAD_COMMAND = 'This string serves to verify if some error was raised by myself on purpose' -BAD_COMMAND_TITLE = 'Misuse of command' -BAD_COMMAND = f'❌ Bad usage of this command, type {BOT_PREFIX}help "command" to understand the command better' + self.SONGS_SHUFFLED = '🔀 Songs shuffled successfully' + self.ERROR_SHUFFLING = '❌ Error while shuffling the songs' + self.ERROR_MOVING = '❌ Error while moving the songs' + self.LENGTH_ERROR = '❌ Numbers must be between 1 and queue length, use -1 for the last song' + self.ERROR_NUMBER = '❌ This command require a number' + self.ERROR_PLAYING = '❌ Error while playing songs' + self.COMMAND_NOT_FOUND = f'❌ Command not found, type {self.BOT_PREFIX}help to see all commands' + self.UNKNOWN_ERROR = f'❌ Unknown Error, if needed, use {self.BOT_PREFIX}reset to reset the player of your server' + self.ERROR_MISSING_ARGUMENTS = f'❌ Missing arguments in this command. Type {self.BOT_PREFIX}help "command" to see more info about this command' + self.NOT_PREVIOUS = '❌ There is none previous song to play' + self.PLAYER_NOT_PLAYING = f'❌ No song playing. Use {self.BOT_PREFIX}play to start the player' + self.IMPOSSIBLE_MOVE = 'That is impossible :(' + self.ERROR_TITLE = 'Error :-(' + self.NO_CHANNEL = 'To play some music, connect to any voice channel first.' + self.NO_GUILD = f'This server does not has a Player, try {self.BOT_PREFIX}reset' + self.INVALID_INPUT = f'This type of input was too strange, try something better or type {self.BOT_PREFIX}help play' + self.DOWNLOADING_ERROR = '❌ An error occurred while downloading' + self.EXTRACTING_ERROR = '❌ An error ocurred while searching for the songs' -COLOURS = { - 'red': 0xDC143C, - 'green': 0x1F8B4C, - 'grey': 0x708090, - 'blue': 0x206694, - 'black': 0x23272A -} + self.MY_ERROR_BAD_COMMAND = 'This string serves to verify if some error was raised by myself on purpose' + self.BAD_COMMAND_TITLE = 'Misuse of command' + self.BAD_COMMAND = f'❌ Bad usage of this command, type {self.BOT_PREFIX}help "command" to understand the command better' + + self.COLOURS = { + 'red': 0xDC143C, + 'green': 0x1F8B4C, + 'grey': 0x708090, + 'blue': 0x206694, + 'black': 0x23272A + } diff --git a/config/help.py b/config/help.py deleted file mode 100644 index 0a9cb35..0000000 --- a/config/help.py +++ /dev/null @@ -1,45 +0,0 @@ -from config.config import * - -HELP_SKIP = 'Skip the current playing song.' -HELP_SKIP_LONG = 'Skip the playing of the current song, does not work if loop one is activated. \n\nArguments: None.' -HELP_RESUME = 'Resumes the song player.' -HELP_RESUME_LONG = 'If the player if paused, return the playing. \n\nArguments: None.' -HELP_CLEAR = 'Clear the queue and songs history.' -HELP_CLEAR_LONG = 'Clear the songs queue and songs history. \n\nArguments: None.' -HELP_STOP = 'Stop the song player.' -HELP_STOP_LONG = 'Stop the song player, clear queue and history and remove Vulkan from voice channel.\n\nArguments: None.' -HELP_LOOP = 'Control the loop of songs.' -HELP_LOOP_LONG = """Control the loop of songs.\n\n Require: A song being played.\nArguments: - One - Start looping the current song. - All - Start looping all songs in queue. - Off - Disable loop.""" -HELP_NP = 'Show the info of the current song.' -HELP_NP_LONG = 'Show the information of the song being played.\n\nRequire: A song being played.\nArguments: None.' -HELP_QUEUE = f'Show the first {MAX_PRELOAD_SONGS} songs in queue.' -HELP_QUEUE_LONG = f'Show the first {MAX_PRELOAD_SONGS} song in the queue.\n\nArguments: None.' -HELP_PAUSE = 'Pauses the song player.' -HELP_PAUSE_LONG = 'If playing, pauses the song player.\n\nArguments: None' -HELP_PREV = 'Play the previous song.' -HELP_PREV_LONG = 'Play the previous song. If playing, the current song will return to queue.\n\nRequire: Loop to be disable.\nArguments: None.' -HELP_SHUFFLE = 'Shuffle the songs playing.' -HELP_SHUFFLE_LONG = 'Randomly shuffle the songs in the queue.\n\nArguments: None.' -HELP_PLAY = 'Plays a song.' -HELP_PLAY_LONG = 'Play a song in discord. \n\nRequire: You to be connected to a voice channel.\nArguments: Youtube or Spotify song/playlist link or the title of the song to be searched in Youtube.' -HELP_HISTORY = f'Show the history of played songs.' -HELP_HISTORY_LONG = f'Show the last {MAX_SONGS_HISTORY} played songs' -HELP_MOVE = 'Moves a song from position x to y in queue.' -HELP_MOVE_LONG = 'Moves a song from position x to position y in queue.\n\nRequire: Positions to be both valid numbers.\nArguments: 1º Number => Initial position, 2º Number => Destination position. Both numbers could be -1 to refer to the last song in queue.\nDefault: By default, if the second number is not passed, it will be 1, moving the selected song to 1º position.' -HELP_REMOVE = 'Remove a song in position x.' -HELP_REMOVE_LONG = 'Remove a song from queue in the position passed.\n\nRequire: Position to be a valid number.\nArguments: 1º Number => Position in queue of the song.' -HELP_RESET = 'Reset the Player of the server.' -HELP_RESET_LONG = 'Reset the Player of the server. Recommended if you find any type of error.\n\nArguments: None' -HELP_HELP = f'Use {BOT_PREFIX}help "command" for more info.' -HELP_HELP_LONG = f'Use {BOT_PREFIX}help command for more info about the command selected.' -HELP_INVITE = 'Send the invite URL to call Vulkan to your server.' -HELP_INVITE_LONG = 'Send an message in text channel with a URL to be used to invite Vulkan to your own server.\n\nArguments: None.' -HELP_RANDOM = 'Return a random number between 1 and x.' -HELP_RANDOM_LONG = 'Send a randomly selected number between 1 and the number you pass.\n\nRequired: Number to be a valid number.\nArguments: 1º Any number to be used as range.' -HELP_CHOOSE = 'Choose randomly one item passed.' -HELP_CHOOSE_LONG = 'Choose randomly one item passed in this command.\n\nRequire: Itens to be separated by comma.\nArguments: As much as you want.' -HELP_CARA = 'Return cara or coroa.' -HELP_CARA_LONG = 'Return cara or coroa.' diff --git a/main.py b/main.py index 7a3a98f..495a193 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,12 @@ import discord import os -from config import config +from config.Config import Config from discord.ext import commands intents = discord.Intents.default() intents.members = True +config = Config() bot = commands.Bot(command_prefix=config.BOT_PREFIX, pm_help=True, case_insensitive=True, intents=intents) diff --git a/vulkan/commands/Control.py b/vulkan/commands/Control.py index 56e973d..860db05 100644 --- a/vulkan/commands/Control.py +++ b/vulkan/commands/Control.py @@ -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) diff --git a/vulkan/commands/Music.py b/vulkan/commands/Music.py index 45e8ac4..fa1136e 100644 --- a/vulkan/commands/Music.py +++ b/vulkan/commands/Music.py @@ -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, diff --git a/vulkan/commands/Random.py b/vulkan/commands/Random.py index 2f7ac34..5c366f9 100644 --- a/vulkan/commands/Random.py +++ b/vulkan/commands/Random.py @@ -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) diff --git a/vulkan/music/Downloader.py b/vulkan/music/Downloader.py index f626dad..2785724 100644 --- a/vulkan/music/Downloader.py +++ b/vulkan/music/Downloader.py @@ -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) diff --git a/vulkan/music/Player.py b/vulkan/music/Player.py index 1bb3806..776aaf2 100644 --- a/vulkan/music/Player.py +++ b/vulkan/music/Player.py @@ -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) diff --git a/vulkan/music/Playlist.py b/vulkan/music/Playlist.py index 23f8ac1..a74083c 100644 --- a/vulkan/music/Playlist.py +++ b/vulkan/music/Playlist.py @@ -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""" diff --git a/vulkan/music/Spotify.py b/vulkan/music/Spotify.py index 96012f5..4708ff8 100644 --- a/vulkan/music/Spotify.py +++ b/vulkan/music/Spotify.py @@ -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: diff --git a/vulkan/music/utils.py b/vulkan/music/utils.py index dcf54e2..76ce021 100644 --- a/vulkan/music/utils.py +++ b/vulkan/music/utils.py @@ -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):