From 72f1f774c7fd9a53a68e4b0058fca1ec755668d1 Mon Sep 17 00:00:00 2001 From: 13xforever Date: Tue, 4 Aug 2020 00:52:51 +0500 Subject: [PATCH] extend mention policy usage a bit --- CompatBot/Config.cs | 6 +++++- CompatBot/EventHandlers/DeletedMessagesMonitor.cs | 6 +++--- CompatBot/EventHandlers/EmpathySimulationHandler.cs | 2 +- CompatBot/Utils/Extensions/DiscordClientExtensions.cs | 8 ++++---- .../LogParserResultFormatter.GeneralNotesSection.cs | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CompatBot/Config.cs b/CompatBot/Config.cs index b5d77739..81aa3dc2 100644 --- a/CompatBot/Config.cs +++ b/CompatBot/Config.cs @@ -84,7 +84,11 @@ namespace CompatBot public static double GameTitleMatchThreshold => config.GetValue(nameof(GameTitleMatchThreshold), 0.57); public static byte[] CryptoSalt => Convert.FromBase64String(config.GetValue(nameof(CryptoSalt), "")); - internal static readonly IMention[] AllowedMentions = { UserMention.All }; + internal static class AllowedMentions + { + internal static readonly IMention[] UsersOnly = { UserMention.All }; + internal static readonly IMention[] Nothing = { }; + } internal static string CurrentLogPath => Path.GetFullPath(Path.Combine(LogPath, "bot.log")); diff --git a/CompatBot/EventHandlers/DeletedMessagesMonitor.cs b/CompatBot/EventHandlers/DeletedMessagesMonitor.cs index 4bff5fdc..061cbec8 100644 --- a/CompatBot/EventHandlers/DeletedMessagesMonitor.cs +++ b/CompatBot/EventHandlers/DeletedMessagesMonitor.cs @@ -58,11 +58,11 @@ namespace CompatBot.EventHandlers await postLock.WaitAsync().ConfigureAwait(false); try { - await logChannel.SendMessageAsync(embed: embed, mentions: Config.AllowedMentions).ConfigureAwait(false); + await logChannel.SendMessageAsync(embed: embed, mentions: Config.AllowedMentions.Nothing).ConfigureAwait(false); if (attachmentContent?.Count > 0) - await logChannel.SendMultipleFilesAsync(attachmentContent, msg.Content, mentions: Config.AllowedMentions).ConfigureAwait(false); + await logChannel.SendMultipleFilesAsync(attachmentContent, msg.Content, mentions: Config.AllowedMentions.Nothing).ConfigureAwait(false); else if (!string.IsNullOrEmpty(msg.Content)) - await logChannel.SendMessageAsync(msg.Content, mentions: Config.AllowedMentions).ConfigureAwait(false); + await logChannel.SendMessageAsync(msg.Content, mentions: Config.AllowedMentions.Nothing).ConfigureAwait(false); } finally { diff --git a/CompatBot/EventHandlers/EmpathySimulationHandler.cs b/CompatBot/EventHandlers/EmpathySimulationHandler.cs index 18cad255..0c120a89 100644 --- a/CompatBot/EventHandlers/EmpathySimulationHandler.cs +++ b/CompatBot/EventHandlers/EmpathySimulationHandler.cs @@ -57,7 +57,7 @@ namespace CompatBot.EventHandlers { Throttling.Set(args.Channel.Id, similarList, ThrottleDuration); var msgContent = GetAvgContent(similarList.Select(m => m.Content).ToList()); - var botMsg = await args.Channel.SendMessageAsync(msgContent, mentions: Config.AllowedMentions).ConfigureAwait(false); + var botMsg = await args.Channel.SendMessageAsync(msgContent, mentions: Config.AllowedMentions.UsersOnly).ConfigureAwait(false); similarList.Add(botMsg); } else diff --git a/CompatBot/Utils/Extensions/DiscordClientExtensions.cs b/CompatBot/Utils/Extensions/DiscordClientExtensions.cs index e2b80c62..0cbcb9b2 100644 --- a/CompatBot/Utils/Extensions/DiscordClientExtensions.cs +++ b/CompatBot/Utils/Extensions/DiscordClientExtensions.cs @@ -125,9 +125,9 @@ namespace CompatBot.Utils try { if (conents?.Count > 0) - return await logChannel.SendMultipleFilesAsync(conents, embed: embedBuilder.Build()).ConfigureAwait(false); + return await logChannel.SendMultipleFilesAsync(conents, embed: embedBuilder.Build(), mentions: Config.AllowedMentions.Nothing).ConfigureAwait(false); else - return await logChannel.SendMessageAsync(embed: embedBuilder.Build()).ConfigureAwait(false); + return await logChannel.SendMessageAsync(embed: embedBuilder.Build(), mentions: Config.AllowedMentions.Nothing).ConfigureAwait(false); } finally { @@ -146,7 +146,7 @@ namespace CompatBot.Utils var mentions = reporters.Select(GetMentionWithNickname); embedBuilder.AddField("Reporters", string.Join(Environment.NewLine, mentions)); var logChannel = await getLogChannelTask.ConfigureAwait(false); - return await logChannel.SendMessageAsync(embed: embedBuilder.Build()).ConfigureAwait(false); + return await logChannel.SendMessageAsync(embed: embedBuilder.Build(), mentions: Config.AllowedMentions.Nothing).ConfigureAwait(false); } public static async Task ReportAsync(this DiscordClient client, string infraction, string description, ICollection potentialVictims, ReportSeverity severity) @@ -160,7 +160,7 @@ namespace CompatBot.Utils if (potentialVictims?.Count > 0) result.AddField("Potential Targets", string.Join(Environment.NewLine, potentialVictims.Select(GetMentionWithNickname)).Trim(EmbedPager.MaxFieldLength)); var logChannel = await client.GetChannelAsync(Config.BotLogId).ConfigureAwait(false); - return await logChannel.SendMessageAsync(embed: result.Build()).ConfigureAwait(false); + return await logChannel.SendMessageAsync(embed: result.Build(), mentions: Config.AllowedMentions.Nothing).ConfigureAwait(false); } public static string GetMentionWithNickname(this DiscordMember member) diff --git a/CompatBot/Utils/ResultFormatters/LogParserResultFormatter.GeneralNotesSection.cs b/CompatBot/Utils/ResultFormatters/LogParserResultFormatter.GeneralNotesSection.cs index d5c12bfd..cf71ecd3 100644 --- a/CompatBot/Utils/ResultFormatters/LogParserResultFormatter.GeneralNotesSection.cs +++ b/CompatBot/Utils/ResultFormatters/LogParserResultFormatter.GeneralNotesSection.cs @@ -550,7 +550,7 @@ namespace CompatBot.Utils.ResultFormatters { var patchNames = items["patch_desc"]; if (patchNames.Any()) - builder.AddField("Applied Game Patches", string.Join(", ", patchNames)); + builder.AddField("Applied Game Patch" + (patchNames.Length == 1 ? "" : "es"), string.Join(", ", patchNames)); } private static void BuildMissingLicensesSection(DiscordEmbedBuilder builder, string serial, NameUniqueObjectCollection items, List generalNotes) {