Fixing errors due to new discor d library

This commit is contained in:
Rafael Vargas 2022-07-27 11:27:38 -03:00
parent fededdbb8c
commit beb0bc085d
25 changed files with 61 additions and 103 deletions

View File

@ -1,10 +1,9 @@
from discord import Embed
from discord.ext import commands
from discord.ext.commands import Cog
from discord.ext.commands import Cog, command
from Config.Configs import Configs
from Config.Helper import Helper
from Config.Colors import Colors
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
from Views.Embeds import Embeds
helper = Helper()
@ -14,10 +13,7 @@ class ControlCog(Cog):
"""Class to handle discord events"""
def __init__(self, bot: VulkanBot):
print('Eae3')
self.__bot = bot
print(self.__bot)
print(bot.extensions)
self.__config = Configs()
self.__colors = Colors()
self.__embeds = Embeds()
@ -30,7 +26,7 @@ class ControlCog(Cog):
}
@commands.command(name="help", help=helper.HELP_HELP, description=helper.HELP_HELP_LONG, aliases=['h', 'ajuda'])
@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:
@ -81,7 +77,7 @@ class ControlCog(Cog):
embedhelp.set_thumbnail(url=self.__bot.user.avatar)
await ctx.send(embed=embedhelp)
@commands.command(name='invite', help=helper.HELP_INVITE, description=helper.HELP_INVITE_LONG, aliases=['convite', 'inv', 'convidar'])
@command(name='invite', help=helper.HELP_INVITE, description=helper.HELP_INVITE_LONG, aliases=['convite', 'inv', 'convidar'])
async def invite_bot(self, ctx):
invite_url = self.__config.INVITE_URL.format(self.__bot.user.id)
txt = self.__config.INVITE_MESSAGE.format(invite_url, invite_url)

View File

