protected override async Task Execute(IDMCommandContext context) { string radiusRequest = WebRequestService.EDSM_MultipleSystemsRadius(SystemName, 50); RequestJSONResult requestResultRadius = await WebRequestService.GetWebJSONAsync(radiusRequest); if (!requestResultRadius.IsSuccess) { if (requestResultRadius.IsException) { await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. Exception Message: `{0}`", requestResultRadius.ThrownException.Message), true); } else { await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. HTTP Error: `{0} {1}`", (int)requestResultRadius.Status, requestResultRadius.Status.ToString()), true); } return; } if (requestResultRadius.JSON.IsObject) { await context.Channel.SendEmbedAsync("System not found in database!", true); return; } Dictionary <string, System> systemInfos = GetNames(requestResultRadius.JSON); List <System> allSystems = new List <System>(systemInfos.Values); foreach (System system in allSystems) { system.SetETTA(JumpRange); } allSystems.Sort(new SystemComparer() { RawDistance = true }); const int requestCnt = 20; System[] requestSystems = new System[requestCnt]; allSystems.CopyTo(0, requestSystems, 0, requestCnt); string infoRequest = WebRequestService.EDSM_MultipleSystemsInfo_URL(requestSystems.Select(system => { return(system.Name); }), true, true, true, true); RequestJSONResult requestResultInfo = await WebRequestService.GetWebJSONAsync(infoRequest); if (!requestResultInfo.IsSuccess) { if (requestResultInfo.IsException) { await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. Exception Message: `{0}`", requestResultInfo.ThrownException.Message), true); } else { await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. HTTP Error: `{0} {1}`", (int)requestResultInfo.Status, requestResultInfo.Status.ToString()), true); } return; } System targetSystem = default; if (requestResultInfo.JSON.IsArray) { foreach (JSONField systemField in requestResultInfo.JSON.Array) { if (systemField.IsObject) { if (systemField.Container.TryGetField("name", out string name)) { if (systemInfos.TryGetValue(name, out System system)) { system.FromJSON(systemField.Container); if (system.Distance == 0) { targetSystem = system; } } } } } } if (targetSystem.Name == null) { await context.Channel.SendEmbedAsync(string.Format("Internal Error! " + Macros.GetCodeLocation(), true)); return; } string hideFaction = Mode == CommandMode.Crime ? targetSystem.Name : null; List <System> validSystems = new List <System>(); foreach (System system in requestSystems) { if (await system.GetBestStation()) { system.SetETTA(JumpRange); validSystems.Add(system); } } validSystems.Sort(new SystemComparer()); EmbedBuilder embed = new EmbedBuilder() { Author = new EmbedAuthorBuilder() { Url = targetSystem.GetEDSM_URL(), Name = $"Suggestions for a temporary base near {targetSystem.Name}" }, Color = BotCore.EmbedColor }; for (int i = 0; i < 5 && i < validSystems.Count; i++) { System system = validSystems[i]; embed.AddField($"\"{system.Name}\" - \"{system.BestStation.Name}\"", $"{(system.RequirePermit ? $"{UnicodeEmoteService.Warning} Permit: `{system.PermitName}` " : string.Empty)} {system.BestStation.Services_Link}"); } await context.Channel.SendEmbedAsync(embed); }