Increase logging precision

This commit is contained in:
Daniel_I_Am 2020-08-30 16:40:14 +02:00
parent 76773074ad
commit c660a0e970
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84
3 changed files with 22 additions and 12 deletions

View File

@ -59,6 +59,11 @@ namespace ChaosBot.Discord.Services
if (message.Source != MessageSource.User) if (message.Source != MessageSource.User)
return; 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); SocketCommandContext context = new SocketCommandContext(_client, message);
int argPos = 0; int argPos = 0;
@ -67,18 +72,19 @@ namespace ChaosBot.Discord.Services
if (!(message.HasMentionPrefix(_client.CurrentUser, ref argPos) || if (!(message.HasMentionPrefix(_client.CurrentUser, ref argPos) ||
message.HasStringPrefix(prefix, ref argPos))) message.HasStringPrefix(prefix, ref argPos)))
{ {
if(Convert.ToBoolean(ConfigurationRepository.GetValue("Experience:Commands", context.Guild.Id, "false")))
ExperienceHandler.AddXp(context); ExperienceHandler.AddXp(context);
return; return;
} }
if(Convert.ToBoolean(ConfigurationRepository.GetValue("Experience:Commands", context.Guild.Id, "false")))
ExperienceHandler.AddXp(context);
bool customCommandExecuted = await CustomCommandHandler.CheckCommand(context, argPos); bool customCommandExecuted = await CustomCommandHandler.CheckCommand(context, argPos);
if (!customCommandExecuted) if (!customCommandExecuted)
{
LoggingFacade.Info($"Executing command [{context.User.Username}#{context.User.Discriminator} -> {context.Message.Content.Substring(argPos)}]");
await _commands.ExecuteAsync(context, argPos, _services); await _commands.ExecuteAsync(context, argPos, _services);
} }
}
catch (Exception ex) catch (Exception ex)
{ {
LoggingFacade.Exception(ex); LoggingFacade.Exception(ex);
@ -186,18 +192,18 @@ namespace ChaosBot.Discord.Services
{ {
if (!command.IsSpecified) 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; return;
} }
if (result.IsSuccess) 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; return;
} }
LoggingFacade.Warn($"{context.User.Username} attempted to access {command.Value.Name} and was denied -> [{result}]"); LoggingFacade.Warn($"Command access denied [{context.User.Username}#{context.User.Discriminator} -> {command.Value.Name} ({result})]");
await context.Channel.SendMessageAsync($"Sorry, {context.User.Username}, that command won't work for you.!"); await context.Channel.SendMessageAsync($"Sorry, {context.User.Mention}, that command won't work for you!");
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -22,6 +22,8 @@ namespace ChaosBot.Discord.Services
if (customCommand == null) return false; if (customCommand == null) return false;
LoggingFacade.Info($"Running custom command [{context.User.Username}#{context.User.Discriminator} -> {customCommand.Command}]");
if (customCommand.Type == CustomCommandType.Basic) if (customCommand.Type == CustomCommandType.Basic)
{ {
await context.Channel.SendMessageAsync(customCommand.Content); await context.Channel.SendMessageAsync(customCommand.Content);

View File

@ -65,6 +65,8 @@ namespace ChaosBot.Discord.Services
if (newLevel > oldLevel) if (newLevel > oldLevel)
{ {
// The user has leveled up, we can send a message // 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 = string channelToSendIn =
ConfigurationRepository.GetValue("LevelUp:Channel", context.Guild.Id, "false"); ConfigurationRepository.GetValue("LevelUp:Channel", context.Guild.Id, "false");