private async Task HandleMessageBest(string searchString, SocketUserMessage message) { int raritySearch = 0; if (searchString.IndexOf("-s") > 4) { var paramStart = searchString.IndexOf("-s"); var paramValue = searchString.Substring(paramStart + 2); searchString = searchString.Substring(0, paramStart).Trim(); if (int.TryParse(paramValue.Trim(), out int pv)) { raritySearch = pv; } } var results = _botHelper.BestCrew(searchString, raritySearch); if ((results == null) || (results.Count == 0)) { await message.Channel.SendMessageAsync($"Sorry, I couldn't run command 'best {searchString}'; try **-d best base <skill>** - check **-d help** for details"); } else { string reply = $"Here's what I found for '{searchString}':\n"; reply += string.Join("\n", results.Take(10).Select(crew => (new string('тнР', crew.max_rarity) + $" {crew.name} - " + FormatCrewStatsWithEmotes(message, crew)))); await message.Channel.SendMessageAsync(reply); } }
static int PerformTest(Test opts) { if (opts.TestType == 0) { var voyImage = new VoyImage(System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "..", "..")); VoyImageResult result; if (opts.TestString.StartsWith("http")) { result = voyImage.SearchUrl(opts.TestString); } else { result = voyImage.SearchImage(opts.TestString); } Console.WriteLine(result); } else if (opts.TestType == 1) { var botHelper = new BotHelper("https://datacore.app/", System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "..", "..", "data")); botHelper.ParseData(); var result = botHelper.BestCrew(opts.TestString, 0); if (result.Count == 0) { Console.WriteLine("Not found"); } else { Console.WriteLine(result[0].name); } } else if (opts.TestType == 2) { var botHelper = new BotHelper("https://datacore.app/", System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "..", "..", "data")); botHelper.ParseData(); var result = botHelper.Gauntlet(opts.TestString.Split(' ')); if (!string.IsNullOrEmpty(result.ErrorMessage) || result.Results.Count() == 0) { Console.WriteLine("Not found"); } else { Console.WriteLine(string.Join(", ", result.Results.Select(gresult => $"{gresult.Crew.name} [{string.Join(", ", gresult.MatchingTraits)}]"))); } } return(0); }
public void TestBotHelper() { var botHelper = new BotHelper("https://datacore.netlify.com/", Path.Combine(Directory.GetCurrentDirectory(), "../../../../..")); botHelper.ParseData(); Assert.AreNotEqual(0, botHelper.TotalCrew()); var crewResults = botHelper.SearchCrew("data"); Assert.AreNotEqual(0, crewResults.Count); crewResults = botHelper.SearchCrew("skywalker"); Assert.AreEqual(0, crewResults.Count); var itemResults = botHelper.SearchItem("combadge"); Assert.AreNotEqual(0, itemResults.Count); itemResults = botHelper.SearchItem("lightsaber"); Assert.AreEqual(0, itemResults.Count); var dilemmaResults = botHelper.SearchDilemmas("Champion"); Assert.AreNotEqual(0, dilemmaResults.Count); dilemmaResults = botHelper.SearchDilemmas("Jedi"); Assert.AreEqual(0, dilemmaResults.Count); var crew = botHelper.GetCrew("jedi_master"); Assert.AreEqual(null, crew); crew = botHelper.GetCrew("data_detective_crew"); Assert.AreNotEqual(null, crew); Assert.AreEqual("Detective Data", crew.name); Assert.AreNotEqual(null, crew.base_skills.engineering_skill); Assert.AreEqual(null, crew.base_skills.medicine_skill); Assert.IsTrue(crew.skill_data[0].base_skills.engineering_skill.core < crew.skill_data[1].base_skills.engineering_skill.core); Assert.AreNotEqual(0, crew.totalChronCost); var bestCrewResults = botHelper.BestCrew("base cmd", 0); Assert.AreNotEqual(0, bestCrewResults.Count); bestCrewResults = botHelper.BestCrew("gauntlet cmd", 0); Assert.AreNotEqual(0, bestCrewResults.Count); bestCrewResults = botHelper.BestCrew("gauntlet cmd sci", 0); Assert.AreNotEqual(0, bestCrewResults.Count); bestCrewResults = botHelper.BestCrew("voyage cmd", 0); Assert.AreNotEqual(0, bestCrewResults.Count); bestCrewResults = botHelper.BestCrew("voyage cmd sci", 0); Assert.AreNotEqual(0, bestCrewResults.Count); bestCrewResults = botHelper.BestCrew("bases cmd", 0); Assert.AreEqual(null, bestCrewResults); bestCrewResults = botHelper.BestCrew("voyage cmd sci sec", 0); Assert.AreEqual(null, bestCrewResults); var gauntletCrew = botHelper.Gauntlet(new string[] { "borg", "interrogator", "resourceful" }); Assert.AreNotEqual(0, gauntletCrew.Results.Length); gauntletCrew = botHelper.Gauntlet(new string[] { "jedi", "invalid", "bogus" }); Assert.IsFalse(string.IsNullOrEmpty(gauntletCrew.ErrorMessage)); }