diff --git a/Common/Utilities.cs b/Common/Utilities.cs
index 55578eb..012841c 100644
--- a/Common/Utilities.cs
+++ b/Common/Utilities.cs
@@ -1,5 +1,6 @@
using Discord;
using System.Diagnostics.CodeAnalysis;
+using System.Text;
using System.Text.RegularExpressions;
namespace RegexBot.Common;
@@ -64,4 +65,45 @@ public static class Utilities {
}
return results;
}
+
+ ///
+ /// Builds and returns an embed which displays this log entry.
+ ///
+ public static Embed BuildEmbed(this Data.ModLogEntry entry, RegexbotClient bot) {
+ var logEmbed = new EmbedBuilder()
+ .WithTitle("Moderation log entry")
+ .WithTimestamp(entry.Timestamp)
+ .WithFooter($"Log ID {entry.LogId}");
+
+ string? issuedDisplay = null;
+ try {
+ var entityTry = new EntityName(entry.IssuedBy, EntityType.User);
+ var issueq = bot.EcQueryUser(entityTry.Id!.Value.ToString());
+ if (issueq != null) issuedDisplay = $"<@{issueq.UserId}> - {issueq.Username}#{issueq.Discriminator} `{issueq.UserId}`";
+ else issuedDisplay = $"Unknown user with ID `{entityTry.Id!.Value}`";
+ } catch (Exception) { }
+ issuedDisplay ??= entry.IssuedBy;
+ string targetDisplay;
+ var targetq = bot.EcQueryUser(entry.UserId.ToString());
+ if (targetq != null) targetDisplay = $"<@{targetq.UserId}> - {targetq.Username}#{targetq.Discriminator} `{targetq.UserId}`";
+ else targetDisplay = $"Unknown user with ID `{entry.UserId}`";
+
+ var contextStr = new StringBuilder();
+ contextStr.AppendLine($"Log type: {Enum.GetName(typeof(ModLogType), entry.LogType)}");
+ contextStr.AppendLine($"Regarding user: {targetDisplay}");
+ contextStr.AppendLine($"Logged by: {issuedDisplay}");
+
+ logEmbed.AddField(new EmbedFieldBuilder() {
+ Name = "Context",
+ Value = contextStr.ToString()
+ });
+ if (entry.Message != null) {
+ logEmbed.AddField(new EmbedFieldBuilder() {
+ Name = "Message",
+ Value = entry.Message
+ });
+ }
+
+ return logEmbed.Build();
+ }
}
diff --git a/Modules/ModLogs/ModLogs.cs b/Modules/ModLogs/ModLogs.cs
index d2dafee..5eb3a0d 100644
--- a/Modules/ModLogs/ModLogs.cs
+++ b/Modules/ModLogs/ModLogs.cs
@@ -10,9 +10,9 @@ internal partial class ModLogs : RegexbotModule {
// TODO consider resurrecting 2.x idea of logging actions to db, making it searchable?
public ModLogs(RegexbotClient bot) : base(bot) {
- // TODO missing logging features: joins, leaves, bans, kicks, user edits (nick/username/discr)
+ // TODO missing logging features: joins, leaves, user edits (nick/username/discr)
DiscordClient.MessageDeleted += HandleDelete;
- bot.SharedEventReceived += FilterIncomingEvents;
+ bot.SharedEventReceived += HandleReceivedSharedEvent;
}
public override Task