diff --git a/MeowerBot/cog.py b/MeowerBot/cog.py index 782187a..ba22fb1 100644 --- a/MeowerBot/cog.py +++ b/MeowerBot/cog.py @@ -5,7 +5,7 @@ class Cog: commands: dict[str, AppCommand] - callbacks: dict[str, list[types.CoroutineType[Any, Any, Any]]] + callbacks: dict[str, list[types.CoroutineType]] __instence__: Union["Cog", None] = None @@ -19,6 +19,12 @@ def __init__(self) -> None: self.update_commands() def update_commands(self): + if not hasattr(self, "commands"): + self.commands = {} + + if not hasattr(self, "callbacks"): + self.callbacks = {} + for command in self.__dir__(): attr = getattr(self, command) if isinstance(attr, AppCommand): diff --git a/tests/intergration/integration_login.py b/tests/intergration/integration_login.py index 42ac620..99fa6c6 100644 --- a/tests/intergration/integration_login.py +++ b/tests/intergration/integration_login.py @@ -1,5 +1,7 @@ from MeowerBot import Bot from MeowerBot.context import Context +from MeowerBot.cog import Cog +from MeowerBot.command import command import logging @@ -25,9 +27,22 @@ async def login(t): async def ping(ctx: Context): await ctx.send_msg("Pong!\n My latency is: " + str(bot.latency)) +class Ping(Cog): + def __init__(self, bot): + self.bot = bot + + @command() + async def cog_ping(self, ctx: Context): + await ctx.send_msg("Pong!\n My latency is: " + str(self.bot.latency)) + + @cog_ping.subcommand() + async def ping(self, ctx: Context): + await ctx.send_msg("Pong!\n My latency is: " + str(self.bot.latency)) @ping.subcommand(name="pong") async def pong(ctx: Context, *message: str): await ctx.send_msg(f"Pong!{" ".join(message)}") + +bot.register_cog(Ping(bot)) bot.register_cog(HelpExt(bot, disable_command_newlines=True)) bot.run(env["uname"], env["pswd"])