Add cog_load and cog_unload method (#34)

* Add `cog_load` and `cog_unload` method

* Move `cog_load` to end

* Resolve conflict
This commit is contained in:
HigherOrderLogic
2022-04-25 19:31:08 +07:00
committed by GitHub
parent 4002be8d39
commit 94ba404912
2 changed files with 18 additions and 1 deletions
+5
View File
@@ -19,6 +19,11 @@ Command
.. autoclass:: revolt.ext.commands.Command
:members:
Cog
~~~~
.. autoclass:: revolt.ext.commands.Cog
:members:
command
~~~~~~~~
.. autodecorator:: revolt.ext.commands.command
+13 -1
View File
@@ -32,18 +32,30 @@ class Cog(metaclass=CogMeta):
_commands: list[Command]
qualified_name: str
def _inject(self, client: CommandsClient):
def cog_load(self):
"""A special method that is called when the cog gets loaded."""
pass
def cog_unload(self):
"""A special method that is called when the cog gets removed."""
pass
def _inject(self, client: CommandsClient):
client.cogs[self.qualified_name] = self
for command in self._commands:
command.cog = self
client.add_command(command)
self.cog_load()
def _uninject(self, client: CommandsClient):
for name, command in client.all_commands.copy().items():
if command in self._commands:
del client.all_commands[name]
self.cog_unload()
@property
def commands(self) -> list[Command]:
return self._commands