diff options
| author | 2020-01-12 20:25:04 +0100 | |
|---|---|---|
| committer | 2020-01-12 20:25:04 +0100 | |
| commit | ae9018eeb7c6470da6b5d157855d2e8c17071051 (patch) | |
| tree | 8eca63130c70c51ae50913550a683eb012393ad4 | |
| parent | Merge pull request #715 from Numerlor/doc-fix (diff) | |
| parent | Use parent path properly. (diff) | |
Merge pull request #725 from python-discord/track-command-completions
Track command completions.
| -rw-r--r-- | bot/cogs/metrics.py | 21 | 
1 files changed, 20 insertions, 1 deletions
diff --git a/bot/cogs/metrics.py b/bot/cogs/metrics.py index 6d3cc67bd..fa858bbd6 100644 --- a/bot/cogs/metrics.py +++ b/bot/cogs/metrics.py @@ -1,7 +1,7 @@  from collections import defaultdict  from discord import Member, Message -from discord.ext.commands import Cog +from discord.ext.commands import Cog, Context  from prometheus_client import Counter, Gauge  from bot.bot import Bot @@ -29,6 +29,11 @@ class Metrics(Cog):              documentation="Guild messages by guild by channel.",              labelnames=('channel_id', 'guild_id', 'channel_name')          ) +        self.command_completions = Counter( +            name=f'{self.PREFIX}_command_completions', +            documentation="Completed commands by command by guild.", +            labelnames=('guild_id', 'command') +        )      @Cog.listener()      async def on_ready(self) -> None: @@ -71,6 +76,20 @@ class Metrics(Cog):              guild_id=message.guild.id,          ).inc() +    @Cog.listener() +    async def on_command_completion(self, ctx: Context) -> None: +        """Increment the command completion counter.""" +        if ctx.message.guild is not None: +            if ctx.command.full_parent_name: +                command = f'{ctx.command.full_parent_name} {ctx.command.name}' +            else: +                command = ctx.command.name + +            self.command_completions.labels( +                guild_id=ctx.message.guild.id, +                command=command, +            ).inc() +  def setup(bot: Bot) -> None:      """Load the Metrics cog."""  |