Esempio n. 1
0
        protected override async Task Execute(IDMCommandContext context)
        {
            string requestSystem   = WebRequestService.EDSM_SystemInfo_URL(systemName, true, true, true, true, true);
            string requestStations = WebRequestService.EDSM_SystemStations_URL(systemName);
            string requestTraffic  = WebRequestService.EDSM_SystemTraffic_URL(systemName);
            string requestDeaths   = WebRequestService.EDSM_SystemDeaths_URL(systemName);

            if (webRequests)
            {
                EmbedBuilder embed = new EmbedBuilder()
                {
                    Title       = "Webrequests",
                    Color       = BotCore.EmbedColor,
                    Description = $"[System]({requestSystem}) `{requestSystem}`\n[Stations]({requestStations}) `{requestStations}`\n[Traffic]({requestTraffic}) `{requestTraffic}`\n[Deaths]({requestDeaths}) `{requestDeaths}`"
                };
                await context.Channel.SendEmbedAsync(embed);
            }
            RequestJSONResult requestResultSystem = await WebRequestService.GetWebJSONAsync(requestSystem);

            RequestJSONResult requestResultStations = await WebRequestService.GetWebJSONAsync(requestStations);

            RequestJSONResult requestResultTraffic = await WebRequestService.GetWebJSONAsync(requestTraffic);

            RequestJSONResult requestResultDeaths = await WebRequestService.GetWebJSONAsync(requestDeaths);

            if (requestResultSystem.IsSuccess)
            {
                if (requestResultSystem.JSON.IsArray && requestResultSystem.JSON.Array.Count < 1)
                {
                    await context.Channel.SendEmbedAsync("System not found in database!", true);
                }
                else
                {
                    if (printJson)
                    {
                        await context.Channel.SendEmbedAsync("General System Info", string.Format("```json\n{0}```", requestResultSystem.JSON.Build(true).MaxLength(2037)));

                        await context.Channel.SendEmbedAsync("Station Info", string.Format("```json\n{0}```", requestResultStations.JSON.Build(true).MaxLength(2037)));
                    }
                    EmbedBuilder systemEmbed = GetSystemInfoEmbed(requestResultSystem.JSON, requestResultStations.JSON, requestResultTraffic.JSON, requestResultDeaths.JSON, out List <EmbedFieldBuilder> allStations);
                    await context.Channel.SendEmbedAsync(systemEmbed);
                }
            }
            else if (requestResultSystem.IsException)
            {
                await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. Exception Message: `{0}`", requestResultSystem.ThrownException.Message), true);
            }
            else
            {
                await context.Channel.SendEmbedAsync(string.Format("Could not connect to EDSMs services. HTTP Error: `{0} {1}`", (int)requestResultSystem.Status, requestResultSystem.Status.ToString()), true);
            }
        }
Esempio n. 2
0
            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);
            }