From ab260eea15a6f05fc0982276c096205c858d6db2 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Tue, 25 Jun 2024 22:31:22 +0500 Subject: [PATCH 1/6] Ban backticks in /remind --- TeamOctolings.Octobot/Commands/RemindCommandGroup.cs | 10 ++++++++++ TeamOctolings.Octobot/Messages.Designer.cs | 6 ++++++ TeamOctolings.Octobot/Messages.resx | 3 +++ TeamOctolings.Octobot/Messages.ru.resx | 3 +++ 4 files changed, 22 insertions(+) diff --git a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs index be53ed7..3b9f2c0 100644 --- a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs @@ -158,6 +158,16 @@ public async Task ExecuteReminderAsync( return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: CancellationToken); } + if (text.Contains('`')) + { + var failedEmbed = new EmbedBuilder() + .WithSmallTitle(Messages.RemindBannedText, bot) + .WithColour(ColorsList.Red) + .Build(); + + return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: CancellationToken); + } + return await AddReminderAsync(timeSpan, text, data, channelId, executor, CancellationToken); } diff --git a/TeamOctolings.Octobot/Messages.Designer.cs b/TeamOctolings.Octobot/Messages.Designer.cs index bbc1366..e51cd9e 100644 --- a/TeamOctolings.Octobot/Messages.Designer.cs +++ b/TeamOctolings.Octobot/Messages.Designer.cs @@ -1196,5 +1196,11 @@ internal static string SettingsModeratorRole { return ResourceManager.GetString("SettingsModeratorRole", resourceCulture); } } + + internal static string RemindBannedText { + get { + return ResourceManager.GetString("RemindBannedText", resourceCulture); + } + } } } diff --git a/TeamOctolings.Octobot/Messages.resx b/TeamOctolings.Octobot/Messages.resx index 47e7d4f..494f19d 100644 --- a/TeamOctolings.Octobot/Messages.resx +++ b/TeamOctolings.Octobot/Messages.resx @@ -681,4 +681,7 @@ Moderator role + + Text contains banned characters! + diff --git a/TeamOctolings.Octobot/Messages.ru.resx b/TeamOctolings.Octobot/Messages.ru.resx index 2eef257..7ad3da4 100644 --- a/TeamOctolings.Octobot/Messages.ru.resx +++ b/TeamOctolings.Octobot/Messages.ru.resx @@ -681,4 +681,7 @@ Роль модератора + + Текст имеет запрещенные символы! + From ee2a19409af056e2c66cebda48ca76b85beca7c4 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Sun, 30 Jun 2024 13:45:28 +0500 Subject: [PATCH 2/6] Revert "Ban backticks in /remind" This reverts commit ab260eea15a6f05fc0982276c096205c858d6db2. --- TeamOctolings.Octobot/Commands/RemindCommandGroup.cs | 10 ---------- TeamOctolings.Octobot/Messages.Designer.cs | 6 ------ TeamOctolings.Octobot/Messages.resx | 3 --- TeamOctolings.Octobot/Messages.ru.resx | 3 --- 4 files changed, 22 deletions(-) diff --git a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs index 3b9f2c0..be53ed7 100644 --- a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs @@ -158,16 +158,6 @@ public async Task ExecuteReminderAsync( return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: CancellationToken); } - if (text.Contains('`')) - { - var failedEmbed = new EmbedBuilder() - .WithSmallTitle(Messages.RemindBannedText, bot) - .WithColour(ColorsList.Red) - .Build(); - - return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: CancellationToken); - } - return await AddReminderAsync(timeSpan, text, data, channelId, executor, CancellationToken); } diff --git a/TeamOctolings.Octobot/Messages.Designer.cs b/TeamOctolings.Octobot/Messages.Designer.cs index e51cd9e..bbc1366 100644 --- a/TeamOctolings.Octobot/Messages.Designer.cs +++ b/TeamOctolings.Octobot/Messages.Designer.cs @@ -1196,11 +1196,5 @@ internal static string SettingsModeratorRole { return ResourceManager.GetString("SettingsModeratorRole", resourceCulture); } } - - internal static string RemindBannedText { - get { - return ResourceManager.GetString("RemindBannedText", resourceCulture); - } - } } } diff --git a/TeamOctolings.Octobot/Messages.resx b/TeamOctolings.Octobot/Messages.resx index 494f19d..47e7d4f 100644 --- a/TeamOctolings.Octobot/Messages.resx +++ b/TeamOctolings.Octobot/Messages.resx @@ -681,7 +681,4 @@ Moderator role - - Text contains banned characters! - diff --git a/TeamOctolings.Octobot/Messages.ru.resx b/TeamOctolings.Octobot/Messages.ru.resx index 7ad3da4..2eef257 100644 --- a/TeamOctolings.Octobot/Messages.ru.resx +++ b/TeamOctolings.Octobot/Messages.ru.resx @@ -681,7 +681,4 @@ Роль модератора - - Текст имеет запрещенные символы! - From a4661116de8b4c2ca71370e96c03514a38d5d093 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Sun, 30 Jun 2024 14:26:29 +0500 Subject: [PATCH 3/6] a more clever workaround --- .../Commands/RemindCommandGroup.cs | 34 ++++++++++++++----- TeamOctolings.Octobot/Messages.Designer.cs | 12 +++++++ TeamOctolings.Octobot/Messages.resx | 6 ++++ TeamOctolings.Octobot/Messages.ru.resx | 6 ++++ 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs index be53ed7..27f74a0 100644 --- a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs @@ -158,11 +158,22 @@ public async Task ExecuteReminderAsync( return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: CancellationToken); } - return await AddReminderAsync(timeSpan, text, data, channelId, executor, CancellationToken); + var replacedText = text.Replace("`", ""); + if (replacedText.Equals(string.Empty)) + { + var failedEmbed = new EmbedBuilder() + .WithSmallTitle(Messages.ReminderTextOnlyBanned, bot) + .WithColour(ColorsList.Red) + .Build(); + + return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: CancellationToken); + } + + return await AddReminderAsync(timeSpan, text, replacedText, data, channelId, executor, CancellationToken); } - private async Task AddReminderAsync(TimeSpan timeSpan, string text, GuildData data, - Snowflake channelId, IUser executor, CancellationToken ct = default) + private async Task AddReminderAsync(TimeSpan timeSpan, string text, string replacedText, + GuildData data, Snowflake channelId, IUser executor, CancellationToken ct = default) { var memberData = data.GetOrCreateMemberData(executor.ID); var remindAt = DateTimeOffset.UtcNow.Add(timeSpan); @@ -177,17 +188,24 @@ private async Task AddReminderAsync(TimeSpan timeSpan, string text, Guil { At = remindAt, ChannelId = channelId.Value, - Text = text, + Text = replacedText, MessageId = response.ID.Value }); - var builder = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(text))) - .AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(remindAt))); + var textEqualsReplaced = text.Equals(replacedText); + var builder = new StringBuilder().AppendBulletPointLine( + string.Format(Messages.ReminderText, Markdown.InlineCode(replacedText))); + if (!textEqualsReplaced) + { + builder.AppendSubBulletPointLine(Messages.ReminderTextContainedBanned); + } + + builder.AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(remindAt))); + var embed = new EmbedBuilder().WithSmallTitle( string.Format(Messages.ReminderCreated, executor.GetTag()), executor) .WithDescription(builder.ToString()) - .WithColour(ColorsList.Green) + .WithColour(textEqualsReplaced ? ColorsList.Green : ColorsList.Yellow) .WithFooter(string.Format(Messages.ReminderPosition, memberData.Reminders.Count)) .Build(); diff --git a/TeamOctolings.Octobot/Messages.Designer.cs b/TeamOctolings.Octobot/Messages.Designer.cs index bbc1366..5ea10f0 100644 --- a/TeamOctolings.Octobot/Messages.Designer.cs +++ b/TeamOctolings.Octobot/Messages.Designer.cs @@ -1196,5 +1196,17 @@ internal static string SettingsModeratorRole { return ResourceManager.GetString("SettingsModeratorRole", resourceCulture); } } + + internal static string ReminderTextContainedBanned { + get { + return ResourceManager.GetString("ReminderTextContainedBanned", resourceCulture); + } + } + + internal static string ReminderTextOnlyBanned { + get { + return ResourceManager.GetString("ReminderTextOnlyBanned", resourceCulture); + } + } } } diff --git a/TeamOctolings.Octobot/Messages.resx b/TeamOctolings.Octobot/Messages.resx index 47e7d4f..9f7955d 100644 --- a/TeamOctolings.Octobot/Messages.resx +++ b/TeamOctolings.Octobot/Messages.resx @@ -681,4 +681,10 @@ Moderator role + + Reminder text contained banned characters. + + + Reminder text contains only banned characters! + diff --git a/TeamOctolings.Octobot/Messages.ru.resx b/TeamOctolings.Octobot/Messages.ru.resx index 2eef257..d6c5446 100644 --- a/TeamOctolings.Octobot/Messages.ru.resx +++ b/TeamOctolings.Octobot/Messages.ru.resx @@ -681,4 +681,10 @@ Роль модератора + + Текст напоминания содержал запрещенные символы. + + + Текст напоминания содержит только запрещенные символы! + From 2aaed56ca6bf13b46c50b2df4a5d555a02540df0 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Mon, 1 Jul 2024 20:31:55 +0500 Subject: [PATCH 4/6] i love reverting commits This reverts commit a4661116de8b4c2ca71370e96c03514a38d5d093. --- .../Commands/RemindCommandGroup.cs | 34 +++++-------------- TeamOctolings.Octobot/Messages.Designer.cs | 12 ------- TeamOctolings.Octobot/Messages.resx | 6 ---- TeamOctolings.Octobot/Messages.ru.resx | 6 ---- 4 files changed, 8 insertions(+), 50 deletions(-) diff --git a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs index 27f74a0..be53ed7 100644 --- a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs @@ -158,22 +158,11 @@ public async Task ExecuteReminderAsync( return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: CancellationToken); } - var replacedText = text.Replace("`", ""); - if (replacedText.Equals(string.Empty)) - { - var failedEmbed = new EmbedBuilder() - .WithSmallTitle(Messages.ReminderTextOnlyBanned, bot) - .WithColour(ColorsList.Red) - .Build(); - - return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: CancellationToken); - } - - return await AddReminderAsync(timeSpan, text, replacedText, data, channelId, executor, CancellationToken); + return await AddReminderAsync(timeSpan, text, data, channelId, executor, CancellationToken); } - private async Task AddReminderAsync(TimeSpan timeSpan, string text, string replacedText, - GuildData data, Snowflake channelId, IUser executor, CancellationToken ct = default) + private async Task AddReminderAsync(TimeSpan timeSpan, string text, GuildData data, + Snowflake channelId, IUser executor, CancellationToken ct = default) { var memberData = data.GetOrCreateMemberData(executor.ID); var remindAt = DateTimeOffset.UtcNow.Add(timeSpan); @@ -188,24 +177,17 @@ private async Task AddReminderAsync(TimeSpan timeSpan, string text, stri { At = remindAt, ChannelId = channelId.Value, - Text = replacedText, + Text = text, MessageId = response.ID.Value }); - var textEqualsReplaced = text.Equals(replacedText); - var builder = new StringBuilder().AppendBulletPointLine( - string.Format(Messages.ReminderText, Markdown.InlineCode(replacedText))); - if (!textEqualsReplaced) - { - builder.AppendSubBulletPointLine(Messages.ReminderTextContainedBanned); - } - - builder.AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(remindAt))); - + var builder = new StringBuilder() + .AppendBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(text))) + .AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(remindAt))); var embed = new EmbedBuilder().WithSmallTitle( string.Format(Messages.ReminderCreated, executor.GetTag()), executor) .WithDescription(builder.ToString()) - .WithColour(textEqualsReplaced ? ColorsList.Green : ColorsList.Yellow) + .WithColour(ColorsList.Green) .WithFooter(string.Format(Messages.ReminderPosition, memberData.Reminders.Count)) .Build(); diff --git a/TeamOctolings.Octobot/Messages.Designer.cs b/TeamOctolings.Octobot/Messages.Designer.cs index 5ea10f0..bbc1366 100644 --- a/TeamOctolings.Octobot/Messages.Designer.cs +++ b/TeamOctolings.Octobot/Messages.Designer.cs @@ -1196,17 +1196,5 @@ internal static string SettingsModeratorRole { return ResourceManager.GetString("SettingsModeratorRole", resourceCulture); } } - - internal static string ReminderTextContainedBanned { - get { - return ResourceManager.GetString("ReminderTextContainedBanned", resourceCulture); - } - } - - internal static string ReminderTextOnlyBanned { - get { - return ResourceManager.GetString("ReminderTextOnlyBanned", resourceCulture); - } - } } } diff --git a/TeamOctolings.Octobot/Messages.resx b/TeamOctolings.Octobot/Messages.resx index 9f7955d..47e7d4f 100644 --- a/TeamOctolings.Octobot/Messages.resx +++ b/TeamOctolings.Octobot/Messages.resx @@ -681,10 +681,4 @@ Moderator role - - Reminder text contained banned characters. - - - Reminder text contains only banned characters! - diff --git a/TeamOctolings.Octobot/Messages.ru.resx b/TeamOctolings.Octobot/Messages.ru.resx index d6c5446..2eef257 100644 --- a/TeamOctolings.Octobot/Messages.ru.resx +++ b/TeamOctolings.Octobot/Messages.ru.resx @@ -681,10 +681,4 @@ Роль модератора - - Текст напоминания содержал запрещенные символы. - - - Текст напоминания содержит только запрещенные символы! - From 1dffff25d50401dcccfe192610098e552c344f82 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Mon, 1 Jul 2024 20:35:48 +0500 Subject: [PATCH 5/6] extremely high quality (not) workaround didn't even tested it yet --- TeamOctolings.Octobot/Commands/RemindCommandGroup.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs index be53ed7..5b09769 100644 --- a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs @@ -94,7 +94,7 @@ private Task ListRemindersAsync(MemberData data, Snowflake guildId, IUse { var reminder = data.Reminders[i]; builder.AppendBulletPointLine(string.Format(Messages.ReminderPosition, Markdown.InlineCode((i + 1).ToString()))) - .AppendSubBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(reminder.Text))) + .AppendSubBulletPointLine(string.Format(Messages.ReminderText, reminder.Text)) .AppendSubBulletPointLine(string.Format(Messages.ReminderTime, Markdown.Timestamp(reminder.At))) .AppendSubBulletPointLine(string.Format(Messages.DescriptionActionJumpToMessage, $"https://discord.com/channels/{guildId.Value}/{reminder.ChannelId}/{reminder.MessageId}")); } @@ -182,7 +182,7 @@ private async Task AddReminderAsync(TimeSpan timeSpan, string text, Guil }); var builder = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(text))) + .AppendBulletPointLine(string.Format(Messages.ReminderText, text)) .AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(remindAt))); var embed = new EmbedBuilder().WithSmallTitle( string.Format(Messages.ReminderCreated, executor.GetTag()), executor) @@ -279,7 +279,7 @@ private async Task EditReminderTimeAsync(int index, string value, Member data.Reminders.RemoveAt(index); var builder = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(oldReminder.Text))) + .AppendBulletPointLine(string.Format(Messages.ReminderText, oldReminder.Text)) .AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(remindAt))); var embed = new EmbedBuilder().WithSmallTitle( string.Format(Messages.ReminderEdited, executor.GetTag()), executor) @@ -309,7 +309,7 @@ private async Task EditReminderTextAsync(int index, string value, Member data.Reminders.RemoveAt(index); var builder = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(value))) + .AppendBulletPointLine(string.Format(Messages.ReminderText, value)) .AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(oldReminder.At))); var embed = new EmbedBuilder().WithSmallTitle( string.Format(Messages.ReminderEdited, executor.GetTag()), executor) @@ -367,7 +367,7 @@ private Task DeleteReminderAsync(MemberData data, int index, IUser bot, var reminder = data.Reminders[index]; var description = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(reminder.Text))) + .AppendBulletPointLine(string.Format(Messages.ReminderText, reminder.Text)) .AppendBulletPointLine(string.Format(Messages.ReminderTime, Markdown.Timestamp(reminder.At))); data.Reminders.RemoveAt(index); From 2b9e3c8d5a149274b986ea67c2419b3e81b77492 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Mon, 1 Jul 2024 20:58:55 +0500 Subject: [PATCH 6/6] fuck workarounds, i have a fresh idea --- TeamOctolings.Octobot/Commands/RemindCommandGroup.cs | 8 ++++---- .../Extensions/MarkdownExtensions.cs | 12 ++++++++++++ .../Services/Update/MemberUpdateService.cs | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs index 5b09769..3188d27 100644 --- a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs @@ -182,7 +182,7 @@ private async Task AddReminderAsync(TimeSpan timeSpan, string text, Guil }); var builder = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.ReminderText, text)) + .AppendLine(MarkdownExtensions.Quote(text)) .AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(remindAt))); var embed = new EmbedBuilder().WithSmallTitle( string.Format(Messages.ReminderCreated, executor.GetTag()), executor) @@ -279,7 +279,7 @@ private async Task EditReminderTimeAsync(int index, string value, Member data.Reminders.RemoveAt(index); var builder = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.ReminderText, oldReminder.Text)) + .AppendLine(MarkdownExtensions.Quote(oldReminder.Text)) .AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(remindAt))); var embed = new EmbedBuilder().WithSmallTitle( string.Format(Messages.ReminderEdited, executor.GetTag()), executor) @@ -309,7 +309,7 @@ private async Task EditReminderTextAsync(int index, string value, Member data.Reminders.RemoveAt(index); var builder = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.ReminderText, value)) + .AppendLine(MarkdownExtensions.Quote(value)) .AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(oldReminder.At))); var embed = new EmbedBuilder().WithSmallTitle( string.Format(Messages.ReminderEdited, executor.GetTag()), executor) @@ -367,7 +367,7 @@ private Task DeleteReminderAsync(MemberData data, int index, IUser bot, var reminder = data.Reminders[index]; var description = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.ReminderText, reminder.Text)) + .AppendLine(MarkdownExtensions.Quote(reminder.Text)) .AppendBulletPointLine(string.Format(Messages.ReminderTime, Markdown.Timestamp(reminder.At))); data.Reminders.RemoveAt(index); diff --git a/TeamOctolings.Octobot/Extensions/MarkdownExtensions.cs b/TeamOctolings.Octobot/Extensions/MarkdownExtensions.cs index 202cd37..30ddff5 100644 --- a/TeamOctolings.Octobot/Extensions/MarkdownExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/MarkdownExtensions.cs @@ -13,4 +13,16 @@ public static string BulletPoint(string text) { return $"- {text}"; } + + /// + /// Formats a string to use Markdown Quote formatting. + /// + /// The input text to format. + /// + /// A markdown-formatted quote string. + /// + public static string Quote(string text) + { + return $"> {text}"; + } } diff --git a/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs b/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs index 0c49c24..3170060 100644 --- a/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs +++ b/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs @@ -234,7 +234,7 @@ private async Task TickReminderAsync(Reminder reminder, IUser user, Memb } var builder = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.DescriptionReminder, Markdown.InlineCode(reminder.Text))) + .AppendLine(MarkdownExtensions.Quote(reminder.Text)) .AppendBulletPointLine(string.Format(Messages.DescriptionActionJumpToMessage, $"https://discord.com/channels/{guildId.Value}/{reminder.ChannelId}/{reminder.MessageId}"));