feat: store message metadata
This commit is contained in:
parent
4db09346e2
commit
5585ffd6ea
2 changed files with 27 additions and 5 deletions
|
|
@ -96,6 +96,14 @@ public class MessageDeleteResponder(
|
||||||
builder.AddField("Member ID", msg.Member, true);
|
builder.AddField("Member ID", msg.Member, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (msg.Metadata != null)
|
||||||
|
{
|
||||||
|
var attachmentInfo = string.Join("\n",
|
||||||
|
msg.Metadata.Attachments.Select(a =>
|
||||||
|
$"{a.Filename} ({a.ContentType}, {a.Size.Bytes().Humanize()})"));
|
||||||
|
if (!string.IsNullOrWhiteSpace(attachmentInfo)) builder.AddField("Attachments", attachmentInfo, false);
|
||||||
|
}
|
||||||
|
|
||||||
await webhookExecutor.QueueLogAsync(logChannel.Value, builder.Build().GetOrThrow());
|
await webhookExecutor.QueueLogAsync(logChannel.Value, builder.Build().GetOrThrow());
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using Catalogger.Backend.Database.Models;
|
using System.Text.Json;
|
||||||
using Catalogger.Backend.Extensions;
|
using Catalogger.Backend.Extensions;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Remora.Discord.API.Abstractions.Gateway.Events;
|
using Remora.Discord.API.Abstractions.Gateway.Events;
|
||||||
|
|
@ -14,6 +14,9 @@ public class MessageRepository(ILogger logger, DatabaseContext db, IEncryptionSe
|
||||||
{
|
{
|
||||||
_logger.Debug("Saving message {MessageId}", msg.ID);
|
_logger.Debug("Saving message {MessageId}", msg.ID);
|
||||||
|
|
||||||
|
var metadata = new Metadata(IsWebhook: msg.WebhookID.HasValue,
|
||||||
|
msg.Attachments.Select(a => new Attachment(a.Filename, a.Size, a.ContentType.Value)));
|
||||||
|
|
||||||
var dbMessage = new DbMessage
|
var dbMessage = new DbMessage
|
||||||
{
|
{
|
||||||
Id = msg.ID.ToUlong(),
|
Id = msg.ID.ToUlong(),
|
||||||
|
|
@ -25,6 +28,7 @@ public class MessageRepository(ILogger logger, DatabaseContext db, IEncryptionSe
|
||||||
await Task.Run(
|
await Task.Run(
|
||||||
() => encryptionService.Encrypt(string.IsNullOrWhiteSpace(msg.Content) ? "None" : msg.Content), ct),
|
() => encryptionService.Encrypt(string.IsNullOrWhiteSpace(msg.Content) ? "None" : msg.Content), ct),
|
||||||
EncryptedUsername = await Task.Run(() => encryptionService.Encrypt(msg.Author.Tag()), ct),
|
EncryptedUsername = await Task.Run(() => encryptionService.Encrypt(msg.Author.Tag()), ct),
|
||||||
|
EncryptedMetadata = await Task.Run(() => encryptionService.Encrypt(JsonSerializer.Serialize(metadata)), ct),
|
||||||
AttachmentSize = msg.Attachments.Select(a => a.Size).Sum()
|
AttachmentSize = msg.Attachments.Select(a => a.Size).Sum()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -40,8 +44,14 @@ public class MessageRepository(ILogger logger, DatabaseContext db, IEncryptionSe
|
||||||
if (dbMsg == null) return null;
|
if (dbMsg == null) return null;
|
||||||
|
|
||||||
return new Message(dbMsg.Id, dbMsg.OriginalId, dbMsg.UserId, dbMsg.ChannelId, dbMsg.GuildId, dbMsg.Member,
|
return new Message(dbMsg.Id, dbMsg.OriginalId, dbMsg.UserId, dbMsg.ChannelId, dbMsg.GuildId, dbMsg.Member,
|
||||||
dbMsg.System, await Task.Run(() => encryptionService.Decrypt(dbMsg.EncryptedUsername), ct),
|
dbMsg.System,
|
||||||
await Task.Run(() => encryptionService.Decrypt(dbMsg.EncryptedContent), ct), null, dbMsg.AttachmentSize);
|
Username: await Task.Run(() => encryptionService.Decrypt(dbMsg.EncryptedUsername), ct),
|
||||||
|
Content: await Task.Run(() => encryptionService.Decrypt(dbMsg.EncryptedContent), ct),
|
||||||
|
Metadata: dbMsg.EncryptedMetadata != null
|
||||||
|
? JsonSerializer.Deserialize<Metadata>(
|
||||||
|
await Task.Run(() => encryptionService.Decrypt(dbMsg.EncryptedMetadata), ct))
|
||||||
|
: null,
|
||||||
|
dbMsg.AttachmentSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -95,7 +105,11 @@ public class MessageRepository(ILogger logger, DatabaseContext db, IEncryptionSe
|
||||||
string? System,
|
string? System,
|
||||||
string Username,
|
string Username,
|
||||||
string Content,
|
string Content,
|
||||||
string? Metadata,
|
Metadata? Metadata,
|
||||||
int AttachmentSize
|
int AttachmentSize
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public record Metadata(bool IsWebhook, IEnumerable<Attachment> Attachments);
|
||||||
|
|
||||||
|
public record Attachment(string Filename, int Size, string ContentType);
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue