internal string GetPCGWUrl(string GameName) { try { if (JsonGrabber.GrabJson(JsonGrabber.BuildRequestUri(PCGW_API_URI, new string[] { JsonGrabber.FormatParameter("action", "ask"), JsonGrabber.FormatParameter("format", "json"), JsonGrabber.FormatParameter("query", "[[Category:Games]] [[" + GameName + "]]") }), out string result)) { if (result != "") { var response = JObject.Parse(result); if (response["query"] != null) { var queryData = response["query"]; if (queryData["results"] != null) { var resultData = queryData["results"]; if (resultData.Count() > 0) { return(resultData.First.First["fullurl"].ToString()); } else { return("Ask query returned no results. You may want to try: " + string.Format("https://www.pcgamingwiki.com/w/index.php?search={0}", Uri.EscapeDataString(GameName))); } } else { return("Query returned no result node! Something is wrong..."); } } else { return("Query returned with no \"Query\" node in response!"); } } else { return("Response was empty!"); } } else { return("Failed to get response from PCGW."); } } catch (Exception e) { ErrorLogging.WriteLine("[ERROR WITH PCGW REQUEST] - " + e.Message); return("Exception thrown when trying to query PCGW. See log file."); } }
public static void GetRaces(SuiBot_ChannelInstance ChannelInstance) { try { if (JsonGrabber.GrabJson(GetUri("races"), out string response)) { string[] twitches = GetEntrantsTwitches(response, ChannelInstance.Channel); if (twitches != null) { ChannelInstance.SendChatMessage("http://kadgar.net/live/" + string.Join("/", twitches)); } else { ChannelInstance.SendChatMessage("Nothing found"); } } } catch { ChannelInstance.SendChatMessage("Some kind of error. Go, poke Sui to fix that"); } }