From d3fe0a0744727dc699aa9805c7081a4fdfc8479e Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Sat, 10 Sep 2022 17:40:02 -0600 Subject: [PATCH] Utilize Client.interaction_tree --- jarvis/client/events/__init__.py | 59 +++++++++++++++++--------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/jarvis/client/events/__init__.py b/jarvis/client/events/__init__.py index ddb423c..d6d14c2 100644 --- a/jarvis/client/events/__init__.py +++ b/jarvis/client/events/__init__.py @@ -58,35 +58,38 @@ class EventMixin(MemberEventMixin, MessageEventMixin, ComponentEventMixin): "{}&permissions=8&scope=bot%20applications.commands".format(self.user.id) ) - global_base_commands = {} - guild_base_commands = {} - global_context_menus = [] - guild_context_menus = [] - for cid in self.interactions: - commands = self.interactions[cid] - to_update = global_base_commands if cid == 0 else guild_base_commands - for command in commands: - if isinstance(commands[command], ContextMenu): - if cid == 0: - global_context_menus.append(command) - else: - guild_context_menus.append(command) - continue - full = command.split(" ") - base = full[0] - if base not in to_update: - to_update[base] = {} - if len(full) == 3: - to_update[base][full[1]] = full[2] - elif len(full) == 2: - to_update[base][full[1]] = None + global_base_commands = 0 + guild_base_commands = 0 + global_context_menus = 0 + guild_context_menus = 0 + for cid in self.interaction_tree: + if cid == 0: + global_base_commands = sum( + 1 + for _ in self.interaction_tree[cid] + if not isinstance(self.interaction_tree[cid][_], ContextMenu) + ) + global_context_menus = sum( + 1 + for _ in self.interaction_tree[cid] + if isinstance(self.interaction_tree[cid][_], ContextMenu) + ) + else: + guild_base_commands += sum( + 1 + for _ in self.interaction_tree[cid] + if not isinstance(self.interaction_tree[cid][_], ContextMenu) + ) + guild_context_menus += sum( + 1 + for _ in self.interaction_tree[cid] + if isinstance(self.interaction_tree[cid][_], ContextMenu) + ) - self.logger.info( - "Loaded {:>2} global base slash commands".format(len(global_base_commands)) - ) - self.logger.info("Loaded {:>2} global context menus".format(len(global_context_menus))) - self.logger.info("Loaded {:>2} guild base slash commands".format(len(guild_base_commands))) - self.logger.info("Loaded {:>2} guild context menus".format(len(guild_context_menus))) + self.logger.info("Loaded {:>3} global base slash commands".format(global_base_commands)) + self.logger.info("Loaded {:>3} global context menus".format(global_context_menus)) + self.logger.info("Loaded {:>3} guild base slash commands".format(guild_base_commands)) + self.logger.info("Loaded {:>3} guild context menus".format(guild_context_menus)) self.logger.debug("Hitting Reminders for faster loads") _ = await Reminder.find().to_list(None)