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)
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)
{
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,18 +192,18 @@ 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)
{

View File

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

View File

@ -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");