public async Task <bool> GetBestStation(string hideMinorFaction = null) { string request = WebRequestService.EDSM_SystemStations_URL(Name); RequestJSONResult result = await WebRequestService.GetWebJSONAsync(request); if (result.IsSuccess) { // Setup Stations if ((result.JSON != null) && result.JSON.TryGetArrayField("stations", out JSONContainer stationsJSON)) { foreach (JSONField stationField in stationsJSON.Array) { if (stationField.IsObject) { StationInfo info = new StationInfo(); if (info.FromJSON(stationField.Container)) { if (string.IsNullOrEmpty(hideMinorFaction) || info.ControllingFaction != hideMinorFaction) { if (BestStation == null) { BestStation = info; } else if (info.IsBetterThan(BestStation)) { BestStation = info; } } } } } return(true); } } return(false); }
private EmbedBuilder GetSystemInfoEmbed(JSONContainer systemJSON, JSONContainer stationsJSON, JSONContainer trafficJSON, JSONContainer deathsJSON, out List <EmbedFieldBuilder> allStations) { EmbedBuilder systemembed = new EmbedBuilder(); allStations = new List <EmbedFieldBuilder>(); bool stationsFound = false; if (systemJSON.TryGetField("name", out string system_name, string.Empty) && systemJSON.TryGetField("id", out ulong system_id, 0)) { // Gathering Information // Gathering General System information string system_name_link = system_name.Replace(' ', '+'); string security = "Unknown"; if (systemJSON.TryGetObjectField("information", out JSONContainer system_information)) { system_information.TryGetField("security", out security, "Anarchy (Unpopulated)"); } string startype = "Not found"; if (systemJSON.TryGetObjectField("primaryStar", out JSONContainer primaryStar)) { primaryStar.TryGetField("type", out startype, startype); if (systemJSON.TryGetField("isScoopable", out bool scoopable)) { if (!scoopable) { startype += " **(Unscoopable)**"; } } } systemJSON.TryGetField("requirePermit", out bool system_requirepermit, false); systemJSON.TryGetField("permitName", out string system_permit, "Unknown Permit"); // Gathering information about stations StationInfo bestOrbitalLarge = null; StationInfo bestOrbitalMedium = null; StationInfo bestPlanetary = null; List <StationInfo> stationInfos = new List <StationInfo>(); if ((stationsJSON != null) && stationsJSON.TryGetArrayField("stations", out stationsJSON)) { stationsFound = true; foreach (JSONField station in stationsJSON.Array) { StationInfo info = new StationInfo(); if (info.FromJSON(station.Container)) { stationInfos.Add(info); if (info.HasLargePadOrbital) { if (bestOrbitalLarge == null) { bestOrbitalLarge = info; } else if (info.Distance < bestOrbitalLarge.Distance) { bestOrbitalLarge = info; } } if (info.HasMedPadOrbital) { if (bestOrbitalMedium == null) { bestOrbitalMedium = info; } else if (info.Distance < bestOrbitalMedium.Distance) { bestOrbitalMedium = info; } } if (info.IsPlanetary) { if (bestPlanetary == null) { bestPlanetary = info; } else if (info.Distance < bestPlanetary.Distance) { bestPlanetary = info; } } } } } // Getting Information about traffic int traffic_week = -1; int traffic_day = -1; if ((trafficJSON != null) && trafficJSON.TryGetObjectField("traffic", out trafficJSON)) { trafficJSON.TryGetField("week", out traffic_week, -1); trafficJSON.TryGetField("day", out traffic_day, -1); } // Getting Information about CMDR deaths int deaths_week = -1; int deaths_day = -1; if ((deathsJSON != null) && deathsJSON.TryGetObjectField("deaths", out deathsJSON)) { deathsJSON.TryGetField("week", out deaths_week, -1); deathsJSON.TryGetField("day", out deaths_day, -1); } // Constructing message systemembed.Color = BotCore.EmbedColor; systemembed.Title = $"__**System Info for {system_name}**__"; systemembed.Url = $"https://www.edsm.net/en/system/id/{system_id}/name/{system_name_link}"; systemembed.AddField("General Info", $"{(system_requirepermit ? string.Format("**Requires Permit**: {0}\n", system_permit) : string.Empty)}Star Type: {startype}\nSecurity: {security}"); bool provideInfoOnLarge = bestOrbitalLarge != null; bool provideInfoOnMedium = (!provideInfoOnLarge && bestOrbitalMedium != null) || (provideInfoOnLarge && bestOrbitalMedium != null && bestOrbitalLarge.Distance > bestOrbitalMedium.Distance); bool provideInfoOnPlanetary = (!provideInfoOnLarge && bestPlanetary != null) || (provideInfoOnLarge && bestPlanetary != null && bestOrbitalLarge.Distance > bestPlanetary.Distance); if (provideInfoOnLarge) { systemembed.AddField("Closest Orbital Large Pad", bestOrbitalLarge.ToString()); } if (provideInfoOnMedium) { systemembed.AddField("Closest Orbital Medium Pad", bestOrbitalMedium.ToString()); } if (provideInfoOnPlanetary) { systemembed.AddField("Closest Planetary Large Pad", bestPlanetary.ToString()); } if (!provideInfoOnLarge && !provideInfoOnMedium && !provideInfoOnPlanetary) { systemembed.AddField("No Stations in this System!", "- / -"); } if (traffic_day != -1 && traffic_week != -1) { systemembed.AddField("Traffic Report", string.Format("Last 7 days: {0} CMDRs, last 24 hours: {1} CMDRs", traffic_week, traffic_day)); } else { systemembed.AddField("No Traffic Report Available", "- / -"); } if (deaths_day != -1 && deaths_week != -1) { systemembed.AddField("CMDR Deaths Report", string.Format("Last 7 days: {0} CMDRs, last 24 hours: {1} CMDRs", deaths_week, deaths_day)); } else { systemembed.AddField("No CMDR Deaths Report Available", "- / -"); } if (stationsFound) { foreach (StationInfo stationInfo in stationInfos) { allStations.Add(Macros.EmbedField(stationInfo.Title_NoLink, stationInfo.Services_Link)); } } }