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:
parent
dab1e4e9e0
commit
0349c36880
2
bot.py
2
bot.py
@ -9,7 +9,7 @@ from modules.common.boot_notice import post_boot_notice
|
|||||||
|
|
||||||
# Version consists of:
|
# Version consists of:
|
||||||
# Major.Enhancement.Minor.Patch.Test (Test is alphanumeric; doesn’t trigger auto update)
|
# 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 ----------
|
# ---------- Env loading ----------
|
||||||
|
|
||||||
|
@ -15,12 +15,13 @@ def _key_from_ctx(ctx: commands.Context) -> str:
|
|||||||
return f"{COUNTER_KEY_PREFIX}{name}"
|
return f"{COUNTER_KEY_PREFIX}{name}"
|
||||||
|
|
||||||
class UsageStatsCog(commands.Cog):
|
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):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
print("[usage] UsageStatsCog init")
|
print("[usage] UsageStatsCog init")
|
||||||
|
|
||||||
|
# -------- slash / app-commands --------
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_app_command_completion(self, interaction: discord.Interaction, command: discord.app_commands.Command):
|
async def on_app_command_completion(self, interaction: discord.Interaction, command: discord.app_commands.Command):
|
||||||
dm = getattr(self.bot, "data_manager", None)
|
dm = getattr(self.bot, "data_manager", None)
|
||||||
@ -33,11 +34,13 @@ class UsageStatsCog(commands.Cog):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("[usage] app !! incr failed:", repr(e))
|
print("[usage] app !! incr failed:", repr(e))
|
||||||
|
|
||||||
|
# -------- prefix (and hybrid-as-prefix) --------
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_command_completion(self, ctx: commands.Context):
|
async def on_command_completion(self, ctx: commands.Context):
|
||||||
# If a HybridCommand was invoked via slash, the app listener already counted it.
|
# If this Context came from a slash interaction (hybrid invoked via slash),
|
||||||
if isinstance(getattr(ctx, "command", None), commands.HybridCommand) and getattr(ctx, "interaction", None):
|
# DO NOT count here—the app listener already did.
|
||||||
print("[usage] px ~~ hybrid-as-slash; ignored (already counted in app)")
|
if getattr(ctx, "interaction", None):
|
||||||
|
print("[usage] px ~~ skip: ctx.interaction is set (slash path already counted)")
|
||||||
return
|
return
|
||||||
|
|
||||||
dm = getattr(self.bot, "data_manager", None)
|
dm = getattr(self.bot, "data_manager", None)
|
||||||
|
Loading…
Reference in New Issue
Block a user