From ad8ded917a2a9738092ce2a6cdd7b9133ce110e4 Mon Sep 17 00:00:00 2001 From: SylveonDeko <59923820+SylveonDeko@users.noreply.github.com> Date: Mon, 7 Oct 2024 11:00:39 -0400 Subject: [PATCH] Fix moving data from sqlite to psql. Add deny sending messages in threads to lockdown, fixed action commands --- .../Common/Attributes/DB/NewPropertyAttriburte.cs | 2 +- src/Mewdeko/Common/Replacements/ReplacementBuilder.cs | 2 +- src/Mewdeko/Database/Models/AntiProtection.cs | 10 ++++++++++ src/Mewdeko/Database/Models/GuildConfig.cs | 1 + src/Mewdeko/GlobalUsings.cs | 1 + src/Mewdeko/Mewdeko.csproj | 2 +- src/Mewdeko/Modules/Music/Music.cs | 2 -- .../Services/ChannelCommandService.cs | 2 +- .../Server Management/Services/RoleMonitorService.cs | 4 ++-- src/Mewdeko/Program.cs | 2 +- 10 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Mewdeko/Common/Attributes/DB/NewPropertyAttriburte.cs b/src/Mewdeko/Common/Attributes/DB/NewPropertyAttriburte.cs index 106a8dc46..2e0ddc17a 100644 --- a/src/Mewdeko/Common/Attributes/DB/NewPropertyAttriburte.cs +++ b/src/Mewdeko/Common/Attributes/DB/NewPropertyAttriburte.cs @@ -3,5 +3,5 @@ namespace Mewdeko.Common.Attributes.DB; /// /// Used for specifying when a db column is new and to not copy it /// -[AttributeUsage(AttributeTargets.Property)] +[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class)] public class NewPropertyAttribute : Attribute; \ No newline at end of file diff --git a/src/Mewdeko/Common/Replacements/ReplacementBuilder.cs b/src/Mewdeko/Common/Replacements/ReplacementBuilder.cs index 1e3b3983d..5fdfad747 100644 --- a/src/Mewdeko/Common/Replacements/ReplacementBuilder.cs +++ b/src/Mewdeko/Common/Replacements/ReplacementBuilder.cs @@ -43,7 +43,7 @@ public partial class ReplacementBuilder /// The Discord client. public ReplacementBuilder(DiscordShardedClient? client = null) { - nekosBestApi = new NekosBestApi(); + nekosBestApi = new NekosBestApi(client?.CurrentUser.Username ?? "Mewdeko"); this.client = client; WithRngRegex(); } diff --git a/src/Mewdeko/Database/Models/AntiProtection.cs b/src/Mewdeko/Database/Models/AntiProtection.cs index 8713cf12c..2682e746d 100644 --- a/src/Mewdeko/Database/Models/AntiProtection.cs +++ b/src/Mewdeko/Database/Models/AntiProtection.cs @@ -77,29 +77,34 @@ public class AntiSpamSetting : DbEntity /// /// Represents settings for anti-mass mention protection in a guild. /// +[NewProperty] [Table("AntiMassMentionSetting")] public class AntiMassMentionSetting : DbEntity { /// /// Gets or sets the ID of the associated guild configuration. /// + [NewProperty] [ForeignKey("GuildConfigId")] public int GuildConfigId { get; set; } /// /// Gets or sets the action to be taken when anti-mass mention measures are triggered. /// + [NewProperty] public PunishmentAction Action { get; set; } /// /// Gets or sets the maximum number of mentions allowed in a single message before triggering anti-mass mention /// measures. /// + [NewProperty] public int MentionThreshold { get; set; } = 3; /// /// Gets or sets the maximum number of mentions allowed within a specified time window. /// + [NewProperty] public int MaxMentionsInTimeWindow { get; set; } = 5; /// @@ -107,27 +112,32 @@ public class AntiMassMentionSetting : DbEntity /// If the number of mentions exceeds MaxMentionsInTimeWindow within this time, anti-mass mention actions are /// triggered. /// + [NewProperty] public int TimeWindowSeconds { get; set; } = 60; /// /// Gets or sets the mute duration in minutes. /// This is applied when a mute action is chosen as the punishment. /// + [NewProperty] public int MuteTime { get; set; } = 0; /// /// Gets or sets the ID of the role to be assigned as punishment. /// + [NewProperty] public ulong? RoleId { get; set; } /// /// Gets or sets a boolean indicating whether bots should be ignored by anti-mass mention measures. /// + [NewProperty] public bool IgnoreBots { get; set; } = true; /// /// Gets or sets the collection of ignored channels for anti-mass mention measures. /// + [NewProperty] public HashSet IgnoredChannels { get; set; } = new(); } diff --git a/src/Mewdeko/Database/Models/GuildConfig.cs b/src/Mewdeko/Database/Models/GuildConfig.cs index 90d33c3b5..7c1799d46 100644 --- a/src/Mewdeko/Database/Models/GuildConfig.cs +++ b/src/Mewdeko/Database/Models/GuildConfig.cs @@ -766,6 +766,7 @@ public class GuildConfig : DbEntity /// /// Gets or sets the anti mass mention settings for the guild. /// + [NewProperty] public AntiMassMentionSetting AntiMassMentionSetting { get; set; } /// diff --git a/src/Mewdeko/GlobalUsings.cs b/src/Mewdeko/GlobalUsings.cs index 7b4f54c55..fda180377 100644 --- a/src/Mewdeko/GlobalUsings.cs +++ b/src/Mewdeko/GlobalUsings.cs @@ -14,5 +14,6 @@ global using Mewdeko.Database.Models; global using Mewdeko.Extensions; global using Mewdeko.Services; +global using Mewdeko.Common.Attributes.DB; global using NonBlocking; global using EventHandler = Mewdeko.Services.Impl.EventHandler; \ No newline at end of file diff --git a/src/Mewdeko/Mewdeko.csproj b/src/Mewdeko/Mewdeko.csproj index 5c14b1dc9..95eb1d144 100644 --- a/src/Mewdeko/Mewdeko.csproj +++ b/src/Mewdeko/Mewdeko.csproj @@ -93,7 +93,7 @@ - + diff --git a/src/Mewdeko/Modules/Music/Music.cs b/src/Mewdeko/Modules/Music/Music.cs index 6d1aa7a75..50463e13e 100644 --- a/src/Mewdeko/Modules/Music/Music.cs +++ b/src/Mewdeko/Modules/Music/Music.cs @@ -35,9 +35,7 @@ public async Task Join() { var (player, result) = await GetPlayerAsync(); if (string.IsNullOrWhiteSpace(result)) - { await ReplyConfirmLocalizedAsync("music_join_success", player.VoiceChannelId).ConfigureAwait(false); - } else { var eb = new EmbedBuilder() diff --git a/src/Mewdeko/Modules/Server Management/Services/ChannelCommandService.cs b/src/Mewdeko/Modules/Server Management/Services/ChannelCommandService.cs index 888cc9695..b6fdec47e 100644 --- a/src/Mewdeko/Modules/Server Management/Services/ChannelCommandService.cs +++ b/src/Mewdeko/Modules/Server Management/Services/ChannelCommandService.cs @@ -283,7 +283,7 @@ public async Task ApplyLockdown(IGuild guild) createPrivateThreads: PermValue.Deny, sendMessages: PermValue.Allow), _ => existingPerms.Modify(sendMessages: PermValue.Deny, createPublicThreads: PermValue.Deny, - createPrivateThreads: PermValue.Deny) + createPrivateThreads: PermValue.Deny, sendMessagesInThreads: PermValue.Deny) }; channelPermissions.Add((channel, lockdownPerms)); diff --git a/src/Mewdeko/Modules/Server Management/Services/RoleMonitorService.cs b/src/Mewdeko/Modules/Server Management/Services/RoleMonitorService.cs index ed5be8368..c39710130 100644 --- a/src/Mewdeko/Modules/Server Management/Services/RoleMonitorService.cs +++ b/src/Mewdeko/Modules/Server Management/Services/RoleMonitorService.cs @@ -188,8 +188,8 @@ private async Task HandleRoleUpdatedAsync(IGuild guild, IAuditLogEntry entry) /// private async Task IsUserWhitelistedAsync(IGuild guild, ulong userId) { - // if (guild.OwnerId == userId) - // return true; + if (guild.OwnerId == userId) + return true; var redisDb = dataCache.Redis.GetDatabase(); var key = $"guild:{guild.Id}:whitelisted_users"; diff --git a/src/Mewdeko/Program.cs b/src/Mewdeko/Program.cs index a25a6bc21..c0895da29 100644 --- a/src/Mewdeko/Program.cs +++ b/src/Mewdeko/Program.cs @@ -199,7 +199,7 @@ private static void ConfigureServices(IServiceCollection services, BotCredential { ReturnAfterSendingPaginator = true })) - .AddSingleton(new NekosBestApi()) + .AddSingleton(new NekosBestApi("Mewdeko")) .AddSingleton(p => new InteractionService(p.GetRequiredService())) .AddSingleton() .AddSingleton()