Creating Player View

This commit is contained in:
Rafael Vargas
2022-07-27 16:14:13 -03:00
parent beb0bc085d
commit 4f11506c2b
22 changed files with 246 additions and 164 deletions

View File

@@ -1,7 +1,7 @@
from Config.Singleton import Singleton
class Colors(Singleton):
class VColors(Singleton):
def __init__(self) -> None:
self.__red = 0xDC143C
self.__green = 0x1F8B4C

View File

@@ -2,7 +2,7 @@ from decouple import config
from Config.Singleton import Singleton
class Configs(Singleton):
class VConfigs(Singleton):
def __init__(self) -> None:
if not super().created:
self.BOT_PREFIX = '!'

357
Config/Embeds.py Normal file
View File

@@ -0,0 +1,357 @@
from Config.Messages import Messages
from Config.Exceptions import VulkanError
from discord import Embed
from Config.Configs import VConfigs
from Config.Colors import VColors
from datetime import timedelta
class VEmbeds:
def __init__(self) -> None:
self.__config = VConfigs()
self.__messages = Messages()
self.__colors = VColors()
def ONE_SONG_LOOPING(self, info: dict) -> Embed:
title = self.__messages.ONE_SONG_LOOPING
return self.SONG_INFO(info, title)
def EMPTY_QUEUE(self) -> Embed:
title = self.__messages.SONG_PLAYER
text = self.__messages.EMPTY_QUEUE
embed = Embed(
title=title,
description=text,
colour=self.__colors.BLUE
)
return embed
def MISSING_ARGUMENTS(self) -> Embed:
embed = Embed(
title=self.__messages.ERROR_TITLE,
description=self.__messages.ERROR_MISSING_ARGUMENTS,
colour=self.__colors.BLACK
)
return embed
def SONG_ADDED_TWO(self, info: dict, pos: int) -> Embed:
embed = self.SONG_INFO(info, self.__messages.SONG_ADDED_TWO, pos)
return embed
def INVALID_INPUT(self) -> Embed:
embed = Embed(
title=self.__messages.ERROR_TITLE,
description=self.__messages.INVALID_INPUT,
colour=self.__colors.BLACK)
return embed
def UNAVAILABLE_VIDEO(self) -> Embed:
embed = Embed(
title=self.__messages.ERROR_TITLE,
description=self.__messages.VIDEO_UNAVAILABLE,
colour=self.__colors.BLACK)
return embed
def DOWNLOADING_ERROR(self) -> Embed:
embed = Embed(
title=self.__messages.ERROR_TITLE,
description=self.__messages.DOWNLOADING_ERROR,
colour=self.__colors.BLACK)
return embed
def SONG_ADDED(self, title: str) -> Embed:
embed = Embed(
title=self.__messages.SONG_PLAYER,
description=self.__messages.SONG_ADDED.format(title),
colour=self.__colors.BLUE)
return embed
def SONGS_ADDED(self, quant: int) -> Embed:
embed = Embed(
title=self.__messages.SONG_PLAYER,
description=self.__messages.SONGS_ADDED.format(quant),
colour=self.__colors.BLUE)
return embed
def SONG_INFO(self, info: dict, title: str, position='Playing Now') -> Embed:
embedvc = Embed(
title=title,
description=f"[{info['title']}]({info['original_url']})",
colour=self.__colors.BLUE
)
embedvc.add_field(name=self.__messages.SONGINFO_UPLOADER,
value=info['uploader'],
inline=False)
embedvc.add_field(name=self.__messages.SONGINFO_REQUESTER,
value=info['requester'],
inline=True)
if 'thumbnail' in info.keys():
embedvc.set_thumbnail(url=info['thumbnail'])
if 'duration' in info.keys():
duration = str(timedelta(seconds=info['duration']))
embedvc.add_field(name=self.__messages.SONGINFO_DURATION,
value=f"{duration}",
inline=True)
else:
embedvc.add_field(name=self.__messages.SONGINFO_DURATION,
value=self.__messages.SONGINFO_UNKNOWN_DURATION,
inline=True)
embedvc.add_field(name=self.__messages.SONGINFO_POSITION,
value=position,
inline=True)
return embedvc
def SONG_MOVED(self, song_name: str, pos1: int, pos2: int) -> Embed:
embed = Embed(
title=self.__messages.SONG_PLAYER,
description=self.__messages.SONG_MOVED_SUCCESSFULLY.format(song_name, pos1, pos2),
colour=self.__colors.BLUE
)
return embed
def ERROR_MOVING(self) -> Embed:
embed = Embed(
title=self.__messages.UNKNOWN_ERROR,
description=self.__messages.ERROR_MOVING,
colour=self.__colors.BLACK
)
return embed
def ERROR_EMBED(self, description: str) -> Embed:
embed = Embed(
description=description,
colour=self.__colors.BLACK
)
return embed
def CUSTOM_ERROR(self, error: VulkanError) -> Embed:
embed = Embed(
title=error.title,
description=error.message,
colour=self.__colors.BLACK
)
return embed
def WRONG_LENGTH_INPUT(self) -> Embed:
embed = Embed(
title=self.__messages.BAD_COMMAND_TITLE,
description=self.__messages.LENGTH_ERROR,
colour=self.__colors.BLACK
)
return embed
def BAD_LOOP_USE(self) -> Embed:
embed = Embed(
title=self.__messages.BAD_COMMAND_TITLE,
description=self.__messages.BAD_USE_OF_LOOP,
colour=self.__colors.BLACK
)
return embed
def COMMAND_ERROR(self):
embed = Embed(
title=self.__messages.ERROR_TITLE,
description=self.__messages.ERROR_MISSING_ARGUMENTS,
colour=self.__colors.BLACK
)
return embed
def COMMAND_NOT_FOUND(self) -> Embed:
embed = Embed(
title=self.__messages.COMMAND_NOT_FOUND_TITLE,
description=self.__messages.COMMAND_NOT_FOUND,
colour=self.__colors.BLACK
)
return embed
def MY_ERROR_BAD_COMMAND(self) -> Embed:
embed = Embed(
title=self.__messages.BAD_COMMAND_TITLE,
description=self.__messages.BAD_COMMAND,
colour=self.__colors.BLACK
)
return embed
def UNKNOWN_ERROR(self) -> Embed:
embed = Embed(
title=self.__messages.ERROR_TITLE,
description=self.__messages.UNKNOWN_ERROR,
colour=self.__colors.RED
)
return embed
def FAIL_DUE_TO_LOOP_ON(self) -> Embed:
embed = Embed(
title=self.__messages.SONG_PLAYER,
description=self.__messages.LOOP_ON,
colour=self.__colors.BLACK
)
return embed
def ERROR_SHUFFLING(self) -> Embed:
embed = Embed(
title=self.__messages.SONG_PLAYER,
description=self.__messages.ERROR_SHUFFLING,
colour=self.__colors.BLACK
)
return embed
def SONGS_SHUFFLED(self) -> Embed:
embed = Embed(
title=self.__messages.SONG_PLAYER,
description=self.__messages.SONGS_SHUFFLED,
colour=self.__colors.BLUE
)
return embed
def LOOP_ONE_ACTIVATED(self) -> Embed:
embed = Embed(
title=self.__messages.LOOP_ONE_ACTIVATE,
colour=self.__colors.BLUE
)
return embed
def LOOP_ALL_ACTIVATED(self) -> Embed:
embed = Embed(
title=self.__messages.LOOP_ALL_ACTIVATE,
colour=self.__colors.BLUE
)
return embed
def SONG_PROBLEMATIC(self) -> Embed:
embed = Embed(
title=self.__messages.ERROR_TITLE,
description=self.__messages.DOWNLOADING_ERROR,
colour=self.__colors.BLACK)
return embed
def PLAYER_RESTARTED(self) -> Embed:
embed = Embed(
title=self.__messages.ERROR_TITLE,
description=self.__messages.ERROR_IN_PROCESS,
colour=self.__colors.BLACK)
return embed
def NO_CHANNEL(self) -> Embed:
embed = Embed(
title=self.__messages.IMPOSSIBLE_MOVE,
description=self.__messages.NO_CHANNEL,
colour=self.__colors.BLACK
)
return embed
def ERROR_DUE_LOOP_ONE_ON(self) -> Embed:
embed = Embed(
title=self.__messages.BAD_COMMAND_TITLE,
description=self.__messages.ERROR_DUE_LOOP_ONE_ON,
colour=self.__colors.BLACK
)
return embed
def LOOP_DISABLE(self) -> Embed:
embed = Embed(
title=self.__messages.LOOP_DISABLE,
colour=self.__colors.BLUE
)
return embed
def NOT_PREVIOUS_SONG(self) -> Embed:
embed = Embed(
title=self.__messages.SONG_PLAYER,
description=self.__messages.NOT_PREVIOUS,
colour=self.__colors.BLUE
)
return embed
def HISTORY(self, description: str) -> Embed:
embed = Embed(
title=self.__messages.HISTORY_TITLE,
description=description,
colour=self.__colors.BLUE)
return embed
def NOT_PLAYING(self) -> Embed:
embed = Embed(
title=self.__messages.SONG_PLAYER,
description=self.__messages.PLAYER_NOT_PLAYING,
colour=self.__colors.BLUE)
return embed
def QUEUE(self, title: str, description: str) -> Embed:
embed = Embed(
title=title,
description=description,
colour=self.__colors.BLUE
)
return embed
def INVITE(self, bot_id: str) -> Embed:
link = self.__messages.INVITE_URL
link.format(bot_id)
text = self.__messages.INVITE_MESSAGE.format(link, link)
embed = Embed(
title="Invite Vulkan",
description=text,
colour=self.__colors.BLUE
)
return embed
def ERROR_NUMBER(self) -> Embed:
embed = Embed(
description=self.__messages.ERROR_NUMBER,
colour=self.__colors.BLACK
)
return embed
def RANDOM_NUMBER(self, a: int, b: int, x: int) -> Embed:
embed = Embed(
title=f'Random number between [{a}, {b}]',
description=x,
colour=self.__colors.GREEN
)
return embed
def SONG_REMOVED(self, song_name: str) -> Embed:
embed = Embed(
description=self.__messages.SONG_REMOVED_SUCCESSFULLY.format(song_name),
colour=self.__colors.BLUE
)
return embed
def PLAYLIST_RANGE_ERROR(self) -> Embed:
embed = Embed(
description=self.__messages.LENGTH_ERROR,
colour=self.__colors.BLACK
)
return embed
def CARA_COROA(self, result: str) -> Embed:
embed = Embed(
title='Cara Coroa',
description=f'Result: {result}',
colour=self.__colors.GREEN
)
return embed
def CHOSEN_THING(self, thing: str) -> Embed:
embed = Embed(
title='Choose something',
description=f'Chosen: {thing}',
colour=self.__colors.GREEN
)
return embed
def BAD_CHOOSE_USE(self) -> Embed:
embed = Embed(
title='Choose something',
description=f'Error: Use {self.__config.BOT_PREFIX}help choose to understand this command.',
colour=self.__colors.RED
)
return embed

