Changing to pycord

This commit is contained in:
Rafael Vargas
2022-07-27 01:36:55 -03:00
parent 4a22b43ce9
commit fededdbb8c
27 changed files with 217 additions and 118 deletions

View File

@@ -1,22 +1,24 @@
from discord import Client, Game, Status, Embed from discord import Embed
from discord.ext.commands.errors import CommandNotFound, MissingRequiredArgument
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import Cog
from Config.Configs import Configs from Config.Configs import Configs
from Config.Helper import Helper from Config.Helper import Helper
from Config.Messages import Messages
from Config.Colors import Colors from Config.Colors import Colors
from Music.MusicBot import VulkanBot
from Views.Embeds import Embeds from Views.Embeds import Embeds
helper = Helper() helper = Helper()
class ControlCog(commands.Cog): class ControlCog(Cog):
"""Class to handle discord events""" """Class to handle discord events"""
def __init__(self, bot: Client): def __init__(self, bot: VulkanBot):
print('Eae3')
self.__bot = bot self.__bot = bot
print(self.__bot)
print(bot.extensions)
self.__config = Configs() self.__config = Configs()
self.__messages = Messages()
self.__colors = Colors() self.__colors = Colors()
self.__embeds = Embeds() self.__embeds = Embeds()
self.__commands = { self.__commands = {
@@ -28,27 +30,6 @@ class ControlCog(commands.Cog):
} }
@commands.Cog.listener()
async def on_ready(self):
print(self.__messages.STARTUP_MESSAGE)
await self.__bot.change_presence(status=Status.online, activity=Game(name=f"Vulkan | {self.__config.BOT_PREFIX}help"))
print(self.__messages.STARTUP_COMPLETE_MESSAGE)
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if isinstance(error, MissingRequiredArgument):
embed = self.__embeds.MISSING_ARGUMENTS()
await ctx.send(embed=embed)
elif isinstance(error, CommandNotFound):
embed = self.__embeds.COMMAND_NOT_FOUND()
await ctx.send(embed=embed)
else:
print(f'DEVELOPER NOTE -> Command Error: {error}')
embed = self.__embeds.UNKNOWN_ERROR()
await ctx.send(embed=embed)
@commands.command(name="help", help=helper.HELP_HELP, description=helper.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=''): async def help_msg(self, ctx, command_help=''):
if command_help != '': if command_help != '':
@@ -97,7 +78,7 @@ class ControlCog(commands.Cog):
colour=self.__colors.BLUE colour=self.__colors.BLUE
) )
embedhelp.set_thumbnail(url=self.__bot.user.avatar_url) embedhelp.set_thumbnail(url=self.__bot.user.avatar)
await ctx.send(embed=embedhelp) await ctx.send(embed=embedhelp)
@commands.command(name='invite', help=helper.HELP_INVITE, description=helper.HELP_INVITE_LONG, aliases=['convite', 'inv', 'convidar']) @commands.command(name='invite', help=helper.HELP_INVITE, description=helper.HELP_INVITE_LONG, aliases=['convite', 'inv', 'convidar'])

View File

@@ -232,4 +232,6 @@ class MusicCog(commands.Cog):
def setup(bot): def setup(bot):
print('Loading Music')
bot.add_cog(MusicCog(bot)) bot.add_cog(MusicCog(bot))
print('Voltou')

View File

@@ -1,5 +1,5 @@
from random import randint, random from random import randint, random
from discord import Client from Music.MusicBot import VulkanBot
from discord.ext.commands import Context, command, Cog from discord.ext.commands import Context, command, Cog
from Config.Helper import Helper from Config.Helper import Helper
from Views.Embeds import Embeds from Views.Embeds import Embeds
@@ -10,7 +10,10 @@ helper = Helper()
class RandomCog(Cog): class RandomCog(Cog):
"""Class to listen to commands of type Random""" """Class to listen to commands of type Random"""
def __init__(self, bot: Client): def __init__(self, bot: VulkanBot):
print('Eae2')
print(bot)
print(bot.extensions)
self.__embeds = Embeds() self.__embeds = Embeds()
@command(name='random', help=helper.HELP_RANDOM, description=helper.HELP_RANDOM_LONG, aliases=['rand']) @command(name='random', help=helper.HELP_RANDOM, description=helper.HELP_RANDOM_LONG, aliases=['rand'])

