- Renamed CustomReaction model to NadekoExpression

- Used structured logging everywhere
This commit is contained in:
Kwoth
2022-01-04 07:35:55 +01:00
parent ef49030841
commit 3aa6a54b6e
30 changed files with 330 additions and 300 deletions

View File

@@ -116,7 +116,7 @@ public class ChatterBotService : IEarlyBehavior
try { await usrMsg.Channel.SendErrorAsync(_eb, returnMsg); }
catch { }
Log.Information(returnMsg);
Log.Information("{PermissionMessage}", returnMsg);
}
return true;
@@ -125,11 +125,19 @@ public class ChatterBotService : IEarlyBehavior
var cleverbotExecuted = await TryAsk(cbs, (ITextChannel)usrMsg.Channel, message);
if (cleverbotExecuted)
{
Log.Information($@"CleverBot Executed
Server: {guild.Name} [{guild.Id}]
Channel: {usrMsg.Channel?.Name} [{usrMsg.Channel?.Id}]
UserId: {usrMsg.Author} [{usrMsg.Author.Id}]
Message: {usrMsg.Content}");
Log.Information(@"CleverBot Executed
Server: {GuildName} [{GuildId}]
Channel: {ChannelName} [{ChannelId}]
UserId: {Author} [{AuthorId}]
Message: {Content}",
guild.Name,
guild.Id,
usrMsg.Channel?.Name,
usrMsg.Channel?.Id,
usrMsg.Author,
usrMsg.Author.Id,
usrMsg.Content);
return true;
}
}

View File

@@ -31,8 +31,7 @@ public class OfficialCleverbotSession : IChatterBotSession
}
catch
{
Log.Warning("Unexpected cleverbot response received: ");
Log.Warning(dataString);
Log.Warning("Unexpected cleverbot response received: {ResponseString}", dataString);
return null;
}
}

View File

@@ -11,8 +11,8 @@ public class TypingGame
public ITextChannel Channel { get; }
public string CurrentSentence { get; private set; }
public bool IsActive { get; private set; }
private readonly Stopwatch sw;
private readonly List<ulong> finishedUserIds;
private readonly Stopwatch _sw;
private readonly List<ulong> _finishedUserIds;
private readonly DiscordSocketClient _client;
private readonly GamesService _games;
private readonly string _prefix;
@@ -35,25 +35,24 @@ public class TypingGame
Channel = channel;
IsActive = false;
sw = new();
finishedUserIds = new();
_sw = new();
_finishedUserIds = new();
}
public async Task<bool> Stop()
{
if (!IsActive) return false;
_client.MessageReceived -= AnswerReceived;
finishedUserIds.Clear();
_finishedUserIds.Clear();
IsActive = false;
sw.Stop();
sw.Reset();
_sw.Stop();
_sw.Reset();
try
{
await Channel.SendConfirmAsync(_eb, "Typing contest stopped.");
}
catch (Exception ex)
catch
{
Log.Warning(ex.ToString());
}
return true;
@@ -88,7 +87,7 @@ public class TypingGame
{
m.Content = CurrentSentence.Replace(" ", " \x200B", StringComparison.InvariantCulture);
});
sw.Start();
_sw.Start();
HandleAnswers();
while (i > 0)
@@ -133,19 +132,19 @@ public class TypingGame
var distance = CurrentSentence.LevenshteinDistance(guess);
var decision = Judge(distance, guess.Length);
if (decision && !finishedUserIds.Contains(msg.Author.Id))
if (decision && !_finishedUserIds.Contains(msg.Author.Id))
{
var elapsed = sw.Elapsed;
var elapsed = _sw.Elapsed;
var wpm = CurrentSentence.Length / WORD_VALUE / elapsed.TotalSeconds * 60;
finishedUserIds.Add(msg.Author.Id);
_finishedUserIds.Add(msg.Author.Id);
await Channel.EmbedAsync(_eb.Create()
.WithOkColor()
.WithTitle($"{msg.Author} finished the race!")
.AddField("Place", $"#{finishedUserIds.Count}", true)
.AddField("Place", $"#{_finishedUserIds.Count}", true)
.AddField("WPM", $"{wpm:F1} *[{elapsed.TotalSeconds:F2}sec]*", true)
.AddField("Errors", distance.ToString(), true));
if (finishedUserIds.Count % 4 == 0)
if (_finishedUserIds.Count % 4 == 0)
await Channel.SendConfirmAsync(_eb,
":exclamation: A lot of people finished, here is the text for those still typing:"
+ $"\n\n**{Format.Sanitize(CurrentSentence.Replace(" ", " \x200B", StringComparison.InvariantCulture)).SanitizeMentions(true)}**");
@@ -153,7 +152,7 @@ public class TypingGame
}
catch (Exception ex)
{
Log.Warning(ex.ToString());
Log.Warning(ex, "Error receiving typing game answer: {ErrorMessage}", ex.Message);
}
});
return Task.CompletedTask;

View File

@@ -264,7 +264,7 @@ public class TriviaGame
embed.WithImageUrl(CurrentQuestion.AnswerImageUrl);
await Channel.EmbedAsync(embed);
}
catch (Exception ex) { Log.Warning(ex.ToString()); }
catch (Exception ex) { Log.Warning(ex, "Exception in a potential guess"); }
});
return Task.CompletedTask;
}