From 97b60f8679e85927fc411c0f3a470dee767a2800 Mon Sep 17 00:00:00 2001 From: Plerx <50530305+Plerx2493@users.noreply.github.com> Date: Sat, 22 Jun 2024 09:31:54 +0200 Subject: [PATCH] Fix db issues and fix bugs in translate commands --- .../TargetLanguageAutoCompletion.cs | 5 +- .../Commands/ContextMenu/TranslateMessage.cs | 8 +- .../Commands/Slash/Jumpad.cs | 7 +- .../Commands/Slash/Quotes.cs | 3 +- .../Commands/Slash/StarboardConfig.cs | 2 +- .../Commands/Slash/Translation.cs | 8 + .../CommandsChecks/EnsureDBEntitiesCheck.cs | 8 +- .../CustomComponents/ActionDiscordButton.cs | 4 +- .../Entities/GuildConfigDbEntity.cs | 6 +- .../Entities/GuildDbEntity.cs | 21 +- .../Entities/QuoteDbEntity.cs | 2 +- .../Entities/UserDbEntity.cs | 2 +- .../EventListener.ActionButtons.cs | 2 +- .../EventListener.GuildDownload.cs | 13 +- ...052300_Remove double guild ids.Designer.cs | 408 ++++++++++++++++++ .../20240622052300_Remove double guild ids.cs | 248 +++++++++++ ...d user key as not db generated.Designer.cs | 402 +++++++++++++++++ ... guild and user key as not db generated.cs | 55 +++ .../Migrations/MadsContextModelSnapshot.cs | 42 +- .../ModularAssistentForDiscordServer.csproj | 38 +- .../ModularDiscordBot.cs | 7 +- .../Services/LoggingService.cs | 15 +- .../Services/QuotesService.cs | 6 +- .../Services/StarboardService.cs | 2 +- .../Services/TranslateInformationService.cs | 4 +- 25 files changed, 1210 insertions(+), 108 deletions(-) create mode 100644 ModularAssistentForDiscordServer/Migrations/20240622052300_Remove double guild ids.Designer.cs create mode 100644 ModularAssistentForDiscordServer/Migrations/20240622052300_Remove double guild ids.cs create mode 100644 ModularAssistentForDiscordServer/Migrations/20240622055159_mark guild and user key as not db generated.Designer.cs create mode 100644 ModularAssistentForDiscordServer/Migrations/20240622055159_mark guild and user key as not db generated.cs diff --git a/ModularAssistentForDiscordServer/Commands/AutoCompletion/TargetLanguageAutoCompletion.cs b/ModularAssistentForDiscordServer/Commands/AutoCompletion/TargetLanguageAutoCompletion.cs index 6cc4d48..fcd7900 100644 --- a/ModularAssistentForDiscordServer/Commands/AutoCompletion/TargetLanguageAutoCompletion.cs +++ b/ModularAssistentForDiscordServer/Commands/AutoCompletion/TargetLanguageAutoCompletion.cs @@ -32,10 +32,9 @@ public async ValueTask> AutoCompleteAsync(Au { TargetLanguage[] sourceLangs = await _service.GetTargetLanguagesAsync(); Dictionary choices = sourceLangs - .Where(x => x.ToString().StartsWith(context.UserInput.ToString() ?? "")) + .Where(x => x.ToString().ToLowerInvariant().StartsWith(context.UserInput.ToLowerInvariant())) .Take(25) - .Select(x => x.ToString()) - .ToDictionary(x => x, x => (object)x); + .ToDictionary(x => x.ToString(), x => (object)x.Code); return choices; } diff --git a/ModularAssistentForDiscordServer/Commands/ContextMenu/TranslateMessage.cs b/ModularAssistentForDiscordServer/Commands/ContextMenu/TranslateMessage.cs index d4a3303..aaedc94 100644 --- a/ModularAssistentForDiscordServer/Commands/ContextMenu/TranslateMessage.cs +++ b/ModularAssistentForDiscordServer/Commands/ContextMenu/TranslateMessage.cs @@ -40,7 +40,7 @@ public async Task TranslateAsync(SlashCommandContext ctx, DiscordMessage target { await ctx.DeferAsync(true); - string? preferredLanguage = await _translateInformationService.GetPreferredLanguage(ctx.User.Id); + string? preferredLanguage = await _translateInformationService.GetPreferredLanguageAsync(ctx.User.Id); bool isPreferredLanguageSet = !preferredLanguage.IsNullOrWhiteSpace(); if(!isPreferredLanguageSet) @@ -78,8 +78,10 @@ public async Task TranslateAsync(SlashCommandContext ctx, DiscordMessage target DiscordFollowupMessageBuilder followUpMessage = new DiscordFollowupMessageBuilder() .WithContent("⚠️ You haven't set a preferred language yet. Default is english.") - .AddComponents(new DiscordButtonComponent(DiscordButtonStyle.Primary, "setLanguage", "Set language").AsActionButton(ActionDiscordButtonEnum.SetTranslationLanguage)) - .AddComponents(new DiscordButtonComponent(DiscordButtonStyle.Primary, "setLanguage", "Set your language to en-US").AsActionButton(ActionDiscordButtonEnum.SetTranslationLanguage, "en-US")) + .AddComponents(new DiscordButtonComponent(DiscordButtonStyle.Primary, "setLanguage", "Set language") + .AsActionButton(ActionDiscordButtonEnum.SetTranslationLanguage)) + .AddComponents(new DiscordButtonComponent(DiscordButtonStyle.Primary, "setLanguage", "Set your language to en-US") + .AsActionButton(ActionDiscordButtonEnum.SetTranslationLanguage, "en-US")) .AsEphemeral(); diff --git a/ModularAssistentForDiscordServer/Commands/Slash/Jumpad.cs b/ModularAssistentForDiscordServer/Commands/Slash/Jumpad.cs index 89cc278..0bfa516 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/Jumpad.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/Jumpad.cs @@ -26,7 +26,7 @@ public sealed class Jumppad { [Command("jumppad"), Description("Create a jumppad button"), RequireGuild, RequirePermissions(DiscordPermissions.MoveMembers)] - public async Task Test + public async Task CreateJumppad ( CommandContext ctx, [Description("Channel where the users will be moved out"), @@ -38,6 +38,11 @@ public async Task Test [Description("Message to be sent")] string? content = null ) { + if (originChannel == targetChannel) + { + await ctx.RespondAsync(new DiscordInteractionResponseBuilder().WithContent("Can't create a jumppad from a channel to itself").AsEphemeral()); + } + DiscordInteractionResponseBuilder message = new(); DiscordButtonComponent newButton = new(DiscordButtonStyle.Success, "Placeholder", "Jump"); newButton = newButton.AsActionButton( diff --git a/ModularAssistentForDiscordServer/Commands/Slash/Quotes.cs b/ModularAssistentForDiscordServer/Commands/Slash/Quotes.cs index 5f3fb42..ca18f1a 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/Quotes.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/Quotes.cs @@ -42,12 +42,11 @@ public async Task AddQuoteUser { await ctx.DeferAsync(true); - QuoteDbEntity newQuote = new() { Content = content, CreatedAt = DateTime.Now, - DiscordGuildId = ctx.Guild!.Id, + GuildId = ctx.Guild!.Id, QuotedUserId = user.Id, UserId = ctx.User.Id }; diff --git a/ModularAssistentForDiscordServer/Commands/Slash/StarboardConfig.cs b/ModularAssistentForDiscordServer/Commands/Slash/StarboardConfig.cs index 38baf31..eba366e 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/StarboardConfig.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/StarboardConfig.cs @@ -53,7 +53,7 @@ public async Task StarboardConfigCommand MadsContext db = await _contextFactory.CreateDbContextAsync(); - GuildConfigDbEntity guildConfig = db.Configs.First(x => x.DiscordGuildId == ctx.Guild.Id); + GuildConfigDbEntity guildConfig = db.Configs.First(x => x.GuildId == ctx.Guild.Id); if (!DiscordEmoji.TryFromUnicode(emojiString, out DiscordEmoji emoji)) { diff --git a/ModularAssistentForDiscordServer/Commands/Slash/Translation.cs b/ModularAssistentForDiscordServer/Commands/Slash/Translation.cs index 4b766cd..2211d5d 100644 --- a/ModularAssistentForDiscordServer/Commands/Slash/Translation.cs +++ b/ModularAssistentForDiscordServer/Commands/Slash/Translation.cs @@ -36,6 +36,14 @@ public Translation(TranslateInformationService translationUserInfo, Translator t _translator = translator; } + [Command("info"), Description("Get your preferred language")] + public async Task InfoAsync(CommandContext ctx) + { + string? lang = await _translationUserInfo.GetPreferredLanguageAsync(ctx.User.Id); + + await ctx.CreateResponse_Success($"Language set to `{lang ?? "null"}`"); + } + [Command("setLanguage"), Description("Set your preferred language")] public async Task SetLanguageAsync ( diff --git a/ModularAssistentForDiscordServer/CommandsChecks/EnsureDBEntitiesCheck.cs b/ModularAssistentForDiscordServer/CommandsChecks/EnsureDBEntitiesCheck.cs index a36a84d..3cd7250 100644 --- a/ModularAssistentForDiscordServer/CommandsChecks/EnsureDBEntitiesCheck.cs +++ b/ModularAssistentForDiscordServer/CommandsChecks/EnsureDBEntitiesCheck.cs @@ -52,16 +52,14 @@ await dbContext.Users.Upsert(userdbEntity) return null; } - GuildDbEntity guildDbEntity = new() - { - DiscordId = context.Guild.Id - }; + GuildDbEntity guildDbEntity = new(context.Guild.Id); await dbContext.Guilds.Upsert(guildDbEntity) - .On(x => x.DiscordId) + .On(x => x.Id) .NoUpdate() .RunAsync(); + await dbContext.SaveChangesAsync(); return null; } } \ No newline at end of file diff --git a/ModularAssistentForDiscordServer/CustomComponents/ActionDiscordButton.cs b/ModularAssistentForDiscordServer/CustomComponents/ActionDiscordButton.cs index 829c39c..429b95f 100644 --- a/ModularAssistentForDiscordServer/CustomComponents/ActionDiscordButton.cs +++ b/ModularAssistentForDiscordServer/CustomComponents/ActionDiscordButton.cs @@ -156,16 +156,15 @@ params object[] args break; case ActionDiscordButtonEnum.SetTranslationLanguage: + actionCode = (int) ActionDiscordButtonEnum.SetTranslationLanguage; if (args.Length == 0) { - actionCode = (int) ActionDiscordButtonEnum.AnswerDmChannel; customId += actionCode; break; } if (args is [string lang]) { - actionCode = (int) ActionDiscordButtonEnum.AnswerDmChannel; customId += actionCode + ":" + lang ; break; } @@ -173,7 +172,6 @@ params object[] args throw new ArgumentException("Please provide 1 lang identifier (string)"); break; - default: throw new ArgumentOutOfRangeException(nameof(action), action, null); } diff --git a/ModularAssistentForDiscordServer/Entities/GuildConfigDbEntity.cs b/ModularAssistentForDiscordServer/Entities/GuildConfigDbEntity.cs index 4fdb7c3..436b31f 100644 --- a/ModularAssistentForDiscordServer/Entities/GuildConfigDbEntity.cs +++ b/ModularAssistentForDiscordServer/Entities/GuildConfigDbEntity.cs @@ -26,9 +26,9 @@ public class GuildConfigDbEntity /// Snowflake id of the guild the config is related to /// [Required, Column("discordId")] - public ulong DiscordGuildId { get; set; } + public ulong GuildId { get; set; } - [Column("prefix")] + [Column("prefix"), MaxLength(5)] public string Prefix { get; set; } [Column("starboardEnabled")] @@ -43,7 +43,7 @@ public class GuildConfigDbEntity [Column("starboardEmojiId")] public ulong? StarboardEmojiId { get; set; } - [Column("starboardEmojiName")] + [Column("starboardEmojiName"), MaxLength(50)] public string? StarboardEmojiName { get; set; } public GuildDbEntity Guild; diff --git a/ModularAssistentForDiscordServer/Entities/GuildDbEntity.cs b/ModularAssistentForDiscordServer/Entities/GuildDbEntity.cs index d5ccb92..ab42078 100644 --- a/ModularAssistentForDiscordServer/Entities/GuildDbEntity.cs +++ b/ModularAssistentForDiscordServer/Entities/GuildDbEntity.cs @@ -22,28 +22,17 @@ namespace MADS.Entities; public class GuildDbEntity { - public GuildDbEntity() + public GuildDbEntity(ulong id) { - Id = 0; + Id = id; Incidents = new List(); Settings = new GuildConfigDbEntity(); Quotes = new List(); } - public GuildDbEntity(GuildDbEntity old) - { - Id = old.Id; - Incidents = old.Incidents; - Settings = old.Settings; - Quotes = old.Quotes; - } - - [Key, Column("id"), DefaultValue(0), DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Key, Column("id"), DatabaseGenerated(DatabaseGeneratedOption.None)] public ulong Id { get; init; } - [Required, Column("discordId")] - public ulong DiscordId { get; set; } - public GuildConfigDbEntity Settings { get; set; } public List Incidents { get; set; } @@ -61,7 +50,7 @@ public void Configure(EntityTypeBuilder builder) builder.HasOne(x => x.Settings) .WithOne(x => x.Guild) - .HasForeignKey(x => x.DiscordGuildId) + .HasForeignKey(x => x.GuildId) .OnDelete(DeleteBehavior.Cascade); builder.HasMany(x => x.Incidents) @@ -71,7 +60,7 @@ public void Configure(EntityTypeBuilder builder) builder.HasMany(x => x.Quotes) .WithOne(x => x.Guild) - .HasForeignKey(x => x.DiscordGuildId) + .HasForeignKey(x => x.GuildId) .OnDelete(DeleteBehavior.Cascade); } } \ No newline at end of file diff --git a/ModularAssistentForDiscordServer/Entities/QuoteDbEntity.cs b/ModularAssistentForDiscordServer/Entities/QuoteDbEntity.cs index b0da8d4..995d483 100644 --- a/ModularAssistentForDiscordServer/Entities/QuoteDbEntity.cs +++ b/ModularAssistentForDiscordServer/Entities/QuoteDbEntity.cs @@ -23,7 +23,7 @@ public class QuoteDbEntity public ulong Id { get; set; } [Column("discordGuildId")] - public ulong DiscordGuildId { get; set; } + public ulong GuildId { get; set; } /// /// User which was quoted diff --git a/ModularAssistentForDiscordServer/Entities/UserDbEntity.cs b/ModularAssistentForDiscordServer/Entities/UserDbEntity.cs index c00b4c5..f6330fc 100644 --- a/ModularAssistentForDiscordServer/Entities/UserDbEntity.cs +++ b/ModularAssistentForDiscordServer/Entities/UserDbEntity.cs @@ -21,7 +21,7 @@ namespace MADS.Entities; public class UserDbEntity { - [Key, Column("id")] + [Key, Column("id"), DatabaseGenerated(DatabaseGeneratedOption.None)] public ulong Id { get; set; } [Column("username")] diff --git a/ModularAssistentForDiscordServer/EventListeners/EventListener.ActionButtons.cs b/ModularAssistentForDiscordServer/EventListeners/EventListener.ActionButtons.cs index 7d95463..c3a9e07 100644 --- a/ModularAssistentForDiscordServer/EventListeners/EventListener.ActionButtons.cs +++ b/ModularAssistentForDiscordServer/EventListeners/EventListener.ActionButtons.cs @@ -115,7 +115,7 @@ private static async Task SetTranslationLanguage(ComponentInteractionCreatedEven InteractivityExtension interactive = sender.GetInteractivity(); InteractivityResult result = - await interactive.WaitForModalAsync($"setLanguage-{args.User.Id}"); + await interactive.WaitForModalAsync($"setLanguage-{args.User.Id}", TimeSpan.FromMinutes(5)); if (result.TimedOut) { diff --git a/ModularAssistentForDiscordServer/EventListeners/EventListener.GuildDownload.cs b/ModularAssistentForDiscordServer/EventListeners/EventListener.GuildDownload.cs index 66d0e22..bc71b0e 100644 --- a/ModularAssistentForDiscordServer/EventListeners/EventListener.GuildDownload.cs +++ b/ModularAssistentForDiscordServer/EventListeners/EventListener.GuildDownload.cs @@ -27,10 +27,8 @@ internal static partial class EventListener public static async Task UpdateDb(DiscordClient client, GuildDownloadCompletedEventArgs args) { IDbContextFactory dbFactory = ModularDiscordBot.Services.GetRequiredService>(); - Task updateGuilds = UpdateGuilds(args, dbFactory); - Task updateUsers = UpdateUsersDb(args, dbFactory); - - await Task.WhenAll(updateGuilds, updateUsers); + await UpdateGuilds(args, dbFactory); + await UpdateUsersDb(args, dbFactory); client.Logger.LogInformation("Database updated!"); } @@ -88,16 +86,15 @@ IDbContextFactory dbFactory { await using MadsContext db = await dbFactory.CreateDbContextAsync(); - List dbGuildIds = db.Guilds.Select(x => x.DiscordId).ToList(); + List dbGuildIds = db.Guilds.Select(x => x.Id).ToList(); GuildDbEntity[] newGuildEntities = args.Guilds .Where(x => !dbGuildIds.Contains(x.Key)) - .Select(x => new GuildDbEntity + .Select(x => new GuildDbEntity(x.Value.Id) { - DiscordId = x.Value.Id, Settings = new GuildConfigDbEntity { - DiscordGuildId = x.Value.Id, + GuildId = x.Value.Id, Prefix = "", StarboardActive = false } diff --git a/ModularAssistentForDiscordServer/Migrations/20240622052300_Remove double guild ids.Designer.cs b/ModularAssistentForDiscordServer/Migrations/20240622052300_Remove double guild ids.Designer.cs new file mode 100644 index 0000000..47f1ea5 --- /dev/null +++ b/ModularAssistentForDiscordServer/Migrations/20240622052300_Remove double guild ids.Designer.cs @@ -0,0 +1,408 @@ +// +using System; +using MADS.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace MADS.Migrations +{ + [DbContext(typeof(MadsContext))] + [Migration("20240622052300_Remove double guild ids")] + partial class Removedoubleguildids + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); + + modelBuilder.Entity("MADS.Entities.GuildConfigDbEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("GuildId") + .HasColumnType("bigint unsigned") + .HasColumnName("discordId"); + + b.Property("Prefix") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("varchar(5)") + .HasColumnName("prefix"); + + b.Property("StarboardActive") + .HasColumnType("tinyint(1)") + .HasColumnName("starboardEnabled"); + + b.Property("StarboardChannelId") + .HasColumnType("bigint unsigned") + .HasColumnName("starboardChannel"); + + b.Property("StarboardEmojiId") + .HasColumnType("bigint unsigned") + .HasColumnName("starboardEmojiId"); + + b.Property("StarboardEmojiName") + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasColumnName("starboardEmojiName"); + + b.Property("StarboardThreshold") + .HasColumnType("int") + .HasColumnName("starboardThreshold"); + + b.HasKey("Id"); + + b.HasIndex("GuildId") + .IsUnique(); + + b.ToTable("Configs"); + }); + + modelBuilder.Entity("MADS.Entities.GuildDbEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.HasKey("Id"); + + b.ToTable("guilds", (string)null); + }); + + modelBuilder.Entity("MADS.Entities.IncidentDbEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("CreationTimeStamp") + .HasColumnType("datetime(6)"); + + b.Property("GuildId") + .HasColumnType("bigint unsigned") + .HasColumnName("guild_id"); + + b.Property("ModeratorId") + .HasColumnType("bigint unsigned") + .HasColumnName("moderator_id"); + + b.Property("Reason") + .IsRequired() + .HasColumnType("longtext") + .HasColumnName("reason"); + + b.Property("TargetId") + .HasColumnType("bigint unsigned") + .HasColumnName("target_id"); + + b.HasKey("Id"); + + b.HasIndex("GuildId"); + + b.HasIndex("TargetId"); + + b.ToTable("Incidents"); + }); + + modelBuilder.Entity("MADS.Entities.QuoteDbEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("varchar(1000)") + .HasColumnName("content"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnName("timestamp"); + + b.Property("GuildId") + .HasColumnType("bigint unsigned") + .HasColumnName("discordGuildId"); + + b.Property("QuotedUserId") + .HasColumnType("bigint unsigned") + .HasColumnName("quotedUserId"); + + b.Property("UserId") + .HasColumnType("bigint unsigned") + .HasColumnName("UserId"); + + b.HasKey("Id"); + + b.HasIndex("GuildId"); + + b.ToTable("Quotes"); + }); + + modelBuilder.Entity("MADS.Entities.ReminderDbEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("ChannelId") + .HasColumnType("bigint unsigned") + .HasColumnName("channelId"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("creationTime"); + + b.Property("ExecutionTime") + .HasColumnType("datetime(6)") + .HasColumnName("executionTime"); + + b.Property("IsPrivate") + .HasColumnType("tinyint(1)") + .HasColumnName("isPrivate"); + + b.Property("MentionedChannel") + .HasColumnType("bigint unsigned") + .HasColumnName("mentionedChannel"); + + b.Property("MentionedMessage") + .HasColumnType("bigint unsigned") + .HasColumnName("MentionedMessage"); + + b.Property("MessageId") + .HasColumnType("bigint unsigned") + .HasColumnName("messageId"); + + b.Property("ReminderText") + .IsRequired() + .HasColumnType("longtext") + .HasColumnName("reminderText"); + + b.Property("UserId") + .HasColumnType("bigint unsigned") + .HasColumnName("userId"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Reminders"); + }); + + modelBuilder.Entity("MADS.Entities.StarboardMessageDbEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("DiscordChannelId") + .HasColumnType("bigint unsigned") + .HasColumnName("discordChannelId"); + + b.Property("DiscordGuildId") + .HasColumnType("bigint unsigned") + .HasColumnName("discordGuildId"); + + b.Property("DiscordMessageId") + .HasColumnType("bigint unsigned") + .HasColumnName("discordMessageId"); + + b.Property("StarboardChannelId") + .HasColumnType("bigint unsigned") + .HasColumnName("starboardChannelId"); + + b.Property("StarboardGuildId") + .HasColumnType("bigint unsigned") + .HasColumnName("starboardGuildId"); + + b.Property("StarboardMessageId") + .HasColumnType("bigint unsigned") + .HasColumnName("starboardMessageId"); + + b.Property("Stars") + .HasColumnType("int") + .HasColumnName("starCount"); + + b.HasKey("Id"); + + b.ToTable("Starboard"); + }); + + modelBuilder.Entity("MADS.Entities.UserDbEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("PreferedLanguage") + .HasColumnType("longtext") + .HasColumnName("prefered_language"); + + b.Property("Username") + .IsRequired() + .HasColumnType("longtext") + .HasColumnName("username"); + + b.HasKey("Id"); + + b.ToTable("users", (string)null); + }); + + modelBuilder.Entity("MADS.Entities.VoiceAlert", b => + { + b.Property("AlertId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("AlertId")); + + b.Property("ChannelId") + .HasColumnType("bigint unsigned") + .HasColumnName("channel_id"); + + b.Property("GuildId") + .HasColumnType("bigint unsigned") + .HasColumnName("guild_id"); + + b.Property("IsRepeatable") + .HasColumnType("tinyint(1)") + .HasColumnName("is_repeatable"); + + b.Property("LastAlert") + .HasColumnType("datetime(6)") + .HasColumnName("last_alert"); + + b.Property("MinTimeBetweenAlerts") + .HasColumnType("time(6)") + .HasColumnName("time_between"); + + b.Property("UserId") + .HasColumnType("bigint unsigned") + .HasColumnName("user_id"); + + b.HasKey("AlertId"); + + b.HasIndex("UserId"); + + b.ToTable("VoiceAlerts"); + }); + + modelBuilder.Entity("MADS.Entities.GuildConfigDbEntity", b => + { + b.HasOne("MADS.Entities.GuildDbEntity", "Guild") + .WithOne("Settings") + .HasForeignKey("MADS.Entities.GuildConfigDbEntity", "GuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Guild"); + }); + + modelBuilder.Entity("MADS.Entities.IncidentDbEntity", b => + { + b.HasOne("MADS.Entities.GuildDbEntity", "Guild") + .WithMany("Incidents") + .HasForeignKey("GuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("MADS.Entities.UserDbEntity", "TargetUser") + .WithMany("Incidents") + .HasForeignKey("TargetId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Guild"); + + b.Navigation("TargetUser"); + }); + + modelBuilder.Entity("MADS.Entities.QuoteDbEntity", b => + { + b.HasOne("MADS.Entities.GuildDbEntity", "Guild") + .WithMany("Quotes") + .HasForeignKey("GuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Guild"); + }); + + modelBuilder.Entity("MADS.Entities.ReminderDbEntity", b => + { + b.HasOne("MADS.Entities.UserDbEntity", "User") + .WithMany("Reminders") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("MADS.Entities.VoiceAlert", b => + { + b.HasOne("MADS.Entities.UserDbEntity", "User") + .WithMany("VoiceAlerts") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("MADS.Entities.GuildDbEntity", b => + { + b.Navigation("Incidents"); + + b.Navigation("Quotes"); + + b.Navigation("Settings") + .IsRequired(); + }); + + modelBuilder.Entity("MADS.Entities.UserDbEntity", b => + { + b.Navigation("Incidents"); + + b.Navigation("Reminders"); + + b.Navigation("VoiceAlerts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ModularAssistentForDiscordServer/Migrations/20240622052300_Remove double guild ids.cs b/ModularAssistentForDiscordServer/Migrations/20240622052300_Remove double guild ids.cs new file mode 100644 index 0000000..c8aa117 --- /dev/null +++ b/ModularAssistentForDiscordServer/Migrations/20240622052300_Remove double guild ids.cs @@ -0,0 +1,248 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace MADS.Migrations +{ + /// + public partial class Removedoubleguildids : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "discordId", + table: "guilds"); + + migrationBuilder.AlterColumn( + name: "id", + table: "VoiceAlerts", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "prefered_language", + table: "users", + type: "longtext", + nullable: true, + oldClrType: typeof(string), + oldType: "longtext") + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AlterColumn( + name: "id", + table: "users", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "id", + table: "Starboard", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "id", + table: "Reminders", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "id", + table: "Quotes", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "id", + table: "Incidents", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "id", + table: "guilds", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "starboardEmojiName", + table: "Configs", + type: "varchar(50)", + maxLength: 50, + nullable: true, + oldClrType: typeof(string), + oldType: "longtext", + oldNullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AlterColumn( + name: "prefix", + table: "Configs", + type: "varchar(5)", + maxLength: 5, + nullable: false, + oldClrType: typeof(string), + oldType: "longtext") + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AlterColumn( + name: "id", + table: "Configs", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "id", + table: "VoiceAlerts", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.UpdateData( + table: "users", + keyColumn: "prefered_language", + keyValue: null, + column: "prefered_language", + value: ""); + + migrationBuilder.AlterColumn( + name: "prefered_language", + table: "users", + type: "longtext", + nullable: false, + oldClrType: typeof(string), + oldType: "longtext", + oldNullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AlterColumn( + name: "id", + table: "users", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "id", + table: "Starboard", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "id", + table: "Reminders", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "id", + table: "Quotes", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "id", + table: "Incidents", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "id", + table: "guilds", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AddColumn( + name: "discordId", + table: "guilds", + type: "bigint unsigned", + nullable: false, + defaultValue: 0ul); + + migrationBuilder.AlterColumn( + name: "starboardEmojiName", + table: "Configs", + type: "longtext", + nullable: true, + oldClrType: typeof(string), + oldType: "varchar(50)", + oldMaxLength: 50, + oldNullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AlterColumn( + name: "prefix", + table: "Configs", + type: "longtext", + nullable: false, + oldClrType: typeof(string), + oldType: "varchar(5)", + oldMaxLength: 5) + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AlterColumn( + name: "id", + table: "Configs", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + } + } +} diff --git a/ModularAssistentForDiscordServer/Migrations/20240622055159_mark guild and user key as not db generated.Designer.cs b/ModularAssistentForDiscordServer/Migrations/20240622055159_mark guild and user key as not db generated.Designer.cs new file mode 100644 index 0000000..bc89fdf --- /dev/null +++ b/ModularAssistentForDiscordServer/Migrations/20240622055159_mark guild and user key as not db generated.Designer.cs @@ -0,0 +1,402 @@ +// +using System; +using MADS.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace MADS.Migrations +{ + [DbContext(typeof(MadsContext))] + [Migration("20240622055159_mark guild and user key as not db generated")] + partial class markguildanduserkeyasnotdbgenerated + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); + + modelBuilder.Entity("MADS.Entities.GuildConfigDbEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("GuildId") + .HasColumnType("bigint unsigned") + .HasColumnName("discordId"); + + b.Property("Prefix") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("varchar(5)") + .HasColumnName("prefix"); + + b.Property("StarboardActive") + .HasColumnType("tinyint(1)") + .HasColumnName("starboardEnabled"); + + b.Property("StarboardChannelId") + .HasColumnType("bigint unsigned") + .HasColumnName("starboardChannel"); + + b.Property("StarboardEmojiId") + .HasColumnType("bigint unsigned") + .HasColumnName("starboardEmojiId"); + + b.Property("StarboardEmojiName") + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasColumnName("starboardEmojiName"); + + b.Property("StarboardThreshold") + .HasColumnType("int") + .HasColumnName("starboardThreshold"); + + b.HasKey("Id"); + + b.HasIndex("GuildId") + .IsUnique(); + + b.ToTable("Configs"); + }); + + modelBuilder.Entity("MADS.Entities.GuildDbEntity", b => + { + b.Property("Id") + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + b.HasKey("Id"); + + b.ToTable("guilds", (string)null); + }); + + modelBuilder.Entity("MADS.Entities.IncidentDbEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("CreationTimeStamp") + .HasColumnType("datetime(6)"); + + b.Property("GuildId") + .HasColumnType("bigint unsigned") + .HasColumnName("guild_id"); + + b.Property("ModeratorId") + .HasColumnType("bigint unsigned") + .HasColumnName("moderator_id"); + + b.Property("Reason") + .IsRequired() + .HasColumnType("longtext") + .HasColumnName("reason"); + + b.Property("TargetId") + .HasColumnType("bigint unsigned") + .HasColumnName("target_id"); + + b.HasKey("Id"); + + b.HasIndex("GuildId"); + + b.HasIndex("TargetId"); + + b.ToTable("Incidents"); + }); + + modelBuilder.Entity("MADS.Entities.QuoteDbEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("varchar(1000)") + .HasColumnName("content"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)") + .HasColumnName("timestamp"); + + b.Property("GuildId") + .HasColumnType("bigint unsigned") + .HasColumnName("discordGuildId"); + + b.Property("QuotedUserId") + .HasColumnType("bigint unsigned") + .HasColumnName("quotedUserId"); + + b.Property("UserId") + .HasColumnType("bigint unsigned") + .HasColumnName("UserId"); + + b.HasKey("Id"); + + b.HasIndex("GuildId"); + + b.ToTable("Quotes"); + }); + + modelBuilder.Entity("MADS.Entities.ReminderDbEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("ChannelId") + .HasColumnType("bigint unsigned") + .HasColumnName("channelId"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("creationTime"); + + b.Property("ExecutionTime") + .HasColumnType("datetime(6)") + .HasColumnName("executionTime"); + + b.Property("IsPrivate") + .HasColumnType("tinyint(1)") + .HasColumnName("isPrivate"); + + b.Property("MentionedChannel") + .HasColumnType("bigint unsigned") + .HasColumnName("mentionedChannel"); + + b.Property("MentionedMessage") + .HasColumnType("bigint unsigned") + .HasColumnName("MentionedMessage"); + + b.Property("MessageId") + .HasColumnType("bigint unsigned") + .HasColumnName("messageId"); + + b.Property("ReminderText") + .IsRequired() + .HasColumnType("longtext") + .HasColumnName("reminderText"); + + b.Property("UserId") + .HasColumnType("bigint unsigned") + .HasColumnName("userId"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Reminders"); + }); + + modelBuilder.Entity("MADS.Entities.StarboardMessageDbEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("DiscordChannelId") + .HasColumnType("bigint unsigned") + .HasColumnName("discordChannelId"); + + b.Property("DiscordGuildId") + .HasColumnType("bigint unsigned") + .HasColumnName("discordGuildId"); + + b.Property("DiscordMessageId") + .HasColumnType("bigint unsigned") + .HasColumnName("discordMessageId"); + + b.Property("StarboardChannelId") + .HasColumnType("bigint unsigned") + .HasColumnName("starboardChannelId"); + + b.Property("StarboardGuildId") + .HasColumnType("bigint unsigned") + .HasColumnName("starboardGuildId"); + + b.Property("StarboardMessageId") + .HasColumnType("bigint unsigned") + .HasColumnName("starboardMessageId"); + + b.Property("Stars") + .HasColumnType("int") + .HasColumnName("starCount"); + + b.HasKey("Id"); + + b.ToTable("Starboard"); + }); + + modelBuilder.Entity("MADS.Entities.UserDbEntity", b => + { + b.Property("Id") + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + b.Property("PreferedLanguage") + .HasColumnType("longtext") + .HasColumnName("prefered_language"); + + b.Property("Username") + .IsRequired() + .HasColumnType("longtext") + .HasColumnName("username"); + + b.HasKey("Id"); + + b.ToTable("users", (string)null); + }); + + modelBuilder.Entity("MADS.Entities.VoiceAlert", b => + { + b.Property("AlertId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned") + .HasColumnName("id"); + + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("AlertId")); + + b.Property("ChannelId") + .HasColumnType("bigint unsigned") + .HasColumnName("channel_id"); + + b.Property("GuildId") + .HasColumnType("bigint unsigned") + .HasColumnName("guild_id"); + + b.Property("IsRepeatable") + .HasColumnType("tinyint(1)") + .HasColumnName("is_repeatable"); + + b.Property("LastAlert") + .HasColumnType("datetime(6)") + .HasColumnName("last_alert"); + + b.Property("MinTimeBetweenAlerts") + .HasColumnType("time(6)") + .HasColumnName("time_between"); + + b.Property("UserId") + .HasColumnType("bigint unsigned") + .HasColumnName("user_id"); + + b.HasKey("AlertId"); + + b.HasIndex("UserId"); + + b.ToTable("VoiceAlerts"); + }); + + modelBuilder.Entity("MADS.Entities.GuildConfigDbEntity", b => + { + b.HasOne("MADS.Entities.GuildDbEntity", "Guild") + .WithOne("Settings") + .HasForeignKey("MADS.Entities.GuildConfigDbEntity", "GuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Guild"); + }); + + modelBuilder.Entity("MADS.Entities.IncidentDbEntity", b => + { + b.HasOne("MADS.Entities.GuildDbEntity", "Guild") + .WithMany("Incidents") + .HasForeignKey("GuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("MADS.Entities.UserDbEntity", "TargetUser") + .WithMany("Incidents") + .HasForeignKey("TargetId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Guild"); + + b.Navigation("TargetUser"); + }); + + modelBuilder.Entity("MADS.Entities.QuoteDbEntity", b => + { + b.HasOne("MADS.Entities.GuildDbEntity", "Guild") + .WithMany("Quotes") + .HasForeignKey("GuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Guild"); + }); + + modelBuilder.Entity("MADS.Entities.ReminderDbEntity", b => + { + b.HasOne("MADS.Entities.UserDbEntity", "User") + .WithMany("Reminders") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("MADS.Entities.VoiceAlert", b => + { + b.HasOne("MADS.Entities.UserDbEntity", "User") + .WithMany("VoiceAlerts") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("MADS.Entities.GuildDbEntity", b => + { + b.Navigation("Incidents"); + + b.Navigation("Quotes"); + + b.Navigation("Settings") + .IsRequired(); + }); + + modelBuilder.Entity("MADS.Entities.UserDbEntity", b => + { + b.Navigation("Incidents"); + + b.Navigation("Reminders"); + + b.Navigation("VoiceAlerts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ModularAssistentForDiscordServer/Migrations/20240622055159_mark guild and user key as not db generated.cs b/ModularAssistentForDiscordServer/Migrations/20240622055159_mark guild and user key as not db generated.cs new file mode 100644 index 0000000..a0ece8a --- /dev/null +++ b/ModularAssistentForDiscordServer/Migrations/20240622055159_mark guild and user key as not db generated.cs @@ -0,0 +1,55 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace MADS.Migrations +{ + /// + public partial class markguildanduserkeyasnotdbgenerated : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "id", + table: "users", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "id", + table: "guilds", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "id", + table: "users", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + + migrationBuilder.AlterColumn( + name: "id", + table: "guilds", + type: "bigint unsigned", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + } + } +} diff --git a/ModularAssistentForDiscordServer/Migrations/MadsContextModelSnapshot.cs b/ModularAssistentForDiscordServer/Migrations/MadsContextModelSnapshot.cs index 8f0b05a..78fdcd8 100644 --- a/ModularAssistentForDiscordServer/Migrations/MadsContextModelSnapshot.cs +++ b/ModularAssistentForDiscordServer/Migrations/MadsContextModelSnapshot.cs @@ -3,6 +3,7 @@ using MADS.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; #nullable disable @@ -16,9 +17,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "8.0.1") + .HasAnnotation("ProductVersion", "8.0.6") .HasAnnotation("Relational:MaxIdentifierLength", 64); + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); + modelBuilder.Entity("MADS.Entities.GuildConfigDbEntity", b => { b.Property("Id") @@ -26,13 +29,16 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("bigint unsigned") .HasColumnName("id"); - b.Property("DiscordGuildId") + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + + b.Property("GuildId") .HasColumnType("bigint unsigned") .HasColumnName("discordId"); b.Property("Prefix") .IsRequired() - .HasColumnType("longtext") + .HasMaxLength(5) + .HasColumnType("varchar(5)") .HasColumnName("prefix"); b.Property("StarboardActive") @@ -48,7 +54,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnName("starboardEmojiId"); b.Property("StarboardEmojiName") - .HasColumnType("longtext") + .HasMaxLength(50) + .HasColumnType("varchar(50)") .HasColumnName("starboardEmojiName"); b.Property("StarboardThreshold") @@ -57,7 +64,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("DiscordGuildId") + b.HasIndex("GuildId") .IsUnique(); b.ToTable("Configs"); @@ -66,14 +73,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("MADS.Entities.GuildDbEntity", b => { b.Property("Id") - .ValueGeneratedOnAdd() .HasColumnType("bigint unsigned") .HasColumnName("id"); - b.Property("DiscordId") - .HasColumnType("bigint unsigned") - .HasColumnName("discordId"); - b.HasKey("Id"); b.ToTable("guilds", (string)null); @@ -86,6 +88,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("bigint unsigned") .HasColumnName("id"); + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + b.Property("CreationTimeStamp") .HasColumnType("datetime(6)"); @@ -122,6 +126,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("bigint unsigned") .HasColumnName("id"); + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + b.Property("Content") .IsRequired() .HasMaxLength(1000) @@ -132,7 +138,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("datetime(6)") .HasColumnName("timestamp"); - b.Property("DiscordGuildId") + b.Property("GuildId") .HasColumnType("bigint unsigned") .HasColumnName("discordGuildId"); @@ -146,7 +152,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); - b.HasIndex("DiscordGuildId"); + b.HasIndex("GuildId"); b.ToTable("Quotes"); }); @@ -158,6 +164,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("bigint unsigned") .HasColumnName("id"); + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + b.Property("ChannelId") .HasColumnType("bigint unsigned") .HasColumnName("channelId"); @@ -209,6 +217,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("bigint unsigned") .HasColumnName("id"); + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); + b.Property("DiscordChannelId") .HasColumnType("bigint unsigned") .HasColumnName("discordChannelId"); @@ -245,12 +255,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("MADS.Entities.UserDbEntity", b => { b.Property("Id") - .ValueGeneratedOnAdd() .HasColumnType("bigint unsigned") .HasColumnName("id"); b.Property("PreferedLanguage") - .IsRequired() .HasColumnType("longtext") .HasColumnName("prefered_language"); @@ -271,6 +279,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("bigint unsigned") .HasColumnName("id"); + MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("AlertId")); + b.Property("ChannelId") .HasColumnType("bigint unsigned") .HasColumnName("channel_id"); @@ -306,7 +316,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.HasOne("MADS.Entities.GuildDbEntity", "Guild") .WithOne("Settings") - .HasForeignKey("MADS.Entities.GuildConfigDbEntity", "DiscordGuildId") + .HasForeignKey("MADS.Entities.GuildConfigDbEntity", "GuildId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -336,7 +346,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.HasOne("MADS.Entities.GuildDbEntity", "Guild") .WithMany("Quotes") - .HasForeignKey("DiscordGuildId") + .HasForeignKey("GuildId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); diff --git a/ModularAssistentForDiscordServer/ModularAssistentForDiscordServer.csproj b/ModularAssistentForDiscordServer/ModularAssistentForDiscordServer.csproj index 6f701f2..a186812 100644 --- a/ModularAssistentForDiscordServer/ModularAssistentForDiscordServer.csproj +++ b/ModularAssistentForDiscordServer/ModularAssistentForDiscordServer.csproj @@ -25,33 +25,33 @@ - - - - - + + + + + - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + - - - + + + diff --git a/ModularAssistentForDiscordServer/ModularDiscordBot.cs b/ModularAssistentForDiscordServer/ModularDiscordBot.cs index 14ae151..48629af 100644 --- a/ModularAssistentForDiscordServer/ModularDiscordBot.cs +++ b/ModularAssistentForDiscordServer/ModularDiscordBot.cs @@ -15,6 +15,7 @@ using DeepL; using DSharpPlus; using DSharpPlus.Extensions; +using DSharpPlus.Net; using MADS.Entities; using MADS.EventListeners; using MADS.Extensions; @@ -66,11 +67,7 @@ await Host.CreateDefaultBuilder() options.EnableDetailedErrors(); } ) - .AddMemoryCache(options => - { - options.ExpirationScanFrequency = TimeSpan.FromMinutes(1); - options.SizeLimit = 4096L; - }) + .AddMemoryCache() .AddQuartz(x => { x.UsePersistentStore(options => diff --git a/ModularAssistentForDiscordServer/Services/LoggingService.cs b/ModularAssistentForDiscordServer/Services/LoggingService.cs index 3afc1b7..44f6627 100644 --- a/ModularAssistentForDiscordServer/Services/LoggingService.cs +++ b/ModularAssistentForDiscordServer/Services/LoggingService.cs @@ -195,19 +195,6 @@ private void SetupWebhookLogging() _discordWebhookClient.AddWebhookAsync(webhookUrl).GetAwaiter().GetResult(); } - public async Task LogEvent(string message, string sender, LogLevel lvl) - { - string log = $"[{DateTime.Now:yyyy'-'MM'-'dd'T'HH':'mm':'ss}] [{lvl}] [{sender}] {message}"; - await File.AppendAllTextAsync(_logPath, log + "\n", Encoding.UTF8); - } - - private async Task LogInfo(string input) - { - string logEntry = - $"[{DateTime.Now:dd'.'MM'.'yyyy'-'HH':'mm':'ss}] [INFO]" + input; - await File.AppendAllTextAsync(_logPath, logEntry + "\n", Encoding.UTF8); - } - public async Task> LogToOwner(string message, string sender, LogLevel logLevel) { DiscordEmbedBuilder discordEmbed = new() @@ -222,7 +209,7 @@ public async Task> LogToOwner(string message, string sender } }; - List messageList = new(); + List messageList = []; foreach (DiscordDmChannel channel in _ownerChannel) { diff --git a/ModularAssistentForDiscordServer/Services/QuotesService.cs b/ModularAssistentForDiscordServer/Services/QuotesService.cs index 5d15fab..a5f0320 100644 --- a/ModularAssistentForDiscordServer/Services/QuotesService.cs +++ b/ModularAssistentForDiscordServer/Services/QuotesService.cs @@ -29,14 +29,14 @@ public QuotesService(IDbContextFactory factory) public async Task> GetQuotesGuildAsync(ulong guildId) { await using MadsContext db = await _dbContextFactory.CreateDbContextAsync(); - return db.Quotes.AsNoTracking().Where(x => x.DiscordGuildId == guildId).ToList(); + return db.Quotes.AsNoTracking().Where(x => x.GuildId == guildId).ToList(); } public async Task GetRndGuildAsync(ulong guildId) { await using MadsContext db = await _dbContextFactory.CreateDbContextAsync(); Random rnd = new(); - QuoteDbEntity[] quotes = db.Quotes.AsNoTracking().Where(x => x.DiscordGuildId == guildId).ToArray(); + QuoteDbEntity[] quotes = db.Quotes.AsNoTracking().Where(x => x.GuildId == guildId).ToArray(); return quotes[rnd.Next(0, quotes.Length)]; } @@ -75,7 +75,7 @@ public async void DeleteQuotesByCreator(ulong id) public async void DeleteQuotesByGuild(ulong id) { await using MadsContext db = await _dbContextFactory.CreateDbContextAsync(); - List entities = db.Quotes.Where(x => x.DiscordGuildId == id).ToList(); + List entities = db.Quotes.Where(x => x.GuildId == id).ToList(); db.Quotes.RemoveRange(entities); await db.SaveChangesAsync(); } diff --git a/ModularAssistentForDiscordServer/Services/StarboardService.cs b/ModularAssistentForDiscordServer/Services/StarboardService.cs index 52699a9..8f5ce5d 100644 --- a/ModularAssistentForDiscordServer/Services/StarboardService.cs +++ b/ModularAssistentForDiscordServer/Services/StarboardService.cs @@ -158,7 +158,7 @@ private async Task HandleEvent(DiscordReactionUpdateEvent e) await using MadsContext db = await _dbFactory.CreateDbContextAsync(); GuildConfigDbEntity? guildSettings = - db.Configs.AsNoTracking().FirstOrDefault(x => x.DiscordGuildId == e.Message.Channel!.GuildId); + db.Configs.AsNoTracking().FirstOrDefault(x => x.GuildId == e.Message.Channel!.GuildId); if (guildSettings is null) { diff --git a/ModularAssistentForDiscordServer/Services/TranslateInformationService.cs b/ModularAssistentForDiscordServer/Services/TranslateInformationService.cs index 2b95a0b..95fd791 100644 --- a/ModularAssistentForDiscordServer/Services/TranslateInformationService.cs +++ b/ModularAssistentForDiscordServer/Services/TranslateInformationService.cs @@ -32,7 +32,7 @@ public TranslateInformationService(IDbContextFactory factory, Trans _translator = translator; } - public async void SetPreferredLanguage(ulong userId, string language) + public async void SetPreferredLanguage(ulong userId, string? language) { await using MadsContext db = await _dbContextFactory.CreateDbContextAsync(); UserDbEntity? user = db.Users.FirstOrDefault(x => x.Id == userId); @@ -45,7 +45,7 @@ public async void SetPreferredLanguage(ulong userId, string language) await db.SaveChangesAsync(); } - public async Task GetPreferredLanguage(ulong userId) + public async Task GetPreferredLanguageAsync(ulong userId) { await using MadsContext db = await _dbContextFactory.CreateDbContextAsync(); UserDbEntity? user = db.Users.AsNoTracking().FirstOrDefault(x => x.Id == userId);