View File

@@ -3,6 +3,7 @@ from typing import List
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client, Guild, ClientUser, Member from discord import Client, Guild, ClientUser, Member
from Config.Messages import Messages from Config.Messages import Messages
from Music.MusicBot import VulkanBot
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Config.Configs import Configs from Config.Configs import Configs
from Config.Helper import Helper from Config.Helper import Helper
@@ -10,8 +11,8 @@ from Views.Embeds import Embeds
class AbstractHandler(ABC): class AbstractHandler(ABC):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
self.__bot: Client = bot self.__bot: VulkanBot = bot
self.__guild: Guild = ctx.guild self.__guild: Guild = ctx.guild
self.__ctx: Context = ctx self.__ctx: Context = ctx
self.__bot_user: ClientUser = self.__bot.user self.__bot_user: ClientUser = self.__bot.user

View File

@@ -1,12 +1,12 @@
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client from discord import VulkanBot
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Parallelism.ProcessManager import ProcessManager from Parallelism.ProcessManager import ProcessManager
class ClearHandler(AbstractHandler): class ClearHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
async def run(self) -> HandlerResponse: async def run(self) -> HandlerResponse:

View File

@@ -1,5 +1,5 @@
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client from Music.MusicBot import VulkanBot
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Utils.Utils import Utils from Utils.Utils import Utils
@@ -7,7 +7,7 @@ from Parallelism.ProcessManager import ProcessManager
class HistoryHandler(AbstractHandler): class HistoryHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
async def run(self) -> HandlerResponse: async def run(self) -> HandlerResponse:

View File

@@ -1,5 +1,5 @@
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client from Music.MusicBot import VulkanBot
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Config.Exceptions import BadCommandUsage from Config.Exceptions import BadCommandUsage
@@ -7,7 +7,7 @@ from Parallelism.ProcessManager import ProcessManager
class LoopHandler(AbstractHandler): class LoopHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
async def run(self, args: str) -> HandlerResponse: async def run(self, args: str) -> HandlerResponse:

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 discord import Client from Music.MusicBot import VulkanBot
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Config.Exceptions import BadCommandUsage, VulkanError, InvalidInput, NumberRequired, UnknownError from Config.Exceptions import BadCommandUsage, VulkanError, InvalidInput, NumberRequired, UnknownError
@@ -9,7 +9,7 @@ from Parallelism.ProcessManager import ProcessManager
class MoveHandler(AbstractHandler): class MoveHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
async def run(self, pos1: str, pos2: str) -> HandlerResponse: async def run(self, pos1: str, pos2: str) -> HandlerResponse:

View File

@@ -1,13 +1,13 @@
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Music.MusicBot import VulkanBot
from Utils.Cleaner import Cleaner from Utils.Cleaner import Cleaner
from Parallelism.ProcessManager import ProcessManager from Parallelism.ProcessManager import ProcessManager
class NowPlayingHandler(AbstractHandler): class NowPlayingHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
self.__cleaner = Cleaner() self.__cleaner = Cleaner()

View File

@@ -1,13 +1,13 @@
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Parallelism.ProcessManager import ProcessManager from Parallelism.ProcessManager import ProcessManager
from Parallelism.Commands import VCommands, VCommandsType from Parallelism.Commands import VCommands, VCommandsType
from Music.MusicBot import VulkanBot
class PauseHandler(AbstractHandler): class PauseHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
async def run(self) -> HandlerResponse: async def run(self) -> HandlerResponse:

View File

@@ -2,7 +2,6 @@ import asyncio
from typing import List from typing import List
from Config.Exceptions import DownloadingError, InvalidInput, VulkanError from Config.Exceptions import DownloadingError, InvalidInput, VulkanError
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Config.Exceptions import ImpossibleMove, UnknownError from Config.Exceptions import ImpossibleMove, UnknownError
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
@@ -12,10 +11,11 @@ from Music.Song import Song
from Parallelism.ProcessManager import ProcessManager from Parallelism.ProcessManager import ProcessManager
from Parallelism.ProcessInfo import ProcessInfo from Parallelism.ProcessInfo import ProcessInfo
from Parallelism.Commands import VCommands, VCommandsType from Parallelism.Commands import VCommands, VCommandsType
from Music.MusicBot import VulkanBot
class PlayHandler(AbstractHandler): class PlayHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
self.__searcher = Searcher() self.__searcher = Searcher()
self.__down = Downloader() self.__down = Downloader()

