From 67481d34c55bffca238b491a4e14f1fa3e1a3349 Mon Sep 17 00:00:00 2001 From: 13xforever Date: Fri, 24 Oct 2025 19:57:14 +0500 Subject: [PATCH] update the default warning message --- CompatBot/Commands/Warnings.ContextMenus.cs | 5 +--- CompatBot/Commands/Warnings.cs | 26 ++++++++++++++++--- CompatBot/Database/Providers/ContentFilter.cs | 11 +++----- .../EventHandlers/DiscordInviteFilter.cs | 10 +++---- CompatBot/EventHandlers/LogParsingHandler.cs | 9 +++---- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/CompatBot/Commands/Warnings.ContextMenus.cs b/CompatBot/Commands/Warnings.ContextMenus.cs index a7f3e6be..b68e86ad 100644 --- a/CompatBot/Commands/Warnings.ContextMenus.cs +++ b/CompatBot/Commands/Warnings.ContextMenus.cs @@ -69,10 +69,7 @@ internal static class WarningsContextMenus if (!suppress) { - var userMsgContent = $""" - User warning saved, {user.Mention} has {recent} recent warning{StringUtils.GetSuffix(recent)} ({total} total) - Warned for: {reason} by {ctx.User.Mention} - """; + var userMsgContent = await Warnings.GetDefaultWarningMessageAsync(ctx.Client, user, reason, recent, total, ctx.User).ConfigureAwait(false); var userMsg = new DiscordMessageBuilder() .WithContent(userMsgContent) .AddMention(new UserMention(user.Id)); diff --git a/CompatBot/Commands/Warnings.cs b/CompatBot/Commands/Warnings.cs index 615b11c0..3cdcf203 100644 --- a/CompatBot/Commands/Warnings.cs +++ b/CompatBot/Commands/Warnings.cs @@ -29,10 +29,7 @@ internal static partial class Warnings if (!suppress) { - var userMsgContent = $""" - User warning saved, {user.Mention} has {recent} recent warning{StringUtils.GetSuffix(recent)} ({total} total) - Warned for: {reason} by {ctx.User.Mention} - """; + var userMsgContent = await GetDefaultWarningMessageAsync(ctx.Client, user, reason, recent, total, ctx.User).ConfigureAwait(false); var userMsg = new DiscordMessageBuilder() .WithContent(userMsgContent) .AddMention(new UserMention(user)); @@ -175,6 +172,27 @@ internal static partial class Warnings await ctx.RespondAsync($"{Config.Reactions.Failure} Warning is not retracted", ephemeral: true).ConfigureAwait(false); } + internal static async ValueTask GetDefaultWarningMessageAsync( + DiscordClient client, + DiscordUser userToWarn, + string reason, + int recentWarnCount, + int totalWarnCount, + DiscordUser moderator) + { + var rulesCh = await client.GetChannelAsync(Config.BotRulesChannelId).ConfigureAwait(false); + return $""" + ## ⚠️ {userToWarn.Mention} you have been warned ⚠️ + **Reason:** {reason} + + **Read the {rulesCh.Mention} before continuing to chat** + Refusing to read/follow the server rules *will* result in a server ban + + -# You have {recentWarnCount} recent warning{StringUtils.GetSuffix(recentWarnCount)} ({totalWarnCount} total) + -# Warning added by {moderator.Mention} + """; + } + internal static async ValueTask<(bool saved, bool suppress, int recentCount, int totalCount)> AddAsync(ulong userId, DiscordUser issuer, string reason, string? fullReason = null) { diff --git a/CompatBot/Database/Providers/ContentFilter.cs b/CompatBot/Database/Providers/ContentFilter.cs index 76de9a3c..6119ff7e 100644 --- a/CompatBot/Database/Providers/ContentFilter.cs +++ b/CompatBot/Database/Providers/ContentFilter.cs @@ -233,20 +233,17 @@ internal static class ContentFilter ).ConfigureAwait(false); if (saved && !suppress && message.Channel is not null) { + var msgContent = await Warnings.GetDefaultWarningMessageAsync(client, message.Author, warningReason, recent, total, client.CurrentUser).ConfigureAwait(false); var msg = new DiscordMessageBuilder() - .WithContent( - $""" - User warning saved, {message.Author.Mention} has {recent} recent warning{StringUtils.GetSuffix(recent)} ({total} total) - Warned for: {warningReason} by {client.CurrentUser.Mention} - """ - ).AddMention(new UserMention(message.Author)); + .WithContent(msgContent) + .AddMention(new UserMention(message.Author)); await message.Channel.SendMessageAsync(msg).ConfigureAwait(false); } completedActions.Add(FilterAction.IssueWarning); } catch (Exception e) { - Config.Log.Warn(e, $"Couldn't issue warning in #{message.Channel.Name}"); + Config.Log.Warn(e, $"Couldn't issue warning in #{message.Channel?.Name}"); } } diff --git a/CompatBot/EventHandlers/DiscordInviteFilter.cs b/CompatBot/EventHandlers/DiscordInviteFilter.cs index 3fb4f7b1..f749b419 100644 --- a/CompatBot/EventHandlers/DiscordInviteFilter.cs +++ b/CompatBot/EventHandlers/DiscordInviteFilter.cs @@ -4,6 +4,7 @@ using System.Net.Http.Headers; using System.Text.RegularExpressions; using CompatApiClient.Compression; using CompatBot.Commands; +using CompatBot.Database; using CompatBot.Database.Providers; using CompatBot.Utils.Extensions; using Microsoft.Extensions.Caching.Memory; @@ -130,13 +131,10 @@ internal static partial class DiscordInviteFilter ).ConfigureAwait(false); if (saved && !suppress) { + var content = await Warnings.GetDefaultWarningMessageAsync(client, message.Author, reason, recent, total, client.CurrentUser).ConfigureAwait(false); var msg = new DiscordMessageBuilder() - .WithContent( - $""" - User warning saved, {message.Author.Mention} has {recent} recent warning{StringUtils.GetSuffix(recent)} ({total} total) - Warned for: {reason} by {client.CurrentUser.Mention} - """ - ).AddMention(new UserMention(message.Author)); + .WithContent(content) + .AddMention(new UserMention(message.Author)); await message.Channel.SendMessageAsync(msg).ConfigureAwait(false); } } diff --git a/CompatBot/EventHandlers/LogParsingHandler.cs b/CompatBot/EventHandlers/LogParsingHandler.cs index a24bfc7c..8c170a81 100644 --- a/CompatBot/EventHandlers/LogParsingHandler.cs +++ b/CompatBot/EventHandlers/LogParsingHandler.cs @@ -235,13 +235,10 @@ public static class LogParsingHandler ); if (saved && !suppress) { + var content = await Warnings.GetDefaultWarningMessageAsync(client, message.Author, reason, recent, total, client.CurrentUser).ConfigureAwait(false); var msg = new DiscordMessageBuilder() - .WithContent( - $""" - User warning saved, {message.Author.Mention} has {recent} recent warning{StringUtils.GetSuffix(recent)} ({total} total) - Warned for: {reason} by {client.CurrentUser.Mention} - """ - ).AddMention(new UserMention(message.Author)); + .WithContent(content) + .AddMention(new UserMention(message.Author)); await message.Channel!.SendMessageAsync(msg).ConfigureAwait(false); } }