mirror of
https://github.com/RafaelSolVargas/Vulkan.git
synced 2025-10-29 16:57:23 +00:00
Chaging the folders and creating a separeted class for messages
This commit is contained in:
parent
2240c7535a
commit
a828350201
@ -2,7 +2,7 @@ import discord
|
||||
from discord import Client
|
||||
from discord.ext.commands.errors import CommandNotFound, MissingRequiredArgument, UserInputError
|
||||
from discord.ext import commands
|
||||
from Config.Config import Config
|
||||
from Config.Config import Configs
|
||||
from Config.Helper import Helper
|
||||
|
||||
helper = Helper()
|
||||
@ -13,7 +13,7 @@ class Control(commands.Cog):
|
||||
|
||||
def __init__(self, bot: Client):
|
||||
self.__bot = bot
|
||||
self.__config = Config()
|
||||
self.__config = Configs()
|
||||
self.__comandos = {
|
||||
'MUSIC': ['resume', 'pause', 'loop', 'stop',
|
||||
'skip', 'play', 'queue', 'clear',
|
||||
@ -2,13 +2,13 @@ from typing import Dict
|
||||
from discord import Guild, Client, Embed
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context
|
||||
from Config.Config import Config
|
||||
from Config.Config import Configs
|
||||
from Config.Helper import Helper
|
||||
from Vulkan.Music.Player import Player
|
||||
from Vulkan.Music.utils import is_connected
|
||||
from Vulkan.Controllers.SkipController import SkipController
|
||||
from Vulkan.Views.EmoteView import EmoteView
|
||||
from Vulkan.Views.EmbedView import EmbedView
|
||||
from Music.Player import Player
|
||||
from Music.utils import is_connected
|
||||
from Controllers.SkipController import SkipController
|
||||
from Views.EmoteView import EmoteView
|
||||
from Views.EmbedView import EmbedView
|
||||
|
||||
|
||||
helper = Helper()
|
||||
@ -18,7 +18,7 @@ class Music(commands.Cog):
|
||||
def __init__(self, bot) -> None:
|
||||
self.__guilds: Dict[Guild, Player] = {}
|
||||
self.__bot: Client = bot
|
||||
self.__config = Config()
|
||||
self.__config = Configs()
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self) -> None:
|
||||
@ -197,7 +197,7 @@ class Music(commands.Cog):
|
||||
player = self.__get_player(ctx)
|
||||
await player.force_stop()
|
||||
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)
|
||||
player = self.__get_player(ctx)
|
||||
@ -1,7 +1,7 @@
|
||||
from random import randint, random
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from Config.Config import Config
|
||||
from Config.Config import Configs
|
||||
from Config.Helper import Helper
|
||||
|
||||
helper = Helper()
|
||||
@ -12,7 +12,7 @@ class Random(commands.Cog):
|
||||
|
||||
def __init__(self, bot):
|
||||
self.__bot = bot
|
||||
self.__config = Config()
|
||||
self.__config = Configs()
|
||||
|
||||
@commands.command(name='random', help=helper.HELP_RANDOM, description=helper.HELP_RANDOM_LONG)
|
||||
async def random(self, ctx, arg: str) -> None:
|
||||
@ -1,12 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client, Guild
|
||||
from Vulkan.Controllers.PlayerController import PlayersController
|
||||
from Vulkan.Music.Player import Player
|
||||
from Vulkan.Controllers.ControllerResponse import ControllerResponse
|
||||
from Config.Config import Config
|
||||
from Controllers.PlayerController import PlayersController
|
||||
from Music.Player import Player
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from Config.Config import Configs
|
||||
from Config.Helper import Helper
|
||||
from Vulkan.Views.Embeds.Embeds import Embeds
|
||||
from Views.Embeds import Embeds
|
||||
|
||||
|
||||
class AbstractController(ABC):
|
||||
@ -16,7 +16,7 @@ class AbstractController(ABC):
|
||||
self.__player: Player = self.__controller.get_player(ctx.guild)
|
||||
self.__guild: Guild = ctx.guild
|
||||
self.__ctx: Context = ctx
|
||||
self.__config = Config()
|
||||
self.__config = Configs()
|
||||
self.__helper = Helper()
|
||||
self.__embeds = Embeds()
|
||||
|
||||
@ -41,7 +41,7 @@ class AbstractController(ABC):
|
||||
return self.__bot
|
||||
|
||||
@property
|
||||
def config(self) -> Config:
|
||||
def config(self) -> Configs:
|
||||
return self.__config
|
||||
|
||||
@property
|
||||
@ -1,6 +1,6 @@
|
||||
from typing import Union
|
||||
from discord.ext.commands import Context
|
||||
from Vulkan.Exceptions.Exceptions import Error
|
||||
from Exceptions.Exceptions import Error
|
||||
from discord import Embed
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from typing import Dict, List, Union
|
||||
from Config.Singleton import Singleton
|
||||
from discord import Guild, Client, VoiceClient
|
||||
from Vulkan.Music.Player import Player
|
||||
from Music.Player import Player
|
||||
|
||||
|
||||
class PlayersController(Singleton):
|
||||
@ -1,8 +1,8 @@
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client
|
||||
from Vulkan.Controllers.AbstractController import AbstractController
|
||||
from Vulkan.Exceptions.Exceptions import BadCommandUsage
|
||||
from Vulkan.Controllers.ControllerResponse import ControllerResponse
|
||||
from Controllers.AbstractController import AbstractController
|
||||
from Exceptions.Exceptions import BadCommandUsage
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
|
||||
|
||||
class SkipController(AbstractController):
|
||||
@ -1,4 +1,4 @@
|
||||
from config.Config import Config
|
||||
from Config.Config import Configs
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
@ -18,7 +18,7 @@ class Error(Exception):
|
||||
|
||||
class ImpossibleMove(Error):
|
||||
def __init__(self, message='', title='', *args: object) -> None:
|
||||
config = Config()
|
||||
config = Configs()
|
||||
if title == '':
|
||||
title = config.IMPOSSIBLE_MOVE
|
||||
super().__init__(message, title, *args)
|
||||
@ -1,15 +1,15 @@
|
||||
import asyncio
|
||||
from typing import List
|
||||
from Config.Config import Config
|
||||
from Config.Config import Configs
|
||||
from yt_dlp import YoutubeDL
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from Vulkan.Music.Song import Song
|
||||
from Vulkan.Music.utils import is_url, run_async
|
||||
from Music.Song import Song
|
||||
from 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()
|
||||
config = Configs()
|
||||
__YDL_OPTIONS = {'format': 'bestaudio/best',
|
||||
'default_search': 'auto',
|
||||
'playliststart': 0,
|
||||
@ -31,7 +31,7 @@ class Downloader():
|
||||
__BASE_URL = 'https://www.youtube.com/watch?v={}'
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.__config = Config()
|
||||
self.__config = Configs()
|
||||
self.__music_keys_only = ['resolution', 'fps', 'quality']
|
||||
self.__not_extracted_keys_only = ['ie_key']
|
||||
self.__not_extracted_not_keys = ['entries']
|
||||
@ -1,14 +1,14 @@
|
||||
from discord.ext import commands
|
||||
from Config.Config import Config
|
||||
from Config.Config import Configs
|
||||
from discord import Client, Guild, FFmpegPCMAudio, Embed
|
||||
from discord.ext.commands import Context
|
||||
from datetime import timedelta
|
||||
from Vulkan.Music.Downloader import Downloader
|
||||
from Vulkan.Music.Playlist import Playlist
|
||||
from Vulkan.Music.Searcher import Searcher
|
||||
from Vulkan.Music.Song import Song
|
||||
from Vulkan.Music.Types import Provider
|
||||
from Vulkan.Music.utils import *
|
||||
from Music.Downloader import Downloader
|
||||
from Music.Playlist import Playlist
|
||||
from Music.Searcher import Searcher
|
||||
from Music.Song import Song
|
||||
from Music.Types import Provider
|
||||
from Music.utils import *
|
||||
|
||||
|
||||
class Player(commands.Cog):
|
||||
@ -21,7 +21,7 @@ class Player(commands.Cog):
|
||||
|
||||
self.__timer = Timer(self.__timeout_handler)
|
||||
self.__playing = False
|
||||
self.__config = Config()
|
||||
self.__config = Configs()
|
||||
|
||||
# Flag to control if the player should stop totally the playing
|
||||
self.__force_stop = False
|
||||
@ -249,7 +249,7 @@ class Player(commands.Cog):
|
||||
self.__playlist.clear()
|
||||
self.__playlist.loop_off()
|
||||
except Exception as e:
|
||||
print(f'Force Stop Error: {e}')
|
||||
print(f'DEVELOPER NOTE -> Force Stop Error: {e}')
|
||||
|
||||
async def pause(self) -> bool:
|
||||
if self.__guild.voice_client == None:
|
||||
@ -1,8 +1,8 @@
|
||||
from collections import deque
|
||||
from typing import List
|
||||
from Config.Config import Config
|
||||
from Vulkan.Music.Interfaces import IPlaylist
|
||||
from Vulkan.Music.Song import Song
|
||||
from Config.Config import Configs
|
||||
from Music.Interfaces import IPlaylist
|
||||
from Music.Song import Song
|
||||
import random
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ class Playlist(IPlaylist):
|
||||
"""Class to manage and control the songs to play and played"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.__config = Config()
|
||||
self.__config = Configs()
|
||||
self.__queue = deque() # Store the musics to play
|
||||
self.__songs_history = deque() # Store the musics played
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
from Vulkan.Music.Types import Provider
|
||||
from Vulkan.Music.Spotify import SpotifySearch
|
||||
from Vulkan.Music.utils import is_url
|
||||
from Music.Types import Provider
|
||||
from Music.Spotify import SpotifySearch
|
||||
from Music.utils import is_url
|
||||
|
||||
|
||||
class Searcher():
|
||||
@ -16,7 +16,6 @@ class Searcher():
|
||||
Return -> A list of musics names and Provider Type
|
||||
"""
|
||||
provider = self.__identify_source(music)
|
||||
print(provider)
|
||||
|
||||
if provider == Provider.YouTube:
|
||||
return [music], Provider.YouTube
|
||||
@ -26,7 +25,7 @@ class Searcher():
|
||||
musics = self.__Spotify.search(music)
|
||||
return musics, Provider.Name
|
||||
else:
|
||||
print('Spotify Not Connected')
|
||||
print('DEVELOPER NOTE -> Spotify Not Connected')
|
||||
return [], Provider.Unknown
|
||||
|
||||
elif provider == Provider.Name:
|
||||
@ -1,4 +1,4 @@
|
||||
from Vulkan.Music.Interfaces import ISong, IPlaylist
|
||||
from Music.Interfaces import ISong, IPlaylist
|
||||
|
||||
|
||||
class Song(ISong):
|
||||
@ -1,13 +1,13 @@
|
||||
import spotipy
|
||||
from spotipy.oauth2 import SpotifyClientCredentials
|
||||
from Config.Config import Config
|
||||
from Config.Config import Configs
|
||||
|
||||
|
||||
class SpotifySearch():
|
||||
"""Search a Spotify music or playlist and return the musics names"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.__config = Config()
|
||||
self.__config = Configs()
|
||||
self.__connected = False
|
||||
self.__connect()
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import re
|
||||
import asyncio
|
||||
from Config.Config import Config
|
||||
from Config.Config import Configs
|
||||
from functools import wraps, partial
|
||||
config = Config()
|
||||
config = Configs()
|
||||
|
||||
|
||||
def is_connected(ctx):
|
||||
@ -1,5 +1,5 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from Vulkan.Controllers.ControllerResponse import ControllerResponse
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
from discord.ext.commands import Context
|
||||
from discord import Client, Message
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
from Vulkan.Views.AbstractView import AbstractView
|
||||
from Vulkan.Controllers.ControllerResponse import ControllerResponse
|
||||
from Views.AbstractView import AbstractView
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
|
||||
|
||||
class EmbedView(AbstractView):
|
||||
@ -1,12 +1,12 @@
|
||||
from discord import Embed
|
||||
from Config.Config import Config
|
||||
from Config.Config import Configs
|
||||
from Config.Colors import Colors
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
class Embeds:
|
||||
def __init__(self) -> None:
|
||||
self.__config = Config()
|
||||
self.__config = Configs()
|
||||
self.__colors = Colors()
|
||||
|
||||
@property
|
||||
@ -1,5 +1,5 @@
|
||||
from Vulkan.Views.AbstractView import AbstractView
|
||||
from Vulkan.Controllers.ControllerResponse import ControllerResponse
|
||||
from Views.AbstractView import AbstractView
|
||||
from Controllers.ControllerResponse import ControllerResponse
|
||||
|
||||
|
||||
class EmoteView(AbstractView):
|
||||
@ -1,11 +1,11 @@
|
||||
from Config.Singleton import Singleton
|
||||
from Config.Config import Config
|
||||
from Config.Config import Configs
|
||||
|
||||
|
||||
class Helper(Singleton):
|
||||
def __init__(self) -> None:
|
||||
if not super().created:
|
||||
config = Config()
|
||||
config = Configs()
|
||||
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.'
|
||||
|
||||
71
config/Messages.py
Normal file
71
config/Messages.py
Normal 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.'
|
||||
@ -2,7 +2,7 @@ from decouple import config
|
||||
from Config.Singleton import Singleton
|
||||
|
||||
|
||||
class Config(Singleton):
|
||||
class Configs(Singleton):
|
||||
def __init__(self) -> None:
|
||||
if not super().created:
|
||||
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.VIDEO_UNAVAILABLE = '❌ Sorry. This video is unavailable for download.'
|
||||
|
||||
self.COLOURS = {
|
||||
'red': 0xDC143C,
|
||||
'green': 0x1F8B4C,
|
||||
'grey': 0x708090,
|
||||
'blue': 0x206694,
|
||||
'black': 0x23272A
|
||||
}
|
||||
self.COLOURS = {
|
||||
'red': 0xDC143C,
|
||||
'green': 0x1F8B4C,
|
||||
'grey': 0x708090,
|
||||
'blue': 0x206694,
|
||||
'black': 0x23272A
|
||||
}
|
||||
|
||||
8
main.py
8
main.py
@ -1,12 +1,12 @@
|
||||
import discord
|
||||
import os
|
||||
|
||||
from config.Config import Config
|
||||
from Config.Config import Configs
|
||||
from discord.ext import commands
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.members = True
|
||||
config = Config()
|
||||
config = Configs()
|
||||
|
||||
bot = commands.Bot(command_prefix=config.BOT_PREFIX, pm_help=True,
|
||||
case_insensitive=True, intents=intents)
|
||||
@ -15,9 +15,9 @@ bot.remove_command('help')
|
||||
if config.BOT_TOKEN == "":
|
||||
exit()
|
||||
|
||||
for filename in os.listdir('./vulkan/commands'):
|
||||
for filename in os.listdir('./Commands'):
|
||||
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)
|
||||
|
||||
@ -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()
|
||||
Loading…
x
Reference in New Issue
Block a user