View File

@@ -1,14 +1,14 @@
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Config.Exceptions import BadCommandUsage, ImpossibleMove from Config.Exceptions import BadCommandUsage, ImpossibleMove
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Parallelism.ProcessManager import ProcessManager from Parallelism.ProcessManager import ProcessManager
from Parallelism.Commands import VCommands, VCommandsType from Parallelism.Commands import VCommands, VCommandsType
from Music.MusicBot import VulkanBot
class PrevHandler(AbstractHandler): class PrevHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
async def run(self) -> HandlerResponse: async def run(self) -> HandlerResponse:

View File

@@ -1,14 +1,14 @@
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Music.Downloader import Downloader from Music.Downloader import Downloader
from Utils.Utils import Utils from Utils.Utils import Utils
from Parallelism.ProcessManager import ProcessManager from Parallelism.ProcessManager import ProcessManager
from Music.MusicBot import VulkanBot
class QueueHandler(AbstractHandler): class QueueHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
self.__down = Downloader() self.__down = Downloader()

View File

@@ -1,15 +1,15 @@
from typing import Union from typing import Union
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Config.Exceptions import BadCommandUsage, VulkanError, ErrorRemoving, InvalidInput, NumberRequired from Config.Exceptions import BadCommandUsage, VulkanError, ErrorRemoving, InvalidInput, NumberRequired
from Music.Playlist import Playlist from Music.Playlist import Playlist
from Parallelism.ProcessManager import ProcessManager from Parallelism.ProcessManager import ProcessManager
from Music.MusicBot import VulkanBot
class RemoveHandler(AbstractHandler): class RemoveHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
async def run(self, position: str) -> HandlerResponse: async def run(self, position: str) -> HandlerResponse:

View File

@@ -1,13 +1,13 @@
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Parallelism.ProcessManager import ProcessManager from Parallelism.ProcessManager import ProcessManager
from Parallelism.Commands import VCommands, VCommandsType from Parallelism.Commands import VCommands, VCommandsType
from Music.MusicBot import VulkanBot
class ResetHandler(AbstractHandler): class ResetHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
async def run(self) -> HandlerResponse: async def run(self) -> HandlerResponse:

View File

@@ -1,13 +1,13 @@
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Parallelism.ProcessManager import ProcessManager from Parallelism.ProcessManager import ProcessManager
from Parallelism.Commands import VCommands, VCommandsType from Parallelism.Commands import VCommands, VCommandsType
from Music.MusicBot import VulkanBot
class ResumeHandler(AbstractHandler): class ResumeHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
async def run(self) -> HandlerResponse: async def run(self) -> HandlerResponse:

View File

@@ -1,13 +1,13 @@
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Config.Exceptions import UnknownError from Config.Exceptions import UnknownError
from Parallelism.ProcessManager import ProcessManager from Parallelism.ProcessManager import ProcessManager
from Music.MusicBot import VulkanBot
class ShuffleHandler(AbstractHandler): class ShuffleHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
async def run(self) -> HandlerResponse: async def run(self) -> HandlerResponse:

View File

@@ -1,14 +1,14 @@
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Config.Exceptions import BadCommandUsage from Config.Exceptions import BadCommandUsage
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Music.MusicBot import VulkanBot
from Parallelism.ProcessManager import ProcessManager from Parallelism.ProcessManager import ProcessManager
from Parallelism.Commands import VCommands, VCommandsType from Parallelism.Commands import VCommands, VCommandsType
class SkipHandler(AbstractHandler): class SkipHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
async def run(self) -> HandlerResponse: async def run(self) -> HandlerResponse:

View File

