Add attachment information to message logs

This commit is contained in:
Noi 2022-07-28 14:10:07 -07:00
parent 724f35fea6
commit 0f15666810

View file

@ -30,7 +30,8 @@ internal partial class ModLogs {
var reportEmbed = new EmbedBuilder() var reportEmbed = new EmbedBuilder()
.WithTitle("Message deleted") .WithTitle("Message deleted")
.WithCurrentTimestamp(); .WithCurrentTimestamp()
.WithFooter($"User ID: {(cachedMsg == null ? "Unknown" : cachedMsg.AuthorId)}");
if (cachedMsg != null) { if (cachedMsg != null) {
if (cachedMsg.Content == null) { if (cachedMsg.Content == null) {
@ -52,6 +53,8 @@ internal partial class ModLogs {
IconUrl = cachedMsg.Author.AvatarUrl ?? GetDefaultAvatarUrl(cachedMsg.Author.Discriminator) IconUrl = cachedMsg.Author.AvatarUrl ?? GetDefaultAvatarUrl(cachedMsg.Author.Discriminator)
}; };
} }
var attach = CheckAttachments(cachedMsg.AttachmentNames);
if (attach != null) reportEmbed.AddField(attach);
} else { } else {
reportEmbed.Description = NotCached; reportEmbed.Description = NotCached;
} }
@ -84,7 +87,8 @@ internal partial class ModLogs {
var reportEmbed = new EmbedBuilder() var reportEmbed = new EmbedBuilder()
.WithTitle("Message edited") .WithTitle("Message edited")
.WithCurrentTimestamp(); .WithCurrentTimestamp()
.WithFooter($"User ID: {newMsg.Author.Id}");
reportEmbed.Author = new EmbedAuthorBuilder() { reportEmbed.Author = new EmbedAuthorBuilder() {
Name = $"{newMsg.Author.Username}#{newMsg.Author.Discriminator}", Name = $"{newMsg.Author.Username}#{newMsg.Author.Discriminator}",
@ -118,6 +122,9 @@ internal partial class ModLogs {
} }
reportEmbed.AddField(newField); reportEmbed.AddField(newField);
var attach = CheckAttachments(newMsg.Attachments.Select(a => a.Filename));
if (attach != null) reportEmbed.AddField(attach);
var contextStr = new StringBuilder(); var contextStr = new StringBuilder();
contextStr.AppendLine($"User: <@!{newMsg.Author.Id}>"); contextStr.AppendLine($"User: <@!{newMsg.Author.Id}>");
contextStr.AppendLine($"Channel: <#{channel.Id}> (#{channel.Name})"); contextStr.AppendLine($"Channel: <#{channel.Id}> (#{channel.Name})");
@ -132,4 +139,17 @@ internal partial class ModLogs {
await reportChannel.SendMessageAsync(embed: reportEmbed.Build()); await reportChannel.SendMessageAsync(embed: reportEmbed.Build());
} }
private static EmbedFieldBuilder? CheckAttachments(IEnumerable<string> attachments) {
if (attachments.Any()) {
var field = new EmbedFieldBuilder { Name = "Attachments" };
var attachNames = new StringBuilder();
foreach (var name in attachments) {
attachNames.AppendLine($"`{name}`");
}
field.Value = attachNames.ToString().TrimEnd();
return field;
}
return null;
}
} }