Skip to content

Commit

Permalink
- Bot now check if mod from log is deprecated
Browse files Browse the repository at this point in the history
- Update VersionMismatch text
  • Loading branch information
xiaoxiao921 committed Aug 23, 2020
1 parent 5d83d76 commit fa3e322
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions CHEF/Components/Watcher/CommonIssues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ public class CommonIssues : Component
"or\n" +
@"`C:\Users\< UserName >\AppData\Local\Temp\Hopoo Games, LLC\Risk of Rain 2\output_log.txt`";

public const string VersionMismatch =
public const string VersionMismatch =
"If you are struggling playing with people in private lobbies:\n" +
"If you are using Steam Build ID mod or UnmoddedClients and that everyone have the mods, remove them.\n" +
"You don't need any kind of id build spoofing if everyone have the same modding setup.\n" +
"If you want to play with people that have the mods but also with people who doesnt. Proceed as follow :\n" +
"Open the in-game console and type this : `build_id_steam`, then invite people who are unmodded.\n" +
"Then, do the same with modded people, by typing : `build_id_mod`";
"You don't need any kind of id build spoofing if everyone have the same modding setup.\n";

public CommonIssues(DiscordSocketClient client) : base(client)
{
Expand Down Expand Up @@ -87,6 +84,7 @@ public static async Task<bool> CheckModsVersion(string text, StringBuilder answe
if (text.Contains("loading [", StringComparison.InvariantCultureIgnoreCase))
{
var outdatedMods = new StringBuilder();
var deprecatedMods = new StringBuilder();

const string regexFindVer = "Loading \\[(.*?) ([0-9].*?)]";
var rx = new Regex(regexFindVer,
Expand All @@ -108,24 +106,37 @@ public static async Task<bool> CheckModsVersion(string text, StringBuilder answe
if (modName.ToLower().Contains("r2api") ||
modName.ToLower().Contains("bepin"))
{
var latestVer = await IsThisLatestModVersion(modName, verFromText);
if (latestVer != null)
var (latestVer, isDeprecated) = await IsThisLatestModVersion(modName, verFromText);
if (latestVer != null && !isDeprecated)
{
outdatedMods.AppendLine($"{modName} v{verFromText} instead of v{latestVer}");
}
else if (isDeprecated)
{
deprecatedMods.AppendLine($"{modName}");
}
}
}
}

if (outdatedMods.Length > 0)
{
var outdatedModsS = outdatedMods.ToString();
var plural = outdatedModsS.Contains('\n');
answer.AppendLine(
$"{author.Mention}, looks like you don't have the latest version installed of " +
$"the following mod{(outdatedModsS.Contains('\n') ? "s" : "")} :" + Environment.NewLine +
$"the following mod{(plural ? "s" : "")} :" + Environment.NewLine +
outdatedModsS);
}

return true;
if (deprecatedMods.Length > 0)
{
var deprecatedModsS = deprecatedMods.ToString();
var plural = deprecatedModsS.Contains('\n');
answer.AppendLine(
$"{author.Mention}, looks like you have {(plural ? "a" : "")} deprecated " +
$"mod{(plural ? "s" : "")} installed. Deprecated mods usually don't work :" + Environment.NewLine +
deprecatedModsS);
}

return false;
Expand All @@ -136,22 +147,28 @@ public static async Task<bool> CheckModsVersion(string text, StringBuilder answe
}

/// <summary>
/// Check for the <paramref name="modName"/> if <paramref name="otherVer"/> is the latest version.<para/>
/// Returns the latest version as a string, null if <paramref name="otherVer"/> is the latest.
/// Check for the <paramref name="modName"/> if <paramref name="verFromText"/> is the latest version.<para/>
/// Returns the latest version as a string, null if <paramref name="verFromText"/> is the latest.
/// Second Tuple value is true if mod is deprecated.
/// </summary>
/// <param name="modName">Name of the mod to check</param>
/// <param name="otherVer">Text that should be equal to the mod version, outdated or not.</param>
/// <param name="verFromText">Text that should be equal to the mod version, outdated or not.</param>
/// <returns></returns>
private static async Task<string> IsThisLatestModVersion(string modName, string otherVer)
private static async Task<(string, bool)> IsThisLatestModVersion(string modName, string verFromText)
{
var modInfo = await Thunderstore.GetModInfoV1(modName);
if (modInfo != null)
{
if (modInfo.IsDeprecated)
{
return (null, true);
}

var latestVer = modInfo.LatestPackage().VersionNumber;
return !latestVer.Equals(otherVer) ? latestVer : null;
return !latestVer.Equals(verFromText) ? (latestVer, false) : (null, false);
}

return null;
return (null, false);
}
}
}

0 comments on commit fa3e322

Please sign in to comment.