mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-22 18:57:59 -05:00
[Core] Make Requires.verify() wait until rules are loaded (#2857)
* Make Requires.verify() wait until rules are loaded Also ensures `Requires` objects are reset when unloaded, particularly in case a `Command` object manages to stay in memory between cog unload and load, and its permissions rules change between those events. Also, this PR re-ordered some of the event loop policy stuff, because it was required that the event loop policy be set before creating any `Requires` objects. This may or may not have an effect on other `get_event_loop()` calls elsewhere (either in our code, a dependency's, or asyncio's). Either way, these effects would be a *correction*, and any bugs that arise from it are likely to have been occurring silently beforehand. Signed-off-by: Toby Harradine <tobyharradine@gmail.com> * Remove calls to `remove_listener()` in permissions Signed-off-by: Toby Harradine <tobyharradine@gmail.com> * Fix adding rules for permissions cog/commands itself Also addresses feedback Signed-off-by: Toby Harradine <tobyharradine@gmail.com> * Clean up indentation when setting uvloop policy Signed-off-by: Toby Harradine <tobyharradine@gmail.com> * Use `set(walk_commands())` to traverse `Group` subcommands Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
committed by
Michael H
parent
21a6384ebf
commit
f83f378528
@@ -4,10 +4,9 @@ from .permissions import Permissions
|
||||
async def setup(bot):
|
||||
cog = Permissions(bot)
|
||||
await cog.initialize()
|
||||
# It's important that these listeners are added prior to load, so
|
||||
# the permissions commands themselves have rules added.
|
||||
# Automatic listeners being added in add_cog happen in arbitrary
|
||||
# order, so we want to circumvent that.
|
||||
bot.add_listener(cog.red_cog_added, "on_cog_add")
|
||||
bot.add_listener(cog.red_command_added, "on_command_add")
|
||||
# We should add the rules for the Permissions cog and its own commands *before* adding the cog.
|
||||
# The actual listeners ought to skip the ones we're passing here.
|
||||
await cog._on_cog_add(cog)
|
||||
for command in cog.__cog_commands__:
|
||||
await cog._on_command_add(command)
|
||||
bot.add_cog(cog)
|
||||
|
||||
Reference in New Issue
Block a user