From 2dc9ce169b45be1a35f498fdbe03c2fda1885a04 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 29 Jul 2016 14:37:11 +0200 Subject: [PATCH] commandlog should print when something errors now --- NadekoBot/Classes/NadekoStats.cs | 39 +++++++++++++++++++------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/NadekoBot/Classes/NadekoStats.cs b/NadekoBot/Classes/NadekoStats.cs index 3ba14adb..8161348a 100644 --- a/NadekoBot/Classes/NadekoStats.cs +++ b/NadekoBot/Classes/NadekoStats.cs @@ -46,21 +46,7 @@ namespace NadekoBot commandService.CommandExecuted += StatsCollector_RanCommand; commandService.CommandFinished += CommandService_CommandFinished; - commandService.CommandErrored += (s, e) => - { - try - { - if (e.ErrorType == CommandErrorType.Exception) - File.AppendAllText("errors.txt", $@"Command: {e.Command} -{e.Exception} -------------------------------------- -"); - } - catch - { - Console.WriteLine("Command errored errorring"); - } - }; + commandService.CommandErrored += CommandService_CommandFinished; Task.Run(StartCollecting); @@ -237,10 +223,31 @@ namespace NadekoBot private void CommandService_CommandFinished(object sender, CommandEventArgs e) { + DateTime dt; if (!commandTracker.TryGetValue(e.Message.Id, out dt)) return; - Console.WriteLine($">>COMMAND ENDED after *{(DateTime.UtcNow - dt).TotalSeconds}s*\nCmd: {e.Command.Text}\nMsg: {e.Message.Text}\nUsr: {e.User.Name} [{e.User.Id}]\nSrvr: {e.Server?.Name ?? "PRIVATE"} [{e.Server?.Id}]\n-----"); + try + { + if (e is CommandErrorEventArgs) + { + var er = e as CommandErrorEventArgs; + if (er.ErrorType == CommandErrorType.Exception) + { + File.AppendAllText("errors.txt", $@"Command: {er.Command} +{er.Exception} +------------------------------------- +"); + Console.WriteLine($">>COMMAND ERRORED after *{(DateTime.UtcNow - dt).TotalSeconds}s*\nCmd: {e.Command.Text}\nMsg: {e.Message.Text}\nUsr: {e.User.Name} [{e.User.Id}]\nSrvr: {e.Server?.Name ?? "PRIVATE"} [{e.Server?.Id}]\n-----"); + } + + } + else + { + Console.WriteLine($">>COMMAND ENDED after *{(DateTime.UtcNow - dt).TotalSeconds}s*\nCmd: {e.Command.Text}\nMsg: {e.Message.Text}\nUsr: {e.User.Name} [{e.User.Id}]\nSrvr: {e.Server?.Name ?? "PRIVATE"} [{e.Server?.Id}]\n-----"); + } + } + catch { } } private async void StatsCollector_RanCommand(object sender, CommandEventArgs e)