From 0349c368809f5c98b1ecdf0df96f99c6bff801db Mon Sep 17 00:00:00 2001 From: Franz Rolfsvaag Date: Sat, 16 Aug 2025 02:56:46 +0200 Subject: [PATCH] 0.4.1.0.a7 - Changed interaction check on command executions in an attempt to prevent hybrid commands from counting twice on the docsite --- bot.py | 2 +- modules/usage/usage_stats.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index 0b73699..efb516a 100644 --- a/bot.py +++ b/bot.py @@ -9,7 +9,7 @@ from modules.common.boot_notice import post_boot_notice # Version consists of: # Major.Enhancement.Minor.Patch.Test (Test is alphanumeric; doesn’t trigger auto update) -VERSION = "0.4.1.0.a6" +VERSION = "0.4.1.0.a7" # ---------- Env loading ---------- diff --git a/modules/usage/usage_stats.py b/modules/usage/usage_stats.py index 558a0a3..b29ef0f 100644 --- a/modules/usage/usage_stats.py +++ b/modules/usage/usage_stats.py @@ -15,12 +15,13 @@ def _key_from_ctx(ctx: commands.Context) -> str: return f"{COUNTER_KEY_PREFIX}{name}" class UsageStatsCog(commands.Cog): - """Count command runs without double-counting hybrids invoked as slash.""" + """Count command runs once: app for slash, prefix for non-interaction Context.""" def __init__(self, bot: commands.Bot): self.bot = bot print("[usage] UsageStatsCog init") + # -------- slash / app-commands -------- @commands.Cog.listener() async def on_app_command_completion(self, interaction: discord.Interaction, command: discord.app_commands.Command): dm = getattr(self.bot, "data_manager", None) @@ -33,11 +34,13 @@ class UsageStatsCog(commands.Cog): except Exception as e: print("[usage] app !! incr failed:", repr(e)) + # -------- prefix (and hybrid-as-prefix) -------- @commands.Cog.listener() async def on_command_completion(self, ctx: commands.Context): - # If a HybridCommand was invoked via slash, the app listener already counted it. - if isinstance(getattr(ctx, "command", None), commands.HybridCommand) and getattr(ctx, "interaction", None): - print("[usage] px ~~ hybrid-as-slash; ignored (already counted in app)") + # If this Context came from a slash interaction (hybrid invoked via slash), + # DO NOT count here—the app listener already did. + if getattr(ctx, "interaction", None): + print("[usage] px ~~ skip: ctx.interaction is set (slash path already counted)") return dm = getattr(self.bot, "data_manager", None)