0.4.1.0.a7

- Changed interaction check on command executions in an attempt to prevent hybrid commands from counting twice on the docsite
This commit is contained in:
Franz Rolfsvaag 2025-08-16 02:56:46 +02:00
parent dab1e4e9e0
commit 0349c36880
2 changed files with 8 additions and 5 deletions

2
bot.py
View File

@ -9,7 +9,7 @@ from modules.common.boot_notice import post_boot_notice
# Version consists of:
# Major.Enhancement.Minor.Patch.Test (Test is alphanumeric; doesnt trigger auto update)
VERSION = "0.4.1.0.a6"
VERSION = "0.4.1.0.a7"
# ---------- Env loading ----------

View File

@ -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)