From 50f4a8d67c8ab9acc9ef0be56dc0b31a92bea4a8 Mon Sep 17 00:00:00 2001 From: Death Date: Wed, 24 Jun 2020 10:02:26 +0200 Subject: [PATCH] Watcher now check for common log errors --- CHEF/Components/Watcher/AutoPastebin.cs | 11 ++-- CHEF/Components/Watcher/CommonIssues.cs | 71 +++++++++++++++++++++---- CHEF/Components/Watcher/ImageParser.cs | 16 +++--- 3 files changed, 70 insertions(+), 28 deletions(-) diff --git a/CHEF/Components/Watcher/AutoPastebin.cs b/CHEF/Components/Watcher/AutoPastebin.cs index 545531b..22edd6f 100644 --- a/CHEF/Components/Watcher/AutoPastebin.cs +++ b/CHEF/Components/Watcher/AutoPastebin.cs @@ -40,14 +40,9 @@ msg.Channel is SocketTextChannel && var fileContent = await HttpClient.GetStringAsync(attachment.Url); var botAnswer = new StringBuilder(); - var outdatedMods = await CommonIssues.CheckModsVersion(fileContent); - if (outdatedMods != null) - { - botAnswer.AppendLine( - $"{msg.Author.Mention}, looks like you don't have the latest version installed of " + - $"the following mod{(outdatedMods.Contains('\n') ? "s" : "")} :" + Environment.NewLine + - outdatedMods); - } + CommonIssues.CheckCommonLogError(fileContent, botAnswer, msg.Author); + + await CommonIssues.CheckModsVersion(fileContent, botAnswer, msg.Author); var pasteResult = await PostBin(fileContent); diff --git a/CHEF/Components/Watcher/CommonIssues.cs b/CHEF/Components/Watcher/CommonIssues.cs index 8b2852d..3b42354 100644 --- a/CHEF/Components/Watcher/CommonIssues.cs +++ b/CHEF/Components/Watcher/CommonIssues.cs @@ -9,6 +9,23 @@ namespace CHEF.Components.Watcher { public class CommonIssues : Component { + public const string DuplicateAssemblyError = + "You seems to have `Tried to load duplicate assembly...` error message." + + "When that happens, you should delete your " + + @"Risk of Rain 2\Risk of Rain 2_Data\Managed folder " + + "and verify the integrity of the game files\n" + + "http://steamcdn-a.akamaihd.net/steam/support/faq/verifygcf2.gif"; + + public const string R2APIMonoModPatchError = + "You seems to have `The Monomod patch of R2API seems to be missing` error message." + + "When that happens, it either means that : \n" + + "You are missing the .dll file like the message is saying,\n" + + "or\n" + + "You are missing the monomod loader that is normally located in the " + + @"`Risk of Rain 2\BepInEx\patchers\BepInEx.MonoMod.Loader` folder.\n" + + "If you don't have this folder, please download BepInEx again from " + + "the thunderstore and make sure to follow the installation instructions."; + public const string CrashLogLocation = "You also mentioned the word `crash` in your message.\n" + "Here is the file path for a log file that could be more useful to us :" + @@ -33,16 +50,37 @@ public override Task SetupAsync() return Task.CompletedTask; } + public static bool CheckCommonLogError(string text, StringBuilder answer, SocketUser author) + { + var hasCommonError = false; + + if (text != null) + { + if (text.Contains("Tried to load duplicate", StringComparison.InvariantCultureIgnoreCase)) + { + answer.AppendLine(DuplicateAssemblyError); + hasCommonError = true; + } + + if (text.Contains("The Monomod patch of", StringComparison.InvariantCultureIgnoreCase)) + { + answer.AppendLine(R2APIMonoModPatchError); + hasCommonError = true; + } + } + + return hasCommonError; + } + /// - /// Check if the contains version numbers of mods, if so, - /// check if their version number in the text is the latest by querying the thunderstore api. - /// Returns the latest version in the first string if doesn't already contains the latest version. - /// Second string is the version that is in the text. - /// Both strings are null if doesn't contains any mod version. + /// Check if the contains version numbers of mods + /// Returns true if the text contains any outdated mods /// - /// Text that may or may not contains mod version numbers. + /// /// Text that may or may not contains mod version numbers + /// StringBuilder that will contains the bot answer ready to be sent + /// /// User that we are answering to /// - public static async Task CheckModsVersion(string text) + public static async Task CheckModsVersion(string text, StringBuilder answer, SocketUser author) { if (text != null) { @@ -60,22 +98,33 @@ public static async Task CheckModsVersion(string text) if (match.Groups.Count > 2) { var modName = match.Groups[1].ToString(); - var verFromText = match.Groups[2].ToString(); + var verFromText = match.Groups[2].ToString().Replace(" ", ""); Logger.Log("modName : " + modName); Logger.Log("verFromText : " + verFromText); var latestVer = await IsThisLatestModVersion(modName, verFromText); if (latestVer != null) { - outdatedMods.AppendLine($"{modName} v{verFromText} instead of {latestVer}"); + outdatedMods.AppendLine($"{modName} v{verFromText} instead of v{latestVer}"); } } } - return outdatedMods.Length > 0 ? outdatedMods.ToString() : null; + if (outdatedMods.Length > 0) + { + var outdatedModsS = outdatedMods.ToString(); + answer.AppendLine( + $"{author.Mention}, looks like you don't have the latest version installed of " + + $"the following mod{(outdatedModsS.Contains('\n') ? "s" : "")} :" + Environment.NewLine + + outdatedModsS); + + return true; + } + + return false; } } - return null; + return false; } /// diff --git a/CHEF/Components/Watcher/ImageParser.cs b/CHEF/Components/Watcher/ImageParser.cs index da28aa3..32a49c4 100644 --- a/CHEF/Components/Watcher/ImageParser.cs +++ b/CHEF/Components/Watcher/ImageParser.cs @@ -42,16 +42,14 @@ msg.Channel is SocketTextChannel && var botAnswer = new StringBuilder(); var queryResult = await QueryYandex(attachment.Url); + Logger.Log("Checking for common log errors."); + CommonIssues.CheckCommonLogError(queryResult.ImageText, botAnswer, msg.Author); + Logger.Log("Checking for outdated mods."); - var outdatedMods = await CommonIssues.CheckModsVersion(queryResult.ImageText); - if (outdatedMods != null) + var hasOutdatedMods = await CommonIssues.CheckModsVersion(queryResult.ImageText, botAnswer, msg.Author); + if (hasOutdatedMods) { - botAnswer.AppendLine( - $"{msg.Author.Mention}, looks like you don't have the latest version installed of " + - $"the following mod{(outdatedMods.Contains('\n') ? "s" : "")} :" + Environment.NewLine + - outdatedMods); - - // Found mods, so its probably a console log that is screenshoted, lets add a tag so its for sure recognized + // Found mods, so its probably a console log that is screenshot, lets add a tag so its for sure recognized // Todo: handle tags better directly queryResult.HasModLoadingText = true; } @@ -61,7 +59,7 @@ msg.Channel is SocketTextChannel && queryResult.ImageText.Contains("Yours=MOD", StringComparison.InvariantCultureIgnoreCase)) { botAnswer.AppendLine($"{msg.Author.Mention}, looks like you just uploaded a screenshot of a lobby game version mismatch."); - botAnswer.AppendLine(CommonIssues.VersionMismatch); + botAnswer.AppendLine(CommonIssues.VersionMismatch); botAnswer.AppendLine("If the issue is something else, just wait for help."); return botAnswer.ToString();