Chaging the folders and creating a separeted class for messages

This commit is contained in:
Rafael Vargas
2022-03-22 17:53:21 -04:00
parent 2240c7535a
commit a828350201
27 changed files with 145 additions and 85 deletions

View File

@@ -2,7 +2,7 @@ import discord
from discord import Client from discord import Client
from discord.ext.commands.errors import CommandNotFound, MissingRequiredArgument, UserInputError from discord.ext.commands.errors import CommandNotFound, MissingRequiredArgument, UserInputError
from discord.ext import commands from discord.ext import commands
from Config.Config import Config from Config.Config import Configs
from Config.Helper import Helper from Config.Helper import Helper
helper = Helper() helper = Helper()
@@ -13,7 +13,7 @@ class Control(commands.Cog):
def __init__(self, bot: Client): def __init__(self, bot: Client):
self.__bot = bot self.__bot = bot
self.__config = Config() self.__config = Configs()
self.__comandos = { self.__comandos = {
'MUSIC': ['resume', 'pause', 'loop', 'stop', 'MUSIC': ['resume', 'pause', 'loop', 'stop',
'skip', 'play', 'queue', 'clear', 'skip', 'play', 'queue', 'clear',

View File

@@ -2,13 +2,13 @@ from typing import Dict
from discord import Guild, Client, Embed from discord import Guild, Client, Embed
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Context from discord.ext.commands import Context
from Config.Config import Config from Config.Config import Configs
from Config.Helper import Helper from Config.Helper import Helper
from Vulkan.Music.Player import Player from Music.Player import Player
from Vulkan.Music.utils import is_connected from Music.utils import is_connected
from Vulkan.Controllers.SkipController import SkipController from Controllers.SkipController import SkipController
from Vulkan.Views.EmoteView import EmoteView from Views.EmoteView import EmoteView
from Vulkan.Views.EmbedView import EmbedView from Views.EmbedView import EmbedView
helper = Helper() helper = Helper()
@@ -18,7 +18,7 @@ class Music(commands.Cog):
def __init__(self, bot) -> None: def __init__(self, bot) -> None:
self.__guilds: Dict[Guild, Player] = {} self.__guilds: Dict[Guild, Player] = {}
self.__bot: Client = bot self.__bot: Client = bot
self.__config = Config() self.__config = Configs()
@commands.Cog.listener() @commands.Cog.listener()
async def on_ready(self) -> None: async def on_ready(self) -> None:
@@ -197,7 +197,7 @@ class Music(commands.Cog):
player = self.__get_player(ctx) player = self.__get_player(ctx)
await player.force_stop() await player.force_stop()
except Exception as e: except Exception as e:
print(f'Reset Error: {e}') print(f'DEVELOPER NOTE -> Reset Error: {e}')
self.__guilds[ctx.guild] = Player(self.__bot, ctx.guild) self.__guilds[ctx.guild] = Player(self.__bot, ctx.guild)
player = self.__get_player(ctx) player = self.__get_player(ctx)

View File

@@ -1,7 +1,7 @@
from random import randint, random from random import randint, random
import discord import discord
from discord.ext import commands from discord.ext import commands
from Config.Config import Config from Config.Config import Configs
from Config.Helper import Helper from Config.Helper import Helper
helper = Helper() helper = Helper()
@@ -12,7 +12,7 @@ class Random(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.__bot = bot self.__bot = bot
self.__config = Config() self.__config = Configs()
@commands.command(name='random', help=helper.HELP_RANDOM, description=helper.HELP_RANDOM_LONG) @commands.command(name='random', help=helper.HELP_RANDOM, description=helper.HELP_RANDOM_LONG)
async def random(self, ctx, arg: str) -> None: async def random(self, ctx, arg: str) -> None:

View File

@@ -1,12 +1,12 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client, Guild from discord import Client, Guild
from Vulkan.Controllers.PlayerController import PlayersController from Controllers.PlayerController import PlayersController
from Vulkan.Music.Player import Player from Music.Player import Player
from Vulkan.Controllers.ControllerResponse import ControllerResponse from Controllers.ControllerResponse import ControllerResponse
from Config.Config import Config from Config.Config import Configs
from Config.Helper import Helper from Config.Helper import Helper
from Vulkan.Views.Embeds.Embeds import Embeds from Views.Embeds import Embeds
class AbstractController(ABC): class AbstractController(ABC):
@@ -16,7 +16,7 @@ class AbstractController(ABC):
self.__player: Player = self.__controller.get_player(ctx.guild) self.__player: Player = self.__controller.get_player(ctx.guild)
self.__guild: Guild = ctx.guild self.__guild: Guild = ctx.guild
self.__ctx: Context = ctx self.__ctx: Context = ctx
self.__config = Config() self.__config = Configs()
self.__helper = Helper() self.__helper = Helper()
self.__embeds = Embeds() self.__embeds = Embeds()
@@ -41,7 +41,7 @@ class AbstractController(ABC):
return self.__bot return self.__bot
@property @property
def config(self) -> Config: def config(self) -> Configs:
return self.__config return self.__config
@property @property

View File

@@ -1,6 +1,6 @@
from typing import Union from typing import Union
from discord.ext.commands import Context from discord.ext.commands import Context
from Vulkan.Exceptions.Exceptions import Error from Exceptions.Exceptions import Error
from discord import Embed from discord import Embed

View File

@@ -1,7 +1,7 @@
from typing import Dict, List, Union from typing import Dict, List, Union
from Config.Singleton import Singleton from Config.Singleton import Singleton
from discord import Guild, Client, VoiceClient from discord import Guild, Client, VoiceClient
from Vulkan.Music.Player import Player from Music.Player import Player
class PlayersController(Singleton): class PlayersController(Singleton):

View File

@@ -1,8 +1,8 @@
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client from discord import Client
from Vulkan.Controllers.AbstractController import AbstractController from Controllers.AbstractController import AbstractController
from Vulkan.Exceptions.Exceptions import BadCommandUsage from Exceptions.Exceptions import BadCommandUsage
from Vulkan.Controllers.ControllerResponse import ControllerResponse from Controllers.ControllerResponse import ControllerResponse
class SkipController(AbstractController): class SkipController(AbstractController):

View File

@@ -1,4 +1,4 @@
from config.Config import Config from Config.Config import Configs
class Error(Exception): class Error(Exception):
@@ -18,7 +18,7 @@ class Error(Exception):
class ImpossibleMove(Error): class ImpossibleMove(Error):
def __init__(self, message='', title='', *args: object) -> None: def __init__(self, message='', title='', *args: object) -> None:
config = Config() config = Configs()
if title == '': if title == '':
title = config.IMPOSSIBLE_MOVE title = config.IMPOSSIBLE_MOVE
super().__init__(message, title, *args) super().__init__(message, title, *args)

View File

@@ -1,15 +1,15 @@
import asyncio import asyncio
from typing import List from typing import List
from Config.Config import Config from Config.Config import Configs
from yt_dlp import YoutubeDL from yt_dlp import YoutubeDL
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from Vulkan.Music.Song import Song from Music.Song import Song
from Vulkan.Music.utils import is_url, run_async from Music.utils import is_url, run_async
class Downloader(): class Downloader():
"""Download musics direct URL and title or Source from Youtube using a music name or Youtube URL""" """Download musics direct URL and title or Source from Youtube using a music name or Youtube URL"""
config = Config() config = Configs()
__YDL_OPTIONS = {'format': 'bestaudio/best', __YDL_OPTIONS = {'format': 'bestaudio/best',
'default_search': 'auto', 'default_search': 'auto',
'playliststart': 0, 'playliststart': 0,
@@ -31,7 +31,7 @@ class Downloader():
__BASE_URL = 'https://www.youtube.com/watch?v={}' __BASE_URL = 'https://www.youtube.com/watch?v={}'
def __init__(self) -> None: def __init__(self) -> None:
self.__config = Config() self.__config = Configs()
self.__music_keys_only = ['resolution', 'fps', 'quality'] self.__music_keys_only = ['resolution', 'fps', 'quality']
self.__not_extracted_keys_only = ['ie_key'] self.__not_extracted_keys_only = ['ie_key']
self.__not_extracted_not_keys = ['entries'] self.__not_extracted_not_keys = ['entries']

View File

@@ -1,14 +1,14 @@
from discord.ext import commands from discord.ext import commands
from Config.Config import Config from Config.Config import Configs
from discord import Client, Guild, FFmpegPCMAudio, Embed from discord import Client, Guild, FFmpegPCMAudio, Embed
from discord.ext.commands import Context from discord.ext.commands import Context
from datetime import timedelta from datetime import timedelta
from Vulkan.Music.Downloader import Downloader from Music.Downloader import Downloader
from Vulkan.Music.Playlist import Playlist from Music.Playlist import Playlist
from Vulkan.Music.Searcher import Searcher from Music.Searcher import Searcher
from Vulkan.Music.Song import Song from Music.Song import Song
from Vulkan.Music.Types import Provider from Music.Types import Provider
from Vulkan.Music.utils import * from Music.utils import *
class Player(commands.Cog): class Player(commands.Cog):
@@ -21,7 +21,7 @@ class Player(commands.Cog):
self.__timer = Timer(self.__timeout_handler) self.__timer = Timer(self.__timeout_handler)
self.__playing = False self.__playing = False
self.__config = Config() self.__config = Configs()
# Flag to control if the player should stop totally the playing # Flag to control if the player should stop totally the playing
self.__force_stop = False self.__force_stop = False
@@ -249,7 +249,7 @@ class Player(commands.Cog):
self.__playlist.clear() self.__playlist.clear()
self.__playlist.loop_off() self.__playlist.loop_off()
except Exception as e: except Exception as e:
print(f'Force Stop Error: {e}') print(f'DEVELOPER NOTE -> Force Stop Error: {e}')
async def pause(self) -> bool: async def pause(self) -> bool:
if self.__guild.voice_client == None: if self.__guild.voice_client == None:

View File

@@ -1,8 +1,8 @@
from collections import deque from collections import deque
from typing import List from typing import List
from Config.Config import Config from Config.Config import Configs
from Vulkan.Music.Interfaces import IPlaylist from Music.Interfaces import IPlaylist
from Vulkan.Music.Song import Song from Music.Song import Song
import random import random
@@ -10,7 +10,7 @@ class Playlist(IPlaylist):
"""Class to manage and control the songs to play and played""" """Class to manage and control the songs to play and played"""
def __init__(self) -> None: def __init__(self) -> None:
self.__config = Config() self.__config = Configs()
self.__queue = deque() # Store the musics to play self.__queue = deque() # Store the musics to play
self.__songs_history = deque() # Store the musics played self.__songs_history = deque() # Store the musics played

View File

@@ -1,6 +1,6 @@
from Vulkan.Music.Types import Provider from Music.Types import Provider
from Vulkan.Music.Spotify import SpotifySearch from Music.Spotify import SpotifySearch
from Vulkan.Music.utils import is_url from Music.utils import is_url
class Searcher(): class Searcher():
@@ -16,7 +16,6 @@ class Searcher():
Return -> A list of musics names and Provider Type Return -> A list of musics names and Provider Type
""" """
provider = self.__identify_source(music) provider = self.__identify_source(music)
print(provider)
if provider == Provider.YouTube: if provider == Provider.YouTube:
return [music], Provider.YouTube return [music], Provider.YouTube
@@ -26,7 +25,7 @@ class Searcher():
musics = self.__Spotify.search(music) musics = self.__Spotify.search(music)
return musics, Provider.Name return musics, Provider.Name
else: else:
print('Spotify Not Connected') print('DEVELOPER NOTE -> Spotify Not Connected')
return [], Provider.Unknown return [], Provider.Unknown
elif provider == Provider.Name: elif provider == Provider.Name:

View File

@@ -1,4 +1,4 @@
from Vulkan.Music.Interfaces import ISong, IPlaylist from Music.Interfaces import ISong, IPlaylist
class Song(ISong): class Song(ISong):

View File

@@ -1,13 +1,13 @@
import spotipy import spotipy
from spotipy.oauth2 import SpotifyClientCredentials from spotipy.oauth2 import SpotifyClientCredentials
from Config.Config import Config from Config.Config import Configs
class SpotifySearch(): class SpotifySearch():
"""Search a Spotify music or playlist and return the musics names""" """Search a Spotify music or playlist and return the musics names"""
def __init__(self) -> None: def __init__(self) -> None:
self.__config = Config() self.__config = Configs()
self.__connected = False self.__connected = False
self.__connect() self.__connect()

View File

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

View File

@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from Vulkan.Controllers.ControllerResponse import ControllerResponse from Controllers.ControllerResponse import ControllerResponse
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client, Message from discord import Client, Message

View File

@@ -1,5 +1,5 @@
from Vulkan.Views.AbstractView import AbstractView from Views.AbstractView import AbstractView
from Vulkan.Controllers.ControllerResponse import ControllerResponse from Controllers.ControllerResponse import ControllerResponse
class EmbedView(AbstractView): class EmbedView(AbstractView):

View File

@@ -1,12 +1,12 @@
from discord import Embed from discord import Embed
from Config.Config import Config from Config.Config import Configs
from Config.Colors import Colors from Config.Colors import Colors
from datetime import timedelta from datetime import timedelta
class Embeds: class Embeds:
def __init__(self) -> None: def __init__(self) -> None:
self.__config = Config() self.__config = Configs()
self.__colors = Colors() self.__colors = Colors()
@property @property

View File

@@ -1,5 +1,5 @@
from Vulkan.Views.AbstractView import AbstractView from Views.AbstractView import AbstractView
from Vulkan.Controllers.ControllerResponse import ControllerResponse from Controllers.ControllerResponse import ControllerResponse
class EmoteView(AbstractView): class EmoteView(AbstractView):

View File

@@ -1,11 +1,11 @@
from Config.Singleton import Singleton from Config.Singleton import Singleton
from Config.Config import Config from Config.Config import Configs
class Helper(Singleton): class Helper(Singleton):
def __init__(self) -> None: def __init__(self) -> None:
if not super().created: if not super().created:
config = Config() config = Configs()
self.HELP_SKIP = 'Skip the current playing song.' 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_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 = 'Resumes the song player.'

71
config/Messages.py Normal file
View File

@@ -0,0 +1,71 @@
from Config.Singleton import Singleton
from Config.Config import Configs
class Messages(Singleton):
def __init__(self) -> None:
if not super().created:
configs = Configs()
self.STARTUP_MESSAGE = 'Starting Vulkan...'
self.STARTUP_COMPLETE_MESSAGE = 'Vulkan is now operating.'
self.INVITE_MESSAGE = 'To invite Vulkan to your own server, click [here]({})'
self.SONGINFO_UPLOADER = "Uploader: "
self.SONGINFO_DURATION = "Duration: "
self.SONGINFO_REQUESTER = 'Requester: '
self.SONGINFO_POSITION = 'Position: '
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 {configs.BOT_PREFIX}play to add new songs'
self.SONG_DOWNLOADING = '📥 Downloading...'
self.HISTORY_TITLE = '🎧 Played Songs'
self.HISTORY_EMPTY = '📜 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.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.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 {configs.BOT_PREFIX}reset'
self.INVALID_INPUT = f'This type of input was too strange, try something better or type {configs.BOT_PREFIX}help play'
self.DOWNLOADING_ERROR = '❌ An error occurred while downloading'
self.EXTRACTING_ERROR = '❌ An error ocurred while searching for the songs'
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.INVITE_URL = 'https://discordapp.com/oauth2/authorize?client_id={}&scope=bot>'
self.VIDEO_UNAVAILABLE = '❌ Sorry. This video is unavailable for download.'

View File

@@ -2,7 +2,7 @@ from decouple import config
from Config.Singleton import Singleton from Config.Singleton import Singleton
class Config(Singleton): class Configs(Singleton):
def __init__(self) -> None: def __init__(self) -> None:
if not super().created: if not super().created:
self.BOT_TOKEN = config('BOT_TOKEN') self.BOT_TOKEN = config('BOT_TOKEN')
@@ -80,10 +80,10 @@ class Config(Singleton):
self.INVITE_URL = 'https://discordapp.com/oauth2/authorize?client_id={}&scope=bot>' self.INVITE_URL = 'https://discordapp.com/oauth2/authorize?client_id={}&scope=bot>'
self.VIDEO_UNAVAILABLE = '❌ Sorry. This video is unavailable for download.' self.VIDEO_UNAVAILABLE = '❌ Sorry. This video is unavailable for download.'
self.COLOURS = { self.COLOURS = {
'red': 0xDC143C, 'red': 0xDC143C,
'green': 0x1F8B4C, 'green': 0x1F8B4C,
'grey': 0x708090, 'grey': 0x708090,
'blue': 0x206694, 'blue': 0x206694,
'black': 0x23272A 'black': 0x23272A
} }

View File

@@ -1,12 +1,12 @@
import discord import discord
import os import os
from config.Config import Config from Config.Config import Configs
from discord.ext import commands from discord.ext import commands
intents = discord.Intents.default() intents = discord.Intents.default()
intents.members = True intents.members = True
config = Config() config = Configs()
bot = commands.Bot(command_prefix=config.BOT_PREFIX, pm_help=True, bot = commands.Bot(command_prefix=config.BOT_PREFIX, pm_help=True,
case_insensitive=True, intents=intents) case_insensitive=True, intents=intents)
@@ -15,9 +15,9 @@ bot.remove_command('help')
if config.BOT_TOKEN == "": if config.BOT_TOKEN == "":
exit() exit()
for filename in os.listdir('./vulkan/commands'): for filename in os.listdir('./Commands'):
if filename.endswith('.py'): if filename.endswith('.py'):
bot.load_extension(f'vulkan.commands.{filename[:-3]}') bot.load_extension(f'Commands.{filename[:-3]}')
bot.run(config.BOT_TOKEN, bot=True, reconnect=True) bot.run(config.BOT_TOKEN, bot=True, reconnect=True)

View File

@@ -1,10 +0,0 @@
from Vulkan.Views.AbstractView import AbstractView
from Vulkan.Controllers.ControllerResponse import ControllerResponse
class MessageView(AbstractView):
def __init__(self, response: ControllerResponse) -> None:
super().__init__(response)
async def run(self) -> None:
return super().run()