From c660a0e970483d9c2085c3cff49163e0a9250012 Mon Sep 17 00:00:00 2001 From: Daniel-I-Am Date: Sun, 30 Aug 2020 16:40:14 +0200 Subject: [PATCH] Increase logging precision --- ChaosBot/Discord/Services/CommandHandler.cs | 30 +++++++++++-------- .../Discord/Services/CustomCommandHandler.cs | 2 ++ .../Discord/Services/ExperienceHandler.cs | 2 ++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/ChaosBot/Discord/Services/CommandHandler.cs b/ChaosBot/Discord/Services/CommandHandler.cs index e9dae59..4ed20bd 100644 --- a/ChaosBot/Discord/Services/CommandHandler.cs +++ b/ChaosBot/Discord/Services/CommandHandler.cs @@ -59,6 +59,11 @@ namespace ChaosBot.Discord.Services if (message.Source != MessageSource.User) return; + string messageToPrint = message.Content.Length > 50 + ? $"{message.Content.Substring(0, 50)}..." + : message.Content; + LoggingFacade.Trace($"Message Received [{message.Author.Username}#{message.Author.Discriminator} -> {messageToPrint}]"); + SocketCommandContext context = new SocketCommandContext(_client, message); int argPos = 0; @@ -67,17 +72,18 @@ namespace ChaosBot.Discord.Services if (!(message.HasMentionPrefix(_client.CurrentUser, ref argPos) || message.HasStringPrefix(prefix, ref argPos))) { - ExperienceHandler.AddXp(context); + if(Convert.ToBoolean(ConfigurationRepository.GetValue("Experience:Commands", context.Guild.Id, "false"))) + ExperienceHandler.AddXp(context); return; } - - if(Convert.ToBoolean(ConfigurationRepository.GetValue("Experience:Commands", context.Guild.Id, "false"))) - ExperienceHandler.AddXp(context); bool customCommandExecuted = await CustomCommandHandler.CheckCommand(context, argPos); - + if (!customCommandExecuted) - await _commands.ExecuteAsync(context, argPos, _services); + { + LoggingFacade.Info($"Executing command [{context.User.Username}#{context.User.Discriminator} -> {context.Message.Content.Substring(argPos)}]"); + await _commands.ExecuteAsync(context, argPos, _services); + } } catch (Exception ex) { @@ -186,23 +192,23 @@ namespace ChaosBot.Discord.Services { if (!command.IsSpecified) { - LoggingFacade.Error($"Command failed to execute for [{context.User.Username}] <-> [{result.ErrorReason}]!"); + LoggingFacade.Error($"Command execution failed [{context.User.Username}#{context.User.Discriminator} -> {command.Value.Name}]"); return; } if (result.IsSuccess) { - LoggingFacade.Info($"Command [{command.Value.Name}] executed for -> [{context.User.Username}]"); + LoggingFacade.Info($"Command executed [{context.User.Username}#{context.User.Discriminator} -> {command.Value.Name}]"); return; - } + } - LoggingFacade.Warn($"{context.User.Username} attempted to access {command.Value.Name} and was denied -> [{result}]"); - await context.Channel.SendMessageAsync($"Sorry, {context.User.Username}, that command won't work for you.!"); + LoggingFacade.Warn($"Command access denied [{context.User.Username}#{context.User.Discriminator} -> {command.Value.Name} ({result})]"); + await context.Channel.SendMessageAsync($"Sorry, {context.User.Mention}, that command won't work for you!"); } catch (Exception ex) { LoggingFacade.Exception(ex); } - } + } } } diff --git a/ChaosBot/Discord/Services/CustomCommandHandler.cs b/ChaosBot/Discord/Services/CustomCommandHandler.cs index 9cf7b56..00b536a 100644 --- a/ChaosBot/Discord/Services/CustomCommandHandler.cs +++ b/ChaosBot/Discord/Services/CustomCommandHandler.cs @@ -21,6 +21,8 @@ namespace ChaosBot.Discord.Services .FirstOrDefault(cc => command.StartsWith(cc.Command)); if (customCommand == null) return false; + + LoggingFacade.Info($"Running custom command [{context.User.Username}#{context.User.Discriminator} -> {customCommand.Command}]"); if (customCommand.Type == CustomCommandType.Basic) { diff --git a/ChaosBot/Discord/Services/ExperienceHandler.cs b/ChaosBot/Discord/Services/ExperienceHandler.cs index 8880bba..ade1678 100644 --- a/ChaosBot/Discord/Services/ExperienceHandler.cs +++ b/ChaosBot/Discord/Services/ExperienceHandler.cs @@ -65,6 +65,8 @@ namespace ChaosBot.Discord.Services if (newLevel > oldLevel) { // The user has leveled up, we can send a message + LoggingFacade.Info($"User leveled up [{context.User.Username}#{context.User.Discriminator} -> Level {newLevel}]"); + string channelToSendIn = ConfigurationRepository.GetValue("LevelUp:Channel", context.Guild.Id, "false");