Properly register command statistics

This commit is contained in:
Ske 2019-12-21 21:51:41 +01:00
parent 5fc654b758
commit 7b55abaacd

View File

@ -1,8 +1,9 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using App.Metrics;
using Discord; using Discord;
using Discord.Net;
using Discord.WebSocket; using Discord.WebSocket;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -19,6 +20,7 @@ namespace PluralKit.Bot.CommandSystem
private readonly IDataStore _data; private readonly IDataStore _data;
private readonly PKSystem _senderSystem; private readonly PKSystem _senderSystem;
private readonly IMetrics _metrics;
private Command _currentCommand; private Command _currentCommand;
@ -29,6 +31,7 @@ namespace PluralKit.Bot.CommandSystem
_message = message; _message = message;
_data = provider.GetRequiredService<IDataStore>(); _data = provider.GetRequiredService<IDataStore>();
_senderSystem = senderSystem; _senderSystem = senderSystem;
_metrics = provider.GetRequiredService<IMetrics>();
_provider = provider; _provider = provider;
_parameters = new Parameters(message.Content.Substring(commandParseOffset)); _parameters = new Parameters(message.Content.Substring(commandParseOffset));
} }
@ -75,6 +78,7 @@ namespace PluralKit.Bot.CommandSystem
try try
{ {
await handler(_provider.GetRequiredService<T>()); await handler(_provider.GetRequiredService<T>());
_metrics.Measure.Meter.Mark(BotMetrics.CommandsRun);
} }
catch (PKSyntaxError e) catch (PKSyntaxError e)
{ {