@@ -1,13 +1,13 @@
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client
from Handlers.AbstractHandler import AbstractHandler from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from Music.MusicBot import VulkanBot
from Parallelism.ProcessManager import ProcessManager from Parallelism.ProcessManager import ProcessManager
from Parallelism.Commands import VCommands, VCommandsType from Parallelism.Commands import VCommands, VCommandsType
class StopHandler(AbstractHandler): class StopHandler(AbstractHandler):
def __init__(self, ctx: Context, bot: Client) -> None: def __init__(self, ctx: Context, bot: VulkanBot) -> None:
super().__init__(ctx, bot) super().__init__(ctx, bot)
async def run(self) -> HandlerResponse: async def run(self) -> HandlerResponse:

73
Music/MusicBot.py Normal file
View File

@@ -0,0 +1,73 @@
from asyncio import AbstractEventLoop
from discord import Guild, Status, Game, Message
from discord.ext.commands.errors import CommandNotFound, MissingRequiredArgument
from Config.Configs import Configs
from discord.ext import commands
from Config.Messages import Messages
from Views.Embeds import Embeds
class VulkanBot(commands.Bot):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__configs = Configs()
self.__messages = Messages()
self.__embeds = Embeds()
self.remove_command("help")
def startBot(self) -> None:
"""Blocking function that will start the bot"""
if self.__configs.BOT_TOKEN == '':
print('DEVELOPER NOTE -> Token not found')
exit()
super().run(self.__configs.BOT_TOKEN, reconnect=True)
async def startBotCoro(self, loop: AbstractEventLoop) -> None:
"""Start a bot coroutine, does not wait for connection to be established"""
task = loop.create_task(self.__login())
await task
loop.create_task(self.__connect())
async def __login(self):
"""Coroutine to login the Bot in discord"""
await self.login(token=self.__configs.BOT_TOKEN)
async def __connect(self):
"""Coroutine to connect the Bot in discord"""
await self.connect(reconnect=True)
async def on_ready(self):
print(self.__messages.STARTUP_MESSAGE)
await self.change_presence(status=Status.online, activity=Game(name=f"Vulkan | {self.__configs.BOT_PREFIX}help"))
print(self.__messages.STARTUP_COMPLETE_MESSAGE)
async def on_command_error(self, ctx, error):
if isinstance(error, MissingRequiredArgument):
embed = self.__embeds.MISSING_ARGUMENTS()
await ctx.send(embed=embed)
elif isinstance(error, CommandNotFound):
embed = self.__embeds.COMMAND_NOT_FOUND()
await ctx.send(embed=embed)
else:
print(f'DEVELOPER NOTE -> Command Error: {error}')
embed = self.__embeds.UNKNOWN_ERROR()
await ctx.send(embed=embed)
async def process_commands(self, message: Message):
if message.author.bot:
return
ctx = await self.get_context(message, cls=Context)
if ctx.valid and not message.guild:
return
await self.invoke(ctx)
class Context(commands.Context):
bot: VulkanBot
guild: Guild

View File

@@ -0,0 +1,43 @@
from random import choices
import string
from discord.bot import Bot
from discord import Intents
from Music.MusicBot import VulkanBot
from os import listdir
from Config.Configs import Configs
class VulkanInitializer:
def __init__(self, willListen: bool) -> None:
self.__config = Configs()
self.__intents = Intents.default()
self.__intents.message_content = True
self.__intents.members = True
self.__bot = self.__create_bot(willListen)
self.__add_cogs(self.__bot)
def getBot(self) -> VulkanBot:
return self.__bot
def __create_bot(self, willListen: bool) -> VulkanBot:
if willListen:
prefix = self.__config.BOT_PREFIX
else:
prefix = ''.join(choices(string.ascii_uppercase + string.digits, k=4))
bot = VulkanBot(command_prefix=prefix,
pm_help=True,
case_insensitive=True,
intents=self.__intents)
return bot
def __add_cogs(self, bot: Bot) -> None:
try:
for filename in listdir(f'./{self.__config.COMMANDS_PATH}'):
if filename.endswith('.py'):
print(f'Loading {filename}')
bot.load_extension(f'{self.__config.COMMANDS_PATH}.{filename[:-3]}')
bot.load_extension(f'DiscordCogs.MusicCog')
except Exception as e:
print(e)

