mirror of
https://github.com/stoatchat/python-client-sdk.git
synced 2026-07-22 10:35:25 -04:00
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:
@@ -19,6 +19,11 @@ Command
|
||||
.. autoclass:: revolt.ext.commands.Command
|
||||
:members:
|
||||
|
||||
Cog
|
||||
~~~~
|
||||
.. autoclass:: revolt.ext.commands.Cog
|
||||
:members:
|
||||
|
||||
command
|
||||
~~~~~~~~
|
||||
.. autodecorator:: revolt.ext.commands.command
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user