20
Config/Emojis.py Normal file
View File

@@ -0,0 +1,20 @@
from Config.Singleton import Singleton
class VEmojis(Singleton):
def __init__(self) -> None:
if not super().created:
self.SKIP = ""
self.BACK = ""
self.PAUSE = "⏸️"
self.PLAY = "▶️"
self.STOP = "⏹️"
self.LOOP_ONE = "🔂"
self.LOOP_OFF = "➡️"
self.LOOP_ALL = "🔁"
self.SHUFFLE = "🔀"
self.QUEUE = "📜"
self.MUSIC = "🎧"
self.ERROR = ""
self.DOWNLOADING = "📥"
self.SUCCESS = ""

View File

@@ -1,11 +1,11 @@
from Config.Singleton import Singleton
from Config.Configs import Configs
from Config.Configs import VConfigs
class Helper(Singleton):
def __init__(self) -> None:
if not super().created:
config = Configs()
config = VConfigs()
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.'

View File

@@ -1,11 +1,13 @@
from Config.Singleton import Singleton
from Config.Configs import Configs
from Config.Configs import VConfigs
from Config.Emojis import VEmojis
class Messages(Singleton):
def __init__(self) -> None:
if not super().created:
configs = Configs()
self.__emojis = VEmojis()
configs = VConfigs()
self.STARTUP_MESSAGE = 'Starting Vulkan...'
self.STARTUP_COMPLETE_MESSAGE = 'Vulkan is now operating.'
@@ -16,67 +18,67 @@ class Messages(Singleton):
self.SONGS_ADDED = 'Downloading `{}` songs to add to the queue'
self.SONG_ADDED = 'Downloading the song `{}` to add 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 {configs.BOT_PREFIX}play to add new songs'
self.SONG_DOWNLOADING = '📥 Downloading...'
self.SONG_ADDED_TWO = f'{self.__emojis.MUSIC} Song added to the queue'
self.SONG_PLAYING = f'{self.__emojis.MUSIC} Song playing now'
self.SONG_PLAYER = f'{self.__emojis.MUSIC} Song Player'
self.QUEUE_TITLE = f'{self.__emojis.MUSIC} Songs in Queue'
self.ONE_SONG_LOOPING = f'{self.__emojis.MUSIC} Looping One Song'
self.ALL_SONGS_LOOPING = f'{self.__emojis.MUSIC} Looping All Songs'
self.SONG_PAUSED = f'{self.__emojis.PAUSE} Song paused'
self.SONG_RESUMED = f'{self.__emojis.PLAY} Song playing'
self.EMPTY_QUEUE = f'{self.__emojis.QUEUE} Song queue is empty, use {configs.BOT_PREFIX}play to add new songs'
self.SONG_DOWNLOADING = f'{self.__emojis.DOWNLOADING} Downloading...'
self.HISTORY_TITLE = '🎧 Played Songs'
self.HISTORY_EMPTY = '📜 There is no musics in history'
self.HISTORY_TITLE = f'{self.__emojis.MUSIC} Played Songs'
self.HISTORY_EMPTY = f'{self.__emojis.QUEUE} There is no musics in history'
self.SONG_MOVED_SUCCESSFULLY = 'Song `{}` in position `{}` moved to the position `{}` successfully'
self.SONG_REMOVED_SUCCESSFULLY = 'Song `{}` removed successfully'
self.LOOP_ALL_ON = f' Vulkan is looping all songs, use {configs.BOT_PREFIX}loop off to disable this loop first'
self.LOOP_ONE_ON = f' Vulkan is looping one song, use {configs.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 {configs.BOT_PREFIX}loop off to disable loop'
self.BAD_USE_OF_LOOP = f""" Invalid arguments of Loop command. Use {configs.BOT_PREFIX}help loop to more information.
-> Available Arguments: ["all", "off", "one", ""]"""
self.LOOP_ALL_ON = f'{self.__emojis.ERROR} Vulkan is looping all songs, use {configs.BOT_PREFIX}loop off to disable this loop first'
self.LOOP_ONE_ON = f'{self.__emojis.ERROR} Vulkan is looping one song, use {configs.BOT_PREFIX}loop off to disable this loop first'
self.LOOP_ALL_ALREADY_ON = f'{self.__emojis.LOOP_ALL} Vulkan is already looping all songs'
self.LOOP_ONE_ALREADY_ON = f'{self.__emojis.LOOP_ONE} Vulkan is already looping the current song'
self.LOOP_ALL_ACTIVATE = f'{self.__emojis.LOOP_ALL} Looping all songs'
self.LOOP_ONE_ACTIVATE = f'{self.__emojis.LOOP_ONE} Looping the current song'
self.LOOP_DISABLE = f'{self.__emojis.LOOP_OFF} Loop disabled'
self.LOOP_ALREADY_DISABLE = f'{self.__emojis.ERROR} Loop is already disabled'
self.LOOP_ON = f'{self.__emojis.ERROR} This command cannot be invoked with any loop activated. Use {configs.BOT_PREFIX}loop off to disable loop'
self.BAD_USE_OF_LOOP = f"""{self.__emojis.ERROR} Invalid arguments of Loop command. Use {configs.BOT_PREFIX}help loop to more information.
-> Available Arguments: ["all", "off", "one", ""]"""
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 {configs.BOT_PREFIX}help to see all commands'
self.UNKNOWN_ERROR = f' Unknown Error, if needed, use {configs.BOT_PREFIX}reset to reset the player of your server'
self.ERROR_MISSING_ARGUMENTS = f' Missing arguments in this command. Type {configs.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 {configs.BOT_PREFIX}play to start the player'
self.SONGS_SHUFFLED = f'{self.__emojis.SHUFFLE} Songs shuffled successfully'
self.ERROR_SHUFFLING = f'{self.__emojis.ERROR} Error while shuffling the songs'
self.ERROR_MOVING = f'{self.__emojis.ERROR} Error while moving the songs'
self.LENGTH_ERROR = f'{self.__emojis.ERROR} Numbers must be between 1 and queue length, use -1 for the last song'
self.ERROR_NUMBER = f'{self.__emojis.ERROR} This command require a number'
self.ERROR_PLAYING = f'{self.__emojis.ERROR} Error while playing songs'
self.COMMAND_NOT_FOUND = f'{self.__emojis.ERROR} Command not found, type {configs.BOT_PREFIX}help to see all commands'
self.UNKNOWN_ERROR = f'{self.__emojis.ERROR} Unknown Error, if needed, use {configs.BOT_PREFIX}reset to reset the player of your server'
self.ERROR_MISSING_ARGUMENTS = f'{self.__emojis.ERROR} Missing arguments in this command. Type {configs.BOT_PREFIX}help "command" to see more info about this command'
self.NOT_PREVIOUS = f'{self.__emojis.ERROR} There is none previous song to play'
self.PLAYER_NOT_PLAYING = f'{self.__emojis.ERROR} No song playing. Use {configs.BOT_PREFIX}play to start the player'
self.IMPOSSIBLE_MOVE = 'That is impossible :('
self.ERROR_TITLE = 'Error :-('
self.COMMAND_NOT_FOUND_TITLE = 'This is strange :-('
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 {configs.BOT_PREFIX}reset'
self.INVALID_INPUT = f'This URL was too strange, try something better or type {configs.BOT_PREFIX}help play'
self.DOWNLOADING_ERROR = " It's impossible to download and play this video"
self.EXTRACTING_ERROR = ' An error ocurred while searching for the songs'
self.DOWNLOADING_ERROR = f"{self.__emojis.ERROR} It's impossible to download and play this video"
self.EXTRACTING_ERROR = f'{self.__emojis.ERROR} An error ocurred while searching for the songs'
self.ERROR_IN_PROCESS = " Due to a internal error your player was restarted, skipping the song."
self.ERROR_IN_PROCESS = f"{self.__emojis.ERROR} Due to a internal error your player was restarted, skipping the song."
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 {configs.BOT_PREFIX}help "command" to understand the command better'
self.VIDEO_UNAVAILABLE = ' Sorry. This video is unavailable for download.'
self.ERROR_DUE_LOOP_ONE_ON = f' This command cannot be executed with loop one activated. Use {configs.BOT_PREFIX}loop off to disable loop.'
self.BAD_COMMAND = f'{self.__emojis.ERROR} Bad usage of this command, type {configs.BOT_PREFIX}help "command" to understand the command better'
self.VIDEO_UNAVAILABLE = f'{self.__emojis.ERROR} Sorry. This video is unavailable for download.'
self.ERROR_DUE_LOOP_ONE_ON = f'{self.__emojis.ERROR} This command cannot be executed with loop one activated. Use {configs.BOT_PREFIX}loop off to disable loop.'
class SearchMessages(Singleton):
def __init__(self) -> None:
if not super().created:
config = Configs()
config = VConfigs()
self.UNKNOWN_INPUT = f'This type of input was too strange, try something else or type {config.BOT_PREFIX}help play'
self.UNKNOWN_INPUT_TITLE = 'Nothing Found'
self.GENERIC_TITLE = 'URL could not be processed'