View File

@@ -1,6 +1,6 @@
import asyncio import asyncio
from os import listdir from Music.VulkanInitializer import VulkanInitializer
from discord import Intents, User, Member, Message, Embed from discord import User, Member, Message, Embed
from asyncio import AbstractEventLoop, Semaphore from asyncio import AbstractEventLoop, Semaphore
from multiprocessing import Process, Queue, RLock from multiprocessing import Process, Queue, RLock
from threading import Lock, Thread from threading import Lock, Thread
@@ -10,7 +10,7 @@ from Music.Playlist import Playlist
from Music.Song import Song from Music.Song import Song
from Config.Configs import Configs from Config.Configs import Configs
from Config.Messages import Messages from Config.Messages import Messages
from discord.ext.commands import Bot from Music.MusicBot import VulkanBot
from Views.Embeds import Embeds from Views.Embeds import Embeds
from Parallelism.Commands import VCommands, VCommandsType from Parallelism.Commands import VCommands, VCommandsType
@@ -50,7 +50,7 @@ class PlayerProcess(Process):
self.__authorID = authorID self.__authorID = authorID
# All information of discord context will be retrieved directly with discord API # All information of discord context will be retrieved directly with discord API
self.__guild: Guild = None self.__guild: Guild = None
self.__bot: Client = None self.__bot: VulkanBot = None
self.__voiceChannel: VoiceChannel = None self.__voiceChannel: VoiceChannel = None
self.__textChannel: TextChannel = None self.__textChannel: TextChannel = None
self.__author: User = None self.__author: User = None
@@ -270,30 +270,13 @@ class PlayerProcess(Process):
self.__playlist.clear() self.__playlist.clear()
self.__playlist.loop_off() self.__playlist.loop_off()
async def __createBotInstance(self) -> Client: async def __createBotInstance(self) -> VulkanBot:
"""Load a new bot instance that should not be directly called. """Load a new bot instance that should not be directly called."""
Get the guild, voice and text Channel in discord API using IDs passed in constructor initializer = VulkanInitializer(willListen=False)
""" bot = initializer.getBot()
intents = Intents.default()
intents.members = True
bot = Bot(command_prefix='Rafael',
pm_help=True,
case_insensitive=True,
intents=intents)
bot.remove_command('help')
# Add the Cogs for this bot too await bot.startBotCoro(self.__loop)
for filename in listdir(f'./{self.__configs.COMMANDS_PATH}'):
if filename.endswith('.py'):
bot.load_extension(f'{self.__configs.COMMANDS_PATH}.{filename[:-3]}')
# Login and connect the bot instance to discord API
task = self.__loop.create_task(bot.login(token=self.__configs.BOT_TOKEN, bot=True))
await task
self.__loop.create_task(bot.connect(reconnect=True))
# Sleep to wait connection to be established
await self.__ensureDiscordConnection(bot) await self.__ensureDiscordConnection(bot)
return bot return bot
async def __timeoutHandler(self) -> None: async def __timeoutHandler(self) -> None:
@@ -316,7 +299,7 @@ class PlayerProcess(Process):
except Exception as e: except Exception as e:
print(f'[Error in Timeout] -> {e}') print(f'[Error in Timeout] -> {e}')
async def __ensureDiscordConnection(self, bot: Client) -> None: async def __ensureDiscordConnection(self, bot: VulkanBot) -> None:
"""Await in this point until connection to discord is established""" """Await in this point until connection to discord is established"""
guild = None guild = None
while guild is None: while guild is None:

View File

@@ -1,16 +1,17 @@
from typing import List from typing import List
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client, Message, Embed from discord import Message, Embed
from Config.Singleton import Singleton from Config.Singleton import Singleton
from Music.MusicBot import VulkanBot
class Cleaner(Singleton): class Cleaner(Singleton):
def __init__(self, bot: Client = None) -> None: def __init__(self, bot: VulkanBot = None) -> None:
if not super().created: if not super().created:
self.__bot = bot self.__bot = bot
self.__clean_str = 'Uploader:' self.__clean_str = 'Uploader:'
def set_bot(self, bot: Client) -> None: def set_bot(self, bot: VulkanBot) -> None:
self.__bot = bot self.__bot = bot
async def clean_messages(self, ctx: Context, quant: int) -> None: async def clean_messages(self, ctx: Context, quant: int) -> None:

