Update DB model: message content may be null
Additionally, removed existing migration data for now. Will re-add when the project is nearly ready for a proper release.
This commit is contained in:
parent
8e05a00136
commit
c77e4bd579
5 changed files with 11 additions and 271 deletions
|
@ -51,7 +51,7 @@ public class CachedGuildMessage {
|
|||
/// <summary>
|
||||
/// Gets this message's content.
|
||||
/// </summary>
|
||||
public string Content { get; set; } = null!;
|
||||
public string? Content { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// If included in the query, references the associated <seealso cref="CachedUser"/> for this entry.
|
||||
|
|
|
@ -1,170 +0,0 @@
|
|||
// <auto-generated />
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using RegexBot.Data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace RegexBot.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(BotDatabaseContext))]
|
||||
[Migration("20220721021550_InitialMigration")]
|
||||
partial class InitialMigration
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.7")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("RegexBot.Data.CachedGuildMessage", b =>
|
||||
{
|
||||
b.Property<long>("MessageId")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("message_id");
|
||||
|
||||
b.Property<List<string>>("AttachmentNames")
|
||||
.IsRequired()
|
||||
.HasColumnType("text[]")
|
||||
.HasColumnName("attachment_names");
|
||||
|
||||
b.Property<long>("AuthorId")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("author_id");
|
||||
|
||||
b.Property<long>("ChannelId")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("channel_id");
|
||||
|
||||
b.Property<string>("Content")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("content");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at")
|
||||
.HasDefaultValueSql("now()");
|
||||
|
||||
b.Property<DateTimeOffset?>("EditedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("edited_at");
|
||||
|
||||
b.Property<long>("GuildId")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("guild_id");
|
||||
|
||||
b.HasKey("MessageId")
|
||||
.HasName("pk_cache_guildmessages");
|
||||
|
||||
b.HasIndex("AuthorId")
|
||||
.HasDatabaseName("ix_cache_guildmessages_author_id");
|
||||
|
||||
b.ToTable("cache_guildmessages", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RegexBot.Data.CachedGuildUser", b =>
|
||||
{
|
||||
b.Property<long>("UserId")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.Property<long>("GuildId")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("guild_id");
|
||||
|
||||
b.Property<DateTimeOffset>("FirstSeenTime")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("first_seen_time")
|
||||
.HasDefaultValueSql("now()");
|
||||
|
||||
b.Property<DateTimeOffset>("GULastUpdateTime")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("gu_last_update_time");
|
||||
|
||||
b.Property<string>("Nickname")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("nickname");
|
||||
|
||||
b.HasKey("UserId", "GuildId")
|
||||
.HasName("pk_cache_usersinguild");
|
||||
|
||||
b.ToTable("cache_usersinguild", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RegexBot.Data.CachedUser", b =>
|
||||
{
|
||||
b.Property<long>("UserId")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.Property<string>("AvatarUrl")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("avatar_url");
|
||||
|
||||
b.Property<string>("Discriminator")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4)
|
||||
.HasColumnType("character(4)")
|
||||
.HasColumnName("discriminator")
|
||||
.IsFixedLength();
|
||||
|
||||
b.Property<DateTimeOffset>("ULastUpdateTime")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("u_last_update_time");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("username");
|
||||
|
||||
b.HasKey("UserId")
|
||||
.HasName("pk_cache_users");
|
||||
|
||||
b.ToTable("cache_users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RegexBot.Data.CachedGuildMessage", b =>
|
||||
{
|
||||
b.HasOne("RegexBot.Data.CachedUser", "Author")
|
||||
.WithMany("GuildMessages")
|
||||
.HasForeignKey("AuthorId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_cache_guildmessages_cache_users_author_id");
|
||||
|
||||
b.Navigation("Author");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RegexBot.Data.CachedGuildUser", b =>
|
||||
{
|
||||
b.HasOne("RegexBot.Data.CachedUser", "User")
|
||||
.WithMany("Guilds")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_cache_usersinguild_cache_users_user_id");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("RegexBot.Data.CachedUser", b =>
|
||||
{
|
||||
b.Navigation("GuildMessages");
|
||||
|
||||
b.Navigation("Guilds");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace RegexBot.Data.Migrations
|
||||
{
|
||||
public partial class InitialMigration : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "cache_users",
|
||||
columns: table => new
|
||||
{
|
||||
user_id = table.Column<long>(type: "bigint", nullable: false),
|
||||
u_last_update_time = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
username = table.Column<string>(type: "text", nullable: false),
|
||||
discriminator = table.Column<string>(type: "character(4)", fixedLength: true, maxLength: 4, nullable: false),
|
||||
avatar_url = table.Column<string>(type: "text", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_cache_users", x => x.user_id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "cache_guildmessages",
|
||||
columns: table => new
|
||||
{
|
||||
message_id = table.Column<long>(type: "bigint", nullable: false),
|
||||
author_id = table.Column<long>(type: "bigint", nullable: false),
|
||||
guild_id = table.Column<long>(type: "bigint", nullable: false),
|
||||
channel_id = table.Column<long>(type: "bigint", nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
||||
edited_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
attachment_names = table.Column<List<string>>(type: "text[]", nullable: false),
|
||||
content = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_cache_guildmessages", x => x.message_id);
|
||||
table.ForeignKey(
|
||||
name: "fk_cache_guildmessages_cache_users_author_id",
|
||||
column: x => x.author_id,
|
||||
principalTable: "cache_users",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "cache_usersinguild",
|
||||
columns: table => new
|
||||
{
|
||||
user_id = table.Column<long>(type: "bigint", nullable: false),
|
||||
guild_id = table.Column<long>(type: "bigint", nullable: false),
|
||||
gu_last_update_time = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
first_seen_time = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
||||
nickname = table.Column<string>(type: "text", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_cache_usersinguild", x => new { x.user_id, x.guild_id });
|
||||
table.ForeignKey(
|
||||
name: "fk_cache_usersinguild_cache_users_user_id",
|
||||
column: x => x.user_id,
|
||||
principalTable: "cache_users",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_cache_guildmessages_author_id",
|
||||
table: "cache_guildmessages",
|
||||
column: "author_id");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "cache_guildmessages");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "cache_usersinguild");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "cache_users");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,7 +43,6 @@ namespace RegexBot.Data.Migrations
|
|||
.HasColumnName("channel_id");
|
||||
|
||||
b.Property<string>("Content")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("content");
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace RegexBot.Modules.ModLogs;
|
|||
internal partial class ModLogs {
|
||||
const string PreviewCutoffNotify = "**Message too long to preview; showing first {0} characters.**\n\n";
|
||||
const string NotCached = "Message not cached.";
|
||||
const string MessageContentNull = "(blank)";
|
||||
|
||||
private async Task HandleDelete(Cacheable<IMessage, ulong> argMsg, Cacheable<IMessageChannel, ulong> argChannel) {
|
||||
const int MaxPreviewLength = 750;
|
||||
|
@ -32,7 +33,9 @@ internal partial class ModLogs {
|
|||
.WithCurrentTimestamp();
|
||||
|
||||
if (cachedMsg != null) {
|
||||
if (cachedMsg.Content.Length > MaxPreviewLength) {
|
||||
if (cachedMsg.Content == null) {
|
||||
reportEmbed.Description = MessageContentNull;
|
||||
} else if (cachedMsg.Content.Length > MaxPreviewLength) {
|
||||
reportEmbed.Description = string.Format(PreviewCutoffNotify, MaxPreviewLength) +
|
||||
cachedMsg.Content[MaxPreviewLength..];
|
||||
} else {
|
||||
|
@ -82,17 +85,17 @@ internal partial class ModLogs {
|
|||
var reportEmbed = new EmbedBuilder()
|
||||
.WithTitle("Message edited")
|
||||
.WithCurrentTimestamp();
|
||||
Console.WriteLine(reportEmbed.Build().ToString());
|
||||
|
||||
reportEmbed.Author = new EmbedAuthorBuilder() {
|
||||
Name = $"{newMsg.Author.Username}#{newMsg.Author.Discriminator}",
|
||||
IconUrl = newMsg.Author.GetAvatarUrl() ?? newMsg.Author.GetDefaultAvatarUrl()
|
||||
};
|
||||
Console.WriteLine(reportEmbed.Build().ToString());
|
||||
|
||||
var oldField = new EmbedFieldBuilder() { Name = "Old" };
|
||||
if (oldMsg != null) {
|
||||
if (oldMsg.Content.Length > MaxPreviewLength) {
|
||||
if (oldMsg.Content == null) {
|
||||
oldField.Value = MessageContentNull;
|
||||
} else if (oldMsg.Content.Length > MaxPreviewLength) {
|
||||
oldField.Value = string.Format(PreviewCutoffNotify, MaxPreviewLength) +
|
||||
oldMsg.Content[MaxPreviewLength..];
|
||||
} else {
|
||||
|
@ -102,18 +105,18 @@ internal partial class ModLogs {
|
|||
oldField.Value = NotCached;
|
||||
}
|
||||
reportEmbed.AddField(oldField);
|
||||
Console.WriteLine(reportEmbed.Build().ToString());
|
||||
|
||||
// TODO shorten 'new' preview, add clickable? check if this would be good usability-wise
|
||||
var newField = new EmbedFieldBuilder() { Name = "New" };
|
||||
if (newMsg.Content.Length > MaxPreviewLength) {
|
||||
if (newMsg.Content == null) {
|
||||
newField.Value = MessageContentNull;
|
||||
} else if (newMsg.Content.Length > MaxPreviewLength) {
|
||||
newField.Value = string.Format(PreviewCutoffNotify, MaxPreviewLength) +
|
||||
newMsg.Content[MaxPreviewLength..];
|
||||
} else {
|
||||
newField.Value = newMsg.Content;
|
||||
}
|
||||
reportEmbed.AddField(newField);
|
||||
Console.WriteLine(reportEmbed.Build().ToString());
|
||||
|
||||
var contextStr = new StringBuilder();
|
||||
contextStr.AppendLine($"User: <@!{newMsg.Author.Id}>");
|
||||
|
@ -126,7 +129,6 @@ internal partial class ModLogs {
|
|||
Value = contextStr.ToString()
|
||||
};
|
||||
reportEmbed.AddField(contextField);
|
||||
Console.WriteLine(reportEmbed.Build().ToString());
|
||||
|
||||
await reportChannel.SendMessageAsync(embed: reportEmbed.Build());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue