From 64a02811d36c4e99cdb019e8e8ce4de478fc0cc3 Mon Sep 17 00:00:00 2001 From: xiaoxiao921 Date: Wed, 10 Aug 2022 11:28:24 +0200 Subject: [PATCH] cleaner looking bot message for outdated mods check --- CHEF/Components/Watcher/CommonIssues.cs | 54 +++++++++++++------------ 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/CHEF/Components/Watcher/CommonIssues.cs b/CHEF/Components/Watcher/CommonIssues.cs index a195155..ac317ac 100644 --- a/CHEF/Components/Watcher/CommonIssues.cs +++ b/CHEF/Components/Watcher/CommonIssues.cs @@ -75,13 +75,13 @@ public static async Task CheckForOutdatedAndDeprecatedMods(string text, St RegexOptions.Compiled | RegexOptions.IgnoreCase); var matches = rx.Matches(text); + var outdatedMods = new StringBuilder(); + var deprecatedMods = new StringBuilder(); + foreach (Match match in matches) { if (match.Groups.Count > 2) { - var outdatedMods = new StringBuilder(); - var deprecatedMods = new StringBuilder(); - // A log line is like this : // TS Manifest: Random-Team-Name-ModName-1.0.0 @@ -99,32 +99,34 @@ public static async Task CheckForOutdatedAndDeprecatedMods(string text, St { deprecatedMods.AppendLine($"{modName}"); } + } - if (outdatedMods.Length > 0) - { - var outdatedModsS = outdatedMods.ToString(); - var plural = outdatedModsS.Count(c => c == '\n') > 1; - answer.AppendLine( - $"{author.Mention}, you don't have the latest version installed of " + - $"the following mod{(plural ? "s" : "")}:" + Environment.NewLine + - outdatedModsS); - - textContainsAnyBadMod = true; - } + } - if (deprecatedMods.Length > 0) - { - var deprecatedModsS = deprecatedMods.ToString(); - var plural = deprecatedModsS.Count(c => c == '\n') > 1; - answer.AppendLine( - $"{author.Mention}, you have {(plural ? "" : "a")} deprecated " + - $"mod{(plural ? "s" : "")} installed. Deprecated mods usually don't work:" + Environment.NewLine + - deprecatedModsS); - - textContainsAnyBadMod = true; - } - } + var notMentionedYet = true; + if (outdatedMods.Length > 0) + { + var outdatedModsS = outdatedMods.ToString(); + var plural = outdatedModsS.Count(c => c == '\n') > 1; + answer.AppendLine( + $"{(notMentionedYet ? author.Mention + " y" : "Y")}ou don't have the latest version installed of " + + $"the following mod{(plural ? "s" : "")}:" + Environment.NewLine + + outdatedModsS); + + textContainsAnyBadMod = true; + notMentionedYet = false; + } + if (deprecatedMods.Length > 0) + { + var deprecatedModsS = deprecatedMods.ToString(); + var plural = deprecatedModsS.Count(c => c == '\n') > 1; + answer.AppendLine( + $"{(notMentionedYet ? author.Mention + " y" : "Y")}ou have {(plural ? "" : "a")} deprecated " + + $"mod{(plural ? "s" : "")} installed. Deprecated mods usually don't work:" + Environment.NewLine + + deprecatedModsS); + + textContainsAnyBadMod = true; } } }