Skip to content

Commit

Permalink
Watcher now check for common log errors
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiao921 committed Jun 24, 2020
1 parent dd2d5a8 commit 50f4a8d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 28 deletions.
11 changes: 3 additions & 8 deletions CHEF/Components/Watcher/AutoPastebin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
71 changes: 60 additions & 11 deletions CHEF/Components/Watcher/CommonIssues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 :" +
Expand All @@ -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;
}

/// <summary>
/// Check if the <paramref name="text"/> contains version numbers of mods, if so,<para/>
/// check if their version number in the text is the latest by querying the thunderstore api.<para/>
/// Returns the latest version in the first string if <paramref name="text"/> doesn't already contains the latest version.<para/>
/// Second string is the version that is in the text.<para/>
/// Both strings are null if <paramref name="text"/> doesn't contains any mod version.
/// Check if the <paramref name="text"/> contains version numbers of mods<para/>
/// Returns true if the text contains any outdated mods
/// </summary>
/// <param name="text">Text that may or may not contains mod version numbers.</param>
/// /// <param name="text">Text that may or may not contains mod version numbers</param>
/// <param name="answer">StringBuilder that will contains the bot answer ready to be sent</param>
/// /// <param name="author">User that we are answering to</param>
/// <returns></returns>
public static async Task<string> CheckModsVersion(string text)
public static async Task<bool> CheckModsVersion(string text, StringBuilder answer, SocketUser author)
{
if (text != null)
{
Expand All @@ -60,22 +98,33 @@ public static async Task<string> 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;
}

/// <summary>
Expand Down
16 changes: 7 additions & 9 deletions CHEF/Components/Watcher/ImageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
Expand Down

0 comments on commit 50f4a8d

Please sign in to comment.