View File

@@ -1,7 +1,8 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from Handlers.HandlerResponse import HandlerResponse from Handlers.HandlerResponse import HandlerResponse
from discord.ext.commands import Context from discord.ext.commands import Context
from discord import Client, Message from discord import Message
from Music.MusicBot import VulkanBot
class AbstractView(ABC): class AbstractView(ABC):
@@ -9,14 +10,14 @@ class AbstractView(ABC):
self.__response: HandlerResponse = response self.__response: HandlerResponse = response
self.__context: Context = response.ctx self.__context: Context = response.ctx
self.__message: Message = response.ctx.message self.__message: Message = response.ctx.message
self.__bot: Client = response.ctx.bot self.__bot: VulkanBot = response.ctx.bot
@property @property
def response(self) -> HandlerResponse: def response(self) -> HandlerResponse:
return self.__response return self.__response
@property @property
def bot(self) -> Client: def bot(self) -> VulkanBot:
return self.__bot return self.__bot
@property @property

View File

@@ -334,7 +334,7 @@ class Embeds:
def CARA_COROA(self, result: str) -> Embed: def CARA_COROA(self, result: str) -> Embed:
embed = Embed( embed = Embed(
title='Cara Cora', title='Cara Coroa',
description=f'Result: {result}', description=f'Result: {result}',
colour=self.__colors.GREEN colour=self.__colors.GREEN
) )

55
main.py
View File

@@ -1,38 +1,49 @@
from discord import Intents, Client from random import choices
import string
from discord.bot import Bot
from discord import Intents
from Music.MusicBot import VulkanBot
from os import listdir from os import listdir
from Config.Configs import Configs from Config.Configs import Configs
from discord.ext.commands import Bot
class VulkanInitializer: class VulkanInitializer:
def __init__(self) -> None: def __init__(self, willListen: bool) -> None:
self.__config = Configs() self.__config = Configs()
self.__intents = Intents.default() self.__intents = Intents.default()
self.__intents.message_content = True
self.__intents.members = True self.__intents.members = True
self.__bot = self.__create_bot() self.__bot = self.__create_bot(willListen)
self.__add_cogs(self.__bot) self.__add_cogs(self.__bot)
def __create_bot(self) -> Client: def getBot(self) -> VulkanBot:
bot = Bot(command_prefix=self.__config.BOT_PREFIX, return self.__bot
pm_help=True,
case_insensitive=True, def __create_bot(self, willListen: bool) -> VulkanBot:
intents=self.__intents) if willListen:
bot.remove_command('help') prefix = self.__config.BOT_PREFIX
else:
prefix = ''.join(choices(string.ascii_uppercase + string.digits, k=4))
bot = VulkanBot(command_prefix=prefix,
pm_help=True,
case_insensitive=True,
intents=self.__intents)
return bot return bot
def __add_cogs(self, bot: Client) -> None: def __add_cogs(self, bot: Bot) -> None:
for filename in listdir(f'./{self.__config.COMMANDS_PATH}'): try:
if filename.endswith('.py'): for filename in listdir(f'./{self.__config.COMMANDS_PATH}'):
bot.load_extension(f'{self.__config.COMMANDS_PATH}.{filename[:-3]}') if filename.endswith('.py'):
print(f'Loading {filename}')
bot.load_extension(f'{self.__config.COMMANDS_PATH}.{filename[:-3]}')
def run(self) -> None: bot.load_extension(f'DiscordCogs.MusicCog')
if self.__config.BOT_TOKEN == '': except Exception as e:
print('DEVELOPER NOTE -> Token not found') print(e)
exit()
self.__bot.run(self.__config.BOT_TOKEN, bot=True, reconnect=True)
if __name__ == '__main__': if __name__ == '__main__':
vulkan = VulkanInitializer() initializer = VulkanInitializer(willListen=True)
vulkan.run() vulkanBot = initializer.getBot()
vulkanBot.startBot()

Binary file not shown.