mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Core] Cog load fixes (#2854)
* split out some fixes from red#2853 * address feedback * feedback
This commit is contained in:
parent
e34eca557b
commit
ac2813012a
@ -407,9 +407,14 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: d
|
|||||||
f"not inherit from the commands.Cog base class. The cog author must update "
|
f"not inherit from the commands.Cog base class. The cog author must update "
|
||||||
f"the cog to adhere to this requirement."
|
f"the cog to adhere to this requirement."
|
||||||
)
|
)
|
||||||
|
if cog.__cog_name__ in self.cogs:
|
||||||
|
raise RuntimeError(f"There is already a cog named {cog.__cog_name__} loaded.")
|
||||||
if not hasattr(cog, "requires"):
|
if not hasattr(cog, "requires"):
|
||||||
commands.Cog.__init__(cog)
|
commands.Cog.__init__(cog)
|
||||||
|
|
||||||
|
added_hooks = []
|
||||||
|
|
||||||
|
try:
|
||||||
for cls in inspect.getmro(cog.__class__):
|
for cls in inspect.getmro(cog.__class__):
|
||||||
try:
|
try:
|
||||||
hook = getattr(cog, f"_{cls.__name__}__permissions_hook")
|
hook = getattr(cog, f"_{cls.__name__}__permissions_hook")
|
||||||
@ -417,6 +422,7 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: d
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.add_permissions_hook(hook)
|
self.add_permissions_hook(hook)
|
||||||
|
added_hooks.append(hook)
|
||||||
|
|
||||||
for command in cog.__cog_commands__:
|
for command in cog.__cog_commands__:
|
||||||
|
|
||||||
@ -433,6 +439,18 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: d
|
|||||||
self.dispatch("cog_add", cog)
|
self.dispatch("cog_add", cog)
|
||||||
for command in cog.__cog_commands__:
|
for command in cog.__cog_commands__:
|
||||||
self.dispatch("command_add", command)
|
self.dispatch("command_add", command)
|
||||||
|
except Exception:
|
||||||
|
for hook in added_hooks:
|
||||||
|
try:
|
||||||
|
self.remove_permissions_hook(hook)
|
||||||
|
except Exception:
|
||||||
|
# This shouldn't be possible
|
||||||
|
log.exception(
|
||||||
|
"A hook got extremely screwed up, "
|
||||||
|
"and could not be removed properly during another error in cog load."
|
||||||
|
)
|
||||||
|
del cog
|
||||||
|
raise
|
||||||
|
|
||||||
def clear_permission_rules(self, guild_id: Optional[int]) -> None:
|
def clear_permission_rules(self, guild_id: Optional[int]) -> None:
|
||||||
"""Clear all permission overrides in a scope.
|
"""Clear all permission overrides in a scope.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user