Reduce calls to config in the on_command_add event (#3764)

* lets reduce config calls here

Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>

* stop using `bot.guilds` in `on_command_add`

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
Draper 2020-04-20 18:10:58 +01:00 committed by GitHub
parent d12fcac9af
commit df7ca65108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -905,15 +905,15 @@ def get_command_disabler(guild: discord.Guild) -> Callable[["Context"], Awaitabl
``False`` if the context is within the given guild. ``False`` if the context is within the given guild.
""" """
try: try:
return __command_disablers[guild] return __command_disablers[guild.id]
except KeyError: except KeyError:
async def disabler(ctx: "Context") -> bool: async def disabler(ctx: "Context") -> bool:
if ctx.guild == guild: if ctx.guild is not None and ctx.guild.id == guild.id:
raise DisabledCommand() raise DisabledCommand()
return True return True
__command_disablers[guild] = disabler __command_disablers[guild.id] = disabler
return disabler return disabler

View File

@ -262,10 +262,11 @@ def init_events(bot, cli_flags):
disabled_commands = await bot._config.disabled_commands() disabled_commands = await bot._config.disabled_commands()
if command.qualified_name in disabled_commands: if command.qualified_name in disabled_commands:
command.enabled = False command.enabled = False
for guild in bot.guilds: guild_data = await bot._config.all_guilds()
disabled_commands = await bot._config.guild(guild).disabled_commands() for guild_id, data in guild_data.items():
disabled_commands = data.get("disabled_commands", [])
if command.qualified_name in disabled_commands: if command.qualified_name in disabled_commands:
command.disable_in(guild) command.disable_in(discord.Object(id=guild_id))
async def _guild_added(guild: discord.Guild): async def _guild_added(guild: discord.Guild):
disabled_commands = await bot._config.guild(guild).disabled_commands() disabled_commands = await bot._config.guild(guild).disabled_commands()