diff --git a/Data/CachedGuildMessage.cs b/Data/CachedGuildMessage.cs
index 6867bf9..fa24c37 100644
--- a/Data/CachedGuildMessage.cs
+++ b/Data/CachedGuildMessage.cs
@@ -51,7 +51,7 @@ public class CachedGuildMessage {
///
/// Gets this message's content.
///
- public string Content { get; set; } = null!;
+ public string? Content { get; set; } = null!;
///
/// If included in the query, references the associated for this entry.
diff --git a/Data/Migrations/20220721021550_InitialMigration.Designer.cs b/Data/Migrations/20220721021550_InitialMigration.Designer.cs
deleted file mode 100644
index c9966f1..0000000
--- a/Data/Migrations/20220721021550_InitialMigration.Designer.cs
+++ /dev/null
@@ -1,170 +0,0 @@
-//
-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("MessageId")
- .HasColumnType("bigint")
- .HasColumnName("message_id");
-
- b.Property>("AttachmentNames")
- .IsRequired()
- .HasColumnType("text[]")
- .HasColumnName("attachment_names");
-
- b.Property("AuthorId")
- .HasColumnType("bigint")
- .HasColumnName("author_id");
-
- b.Property("ChannelId")
- .HasColumnType("bigint")
- .HasColumnName("channel_id");
-
- b.Property("Content")
- .IsRequired()
- .HasColumnType("text")
- .HasColumnName("content");
-
- b.Property("CreatedAt")
- .ValueGeneratedOnAdd()
- .HasColumnType("timestamp with time zone")
- .HasColumnName("created_at")
- .HasDefaultValueSql("now()");
-
- b.Property("EditedAt")
- .HasColumnType("timestamp with time zone")
- .HasColumnName("edited_at");
-
- b.Property("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("UserId")
- .HasColumnType("bigint")
- .HasColumnName("user_id");
-
- b.Property("GuildId")
- .HasColumnType("bigint")
- .HasColumnName("guild_id");
-
- b.Property("FirstSeenTime")
- .ValueGeneratedOnAdd()
- .HasColumnType("timestamp with time zone")
- .HasColumnName("first_seen_time")
- .HasDefaultValueSql("now()");
-
- b.Property("GULastUpdateTime")
- .HasColumnType("timestamp with time zone")
- .HasColumnName("gu_last_update_time");
-
- b.Property("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("UserId")
- .HasColumnType("bigint")
- .HasColumnName("user_id");
-
- b.Property("AvatarUrl")
- .HasColumnType("text")
- .HasColumnName("avatar_url");
-
- b.Property("Discriminator")
- .IsRequired()
- .HasMaxLength(4)
- .HasColumnType("character(4)")
- .HasColumnName("discriminator")
- .IsFixedLength();
-
- b.Property("ULastUpdateTime")
- .HasColumnType("timestamp with time zone")
- .HasColumnName("u_last_update_time");
-
- b.Property("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
- }
- }
-}
diff --git a/Data/Migrations/20220721021550_InitialMigration.cs b/Data/Migrations/20220721021550_InitialMigration.cs
deleted file mode 100644
index ccbfbc4..0000000
--- a/Data/Migrations/20220721021550_InitialMigration.cs
+++ /dev/null
@@ -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(type: "bigint", nullable: false),
- u_last_update_time = table.Column(type: "timestamp with time zone", nullable: false),
- username = table.Column(type: "text", nullable: false),
- discriminator = table.Column(type: "character(4)", fixedLength: true, maxLength: 4, nullable: false),
- avatar_url = table.Column(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(type: "bigint", nullable: false),
- author_id = table.Column(type: "bigint", nullable: false),
- guild_id = table.Column(type: "bigint", nullable: false),
- channel_id = table.Column(type: "bigint", nullable: false),
- created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
- edited_at = table.Column(type: "timestamp with time zone", nullable: true),
- attachment_names = table.Column>(type: "text[]", nullable: false),
- content = table.Column(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(type: "bigint", nullable: false),
- guild_id = table.Column(type: "bigint", nullable: false),
- gu_last_update_time = table.Column(type: "timestamp with time zone", nullable: false),
- first_seen_time = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
- nickname = table.Column(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");
- }
- }
-}
diff --git a/Data/Migrations/BotDatabaseContextModelSnapshot.cs b/Data/Migrations/BotDatabaseContextModelSnapshot.cs
index 75e34f5..038cc06 100644
--- a/Data/Migrations/BotDatabaseContextModelSnapshot.cs
+++ b/Data/Migrations/BotDatabaseContextModelSnapshot.cs
@@ -43,7 +43,6 @@ namespace RegexBot.Data.Migrations
.HasColumnName("channel_id");
b.Property("Content")
- .IsRequired()
.HasColumnType("text")
.HasColumnName("content");
diff --git a/Modules/ModLogs/ModLogs_Messages.cs b/Modules/ModLogs/ModLogs_Messages.cs
index 7330866..4c097ca 100644
--- a/Modules/ModLogs/ModLogs_Messages.cs
+++ b/Modules/ModLogs/ModLogs_Messages.cs
@@ -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 argMsg, Cacheable 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());
}