@ -1,6 +1,5 @@
from discord import Guild, Client
from discord.ext import commands
from discord.ext.commands import Context
from discord.ext.commands import Context, command, Cog
from Config.Helper import Helper
from Handlers.ClearHandler import ClearHandler
from Handlers.MoveHandler import MoveHandler
@ -23,7 +22,7 @@ from Views.EmbedView import EmbedView
helper = Helper()
class MusicCog(commands.Cog):
class MusicCog(Cog):
"""
Class to listen to Music commands
It'll listen for commands from discord, when triggered will create a specific Handler for the command
@ -33,7 +32,7 @@ class MusicCog(commands.Cog):
def __init__(self, bot) -> None:
self.__bot: Client = bot
@commands.command(name="play", help=helper.HELP_PLAY, description=helper.HELP_PLAY_LONG, aliases=['p', 'tocar'])
@command(name="play", help=helper.HELP_PLAY, description=helper.HELP_PLAY_LONG, aliases=['p', 'tocar'])
async def play(self, ctx: Context, *args) -> None:
try:
controller = PlayHandler(ctx, self.__bot)
@ -47,7 +46,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name="queue", help=helper.HELP_QUEUE, description=helper.HELP_QUEUE_LONG, aliases=['q', 'fila', 'musicas'])
@command(name="queue", help=helper.HELP_QUEUE, description=helper.HELP_QUEUE_LONG, aliases=['q', 'fila', 'musicas'])
async def queue(self, ctx: Context) -> None:
try:
controller = QueueHandler(ctx, self.__bot)
@ -58,7 +57,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name="skip", help=helper.HELP_SKIP, description=helper.HELP_SKIP_LONG, aliases=['s', 'pular', 'next'])
@command(name="skip", help=helper.HELP_SKIP, description=helper.HELP_SKIP_LONG, aliases=['s', 'pular', 'next'])
async def skip(self, ctx: Context) -> None:
try:
controller = SkipHandler(ctx, self.__bot)
@ -73,7 +72,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name='stop', help=helper.HELP_STOP, description=helper.HELP_STOP_LONG, aliases=['parar'])
@command(name='stop', help=helper.HELP_STOP, description=helper.HELP_STOP_LONG, aliases=['parar'])
async def stop(self, ctx: Context) -> None:
try:
controller = StopHandler(ctx, self.__bot)
@ -88,7 +87,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name='pause', help=helper.HELP_PAUSE, description=helper.HELP_PAUSE_LONG, aliases=['pausar', 'pare'])
@command(name='pause', help=helper.HELP_PAUSE, description=helper.HELP_PAUSE_LONG, aliases=['pausar', 'pare'])
async def pause(self, ctx: Context) -> None:
try:
controller = PauseHandler(ctx, self.__bot)
@ -101,7 +100,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name='resume', help=helper.HELP_RESUME, description=helper.HELP_RESUME_LONG, aliases=['soltar', 'despausar'])
@command(name='resume', help=helper.HELP_RESUME, description=helper.HELP_RESUME_LONG, aliases=['soltar', 'despausar'])
async def resume(self, ctx: Context) -> None:
try:
controller = ResumeHandler(ctx, self.__bot)
@ -114,7 +113,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name='prev', help=helper.HELP_PREV, description=helper.HELP_PREV_LONG, aliases=['anterior', 'return', 'previous', 'back'])
@command(name='prev', help=helper.HELP_PREV, description=helper.HELP_PREV_LONG, aliases=['anterior', 'return', 'previous', 'back'])
async def prev(self, ctx: Context) -> None:
try:
controller = PrevHandler(ctx, self.__bot)
@ -128,7 +127,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name='history', help=helper.HELP_HISTORY, description=helper.HELP_HISTORY_LONG, aliases=['historico', 'anteriores', 'hist'])
@command(name='history', help=helper.HELP_HISTORY, description=helper.HELP_HISTORY_LONG, aliases=['historico', 'anteriores', 'hist'])
async def history(self, ctx: Context) -> None:
try:
controller = HistoryHandler(ctx, self.__bot)
@ -141,7 +140,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name='loop', help=helper.HELP_LOOP, description=helper.HELP_LOOP_LONG, aliases=['l', 'repeat'])
@command(name='loop', help=helper.HELP_LOOP, description=helper.HELP_LOOP_LONG, aliases=['l', 'repeat'])
async def loop(self, ctx: Context, args='') -> None:
try:
controller = LoopHandler(ctx, self.__bot)
@ -154,7 +153,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name='clear', help=helper.HELP_CLEAR, description=helper.HELP_CLEAR_LONG, aliases=['c', 'limpar'])
@command(name='clear', help=helper.HELP_CLEAR, description=helper.HELP_CLEAR_LONG, aliases=['c', 'limpar'])
async def clear(self, ctx: Context) -> None:
try:
controller = ClearHandler(ctx, self.__bot)
@ -165,7 +164,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name='np', help=helper.HELP_NP, description=helper.HELP_NP_LONG, aliases=['playing', 'now', 'this'])
@command(name='np', help=helper.HELP_NP, description=helper.HELP_NP_LONG, aliases=['playing', 'now', 'this'])
async def now_playing(self, ctx: Context) -> None:
try:
controller = NowPlayingHandler(ctx, self.__bot)
@ -178,7 +177,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name='shuffle', help=helper.HELP_SHUFFLE, description=helper.HELP_SHUFFLE_LONG, aliases=['aleatorio', 'misturar'])
@command(name='shuffle', help=helper.HELP_SHUFFLE, description=helper.HELP_SHUFFLE_LONG, aliases=['aleatorio', 'misturar'])
async def shuffle(self, ctx: Context) -> None:
try:
controller = ShuffleHandler(ctx, self.__bot)
@ -191,7 +190,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name='move', help=helper.HELP_MOVE, description=helper.HELP_MOVE_LONG, aliases=['m', 'mover'])
@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:
try:
controller = MoveHandler(ctx, self.__bot)
@ -204,7 +203,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name='remove', help=helper.HELP_REMOVE, description=helper.HELP_REMOVE_LONG, aliases=['remover'])
@command(name='remove', help=helper.HELP_REMOVE, description=helper.HELP_REMOVE_LONG, aliases=['remover'])
async def remove(self, ctx: Context, position) -> None:
try:
controller = RemoveHandler(ctx, self.__bot)
@ -217,7 +216,7 @@ class MusicCog(commands.Cog):
except Exception as e:
print(f'[ERROR IN COG] -> {e}')
@commands.command(name='reset', help=helper.HELP_RESET, description=helper.HELP_RESET_LONG, aliases=['resetar'])
@command(name='reset', help=helper.HELP_RESET, description=helper.HELP_RESET_LONG, aliases=['resetar'])
async def reset(self, ctx: Context) -> None:
try:
controller = ResetHandler(ctx, self.__bot)
@ -232,6 +231,4 @@ class MusicCog(commands.Cog):
def setup(bot):
print('Loading Music')
bot.add_cog(MusicCog(bot))
print('Voltou')

View File

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

View File

@ -3,7 +3,7 @@ from typing import List
from discord.ext.commands import Context
from discord import Client, Guild, ClientUser, Member
from Config.Messages import Messages
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
from Handlers.HandlerResponse import HandlerResponse
from Config.Configs import Configs
from Config.Helper import Helper

View File

@ -1,5 +1,5 @@
from discord.ext.commands import Context
from discord import VulkanBot
from Music.VulkanBot import VulkanBot
from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse
from Parallelism.ProcessManager import ProcessManager

View File

@ -1,5 +1,5 @@
from discord.ext.commands import Context
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse
from Utils.Utils import Utils

View File

@ -1,5 +1,5 @@
from discord.ext.commands import Context
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse
from Config.Exceptions import BadCommandUsage

View File

@ -1,6 +1,6 @@
from typing import Union
from discord.ext.commands import Context
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse
from Config.Exceptions import BadCommandUsage, VulkanError, InvalidInput, NumberRequired, UnknownError

View File

@ -1,7 +1,7 @@
from discord.ext.commands import Context
from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
from Utils.Cleaner import Cleaner
from Parallelism.ProcessManager import ProcessManager

View File

@ -3,7 +3,7 @@ from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse
from Parallelism.ProcessManager import ProcessManager
from Parallelism.Commands import VCommands, VCommandsType
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
class PauseHandler(AbstractHandler):

View File

@ -11,7 +11,7 @@ from Music.Song import Song
from Parallelism.ProcessManager import ProcessManager
from Parallelism.ProcessInfo import ProcessInfo
from Parallelism.Commands import VCommands, VCommandsType
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
class PlayHandler(AbstractHandler):

View File

@ -4,7 +4,7 @@ from Config.Exceptions import BadCommandUsage, ImpossibleMove
from Handlers.HandlerResponse import HandlerResponse
from Parallelism.ProcessManager import ProcessManager
from Parallelism.Commands import VCommands, VCommandsType
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
class PrevHandler(AbstractHandler):

View File

@ -4,7 +4,7 @@ from Handlers.HandlerResponse import HandlerResponse
from Music.Downloader import Downloader
from Utils.Utils import Utils
from Parallelism.ProcessManager import ProcessManager
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
class QueueHandler(AbstractHandler):

View File

@ -5,7 +5,7 @@ from Handlers.HandlerResponse import HandlerResponse
from Config.Exceptions import BadCommandUsage, VulkanError, ErrorRemoving, InvalidInput, NumberRequired
from Music.Playlist import Playlist
from Parallelism.ProcessManager import ProcessManager
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
class RemoveHandler(AbstractHandler):

View File

@ -3,7 +3,7 @@ from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse
from Parallelism.ProcessManager import ProcessManager
from Parallelism.Commands import VCommands, VCommandsType
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
class ResetHandler(AbstractHandler):

View File

@ -3,7 +3,7 @@ from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse
from Parallelism.ProcessManager import ProcessManager
from Parallelism.Commands import VCommands, VCommandsType
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
class ResumeHandler(AbstractHandler):

View File

@ -3,7 +3,7 @@ from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse
from Config.Exceptions import UnknownError
from Parallelism.ProcessManager import ProcessManager
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
class ShuffleHandler(AbstractHandler):

View File

@ -2,7 +2,7 @@ from discord.ext.commands import Context
from Handlers.AbstractHandler import AbstractHandler
from Config.Exceptions import BadCommandUsage
from Handlers.HandlerResponse import HandlerResponse
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
from Parallelism.ProcessManager import ProcessManager
from Parallelism.Commands import VCommands, VCommandsType

View File

@ -1,7 +1,7 @@
from discord.ext.commands import Context
from Handlers.AbstractHandler import AbstractHandler
from Handlers.HandlerResponse import HandlerResponse
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
from Parallelism.ProcessManager import ProcessManager
from Parallelism.Commands import VCommands, VCommandsType

View File

@ -2,12 +2,12 @@ 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 discord.ext.commands import Bot, Context
from Config.Messages import Messages
from Views.Embeds import Embeds
class VulkanBot(commands.Bot):
class VulkanBot(Bot):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__configs = Configs()
@ -68,6 +68,6 @@ class VulkanBot(commands.Bot):
await self.invoke(ctx)
class Context(commands.Context):
class Context(Context):
bot: VulkanBot
guild: Guild

View File

@ -2,9 +2,10 @@ from random import choices
import string
from discord.bot import Bot
from discord import Intents
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
from os import listdir
from Config.Configs import Configs
from Config.Exceptions import VulkanError
class VulkanInitializer:
@ -35,9 +36,18 @@ class VulkanInitializer:
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]}')
cogPath = f'{self.__config.COMMANDS_PATH}.{filename[:-3]}'
bot.load_extension(cogPath, store=True)
bot.load_extension(f'DiscordCogs.MusicCog')
except Exception as e:
print(e)
if len(bot.cogs.keys()) != self.__getTotalCogs():
raise VulkanError(message='Failed to load some Cog')
except VulkanError as e:
print(f'[Error Loading Vulkan] -> {e.message}')
def __getTotalCogs(self) -> int:
quant = 0
for filename in listdir(f'./{self.__config.COMMANDS_PATH}'):
if filename.endswith('.py'):
quant += 1
return quant

View File

@ -10,7 +10,7 @@ from Music.Playlist import Playlist
from Music.Song import Song
from Config.Configs import Configs
from Config.Messages import Messages
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
from Views.Embeds import Embeds
from Parallelism.Commands import VCommands, VCommandsType

View File

@ -2,7 +2,7 @@ from typing import List
from discord.ext.commands import Context
from discord import Message, Embed
from Config.Singleton import Singleton
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
class Cleaner(Singleton):

View File

@ -2,7 +2,7 @@ from abc import ABC, abstractmethod
from Handlers.HandlerResponse import HandlerResponse
from discord.ext.commands import Context
from discord import Message
from Music.MusicBot import VulkanBot
from Music.VulkanBot import VulkanBot
class AbstractView(ABC):

44
main.py
View File

@ -1,46 +1,4 @@
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)
from Music.VulkanInitializer import VulkanInitializer
if __name__ == '__main__':