RegexBot/Data/CachedGuildMessage.cs
2022-12-03 17:46:26 -08:00

76 lines
2.5 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace RegexBot.Data;
/// <summary>
/// Represents an item in the guild message cache.
/// </summary>
[Table("cache_guildmessages")]
public class CachedGuildMessage {
/// <summary>
/// Gets the message's snowflake ID.
/// </summary>
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public ulong MessageId { get; set; }
/// <summary>
/// Gets the message author's snowflake ID.
/// </summary>
public ulong AuthorId { get; set; }
/// <summary>
/// Gets the associated guild's snowflake ID.
/// </summary>
public ulong GuildId { get; set; }
/// <summary>
/// Gets the corresponding channel's snowflake ID.
/// </summary>
public ulong ChannelId { get; set; }
/// <summary>
/// Gets the timestamp showing when this message was originally created.
/// </summary>
/// <remarks>
/// Though it's possible to draw this from <see cref="MessageId"/>, it is stored in the database
/// as a separate field for any possible necessary use via database queries.
/// </remarks>
public DateTimeOffset CreatedAt { get; set; }
/// <summary>
/// Gets the timestamp, if any, showing when this message was last edited.
/// </summary>
public DateTimeOffset? EditedAt { get; set; }
/// <summary>
/// Gets a list of file names that were attached to this message.
/// </summary>
public List<string> AttachmentNames { get; set; } = null!;
/// <summary>
/// Gets this message's content.
/// </summary>
public string? Content { get; set; } = null!;
/// <inheritdoc cref="CachedGuildUser.User" />
[ForeignKey(nameof(AuthorId))]
[InverseProperty(nameof(CachedUser.GuildMessages))]
public CachedUser Author { get; set; } = null!;
// TODO set up composite foreign key. will require rewriting some parts in modules...
// Used by MessageCachingSubservice
internal static CachedGuildMessage? Clone(CachedGuildMessage? original) {
if (original == null) return null;
return new() {
MessageId = original.MessageId,
AuthorId = original.AuthorId,
GuildId = original.GuildId,
ChannelId = original.ChannelId,
CreatedAt = original.CreatedAt,
EditedAt = original.EditedAt,
AttachmentNames = new(original.AttachmentNames),
Content = original.Content
};
}
}