示例#1
0
        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));
                    }
                }
            }
示例#2
0
        public static async Task SendMessage_SystemInfo(CommandContext context, JSONObject system, JSONObject stations, JSONObject traffic, JSONObject deaths, bool listStations)
        {
            EmbedBuilder      infoembed = new EmbedBuilder();
            List <EmbedField> listembed = new List <EmbedField>();
            bool stationsFound          = false;

            // Gathering Information

            string system_name          = string.Empty;
            string system_name_link     = string.Empty;
            long   system_id            = 0;
            string system_startype      = string.Empty;
            string security             = string.Empty;
            bool   system_requirepermit = false;
            string system_permit        = string.Empty;

            if (system.GetField(ref system_name, "name") && system.GetField(ref system_id, "id"))
            {
                // Gathering General System information
                system_name_link = system_name.Replace(' ', '+');
                JSONObject system_information = system["information"];
                if (!((system_information != null) && system_information.GetField(ref security, "security")))
                {
                    security = "Anarchy (Unpopulated)";
                }
                string     startype    = "Not found";
                JSONObject primaryStar = system["primaryStar"];
                if ((primaryStar != null) && primaryStar.Count > 0)
                {
                    startype = system["primaryStar"]["type"].str;
                    if (!system["primaryStar"]["isScoopable"].b)
                    {
                        startype += " **(Unscoopable)**";
                    }
                }
                system.GetField(out system_requirepermit, "requirePermit", false);
                if (!system.GetField(ref system_permit, "permitName"))
                {
                    system_permit = "Unknown Permit";
                }

                // Gathering information about stations
                StationInfo        bestOrbitalLarge  = null;
                StationInfo        bestOrbitalMedium = null;
                StationInfo        bestPlanetary     = null;
                List <StationInfo> stationInfos      = new List <StationInfo>();
                if ((stations != null) && stations.HasField("stations"))
                {
                    stationsFound = true;
                    foreach (JSONObject station in stations["stations"])
                    {
                        JSONObject otherservices    = station["otherServices"];
                        string     station_name     = string.Empty;
                        long       station_id       = 0;
                        string     station_type     = "Unresolved";
                        float      station_distance = float.PositiveInfinity;
                        string     station_gov      = string.Empty;
                        if (station.GetField(ref station_name, "name") && station.GetField(ref station_id, "id"))
                        {
                            station.GetField(ref station_type, "type");
                            station.GetField(ref station_distance, "distanceToArrival");
                            StationInfo info = new StationInfo(station_name, station_id, system_name_link, system_id, station_type, station_distance);
                            if (station.GetField(ref station_gov, "government"))
                            {
                                if (station_gov.Equals("Workshop (Engineer)"))
                                {
                                    info.Type = StationType.EngineerBase;
                                }
                            }
                            station.GetField(ref info.HasShipyard, "haveShipyard");
                            station.GetField(ref info.HasOutfitting, "haveOutfitting");
                            if (otherservices != null)
                            {
                                foreach (JSONObject service in otherservices)
                                {
                                    switch (service.str)
                                    {
                                    case "Restock":
                                        info.HasRestock = true;
                                        break;

                                    case "Repair":
                                        info.HasRepair = true;
                                        break;

                                    case "Refuel":
                                        info.HasRefuel = true;
                                        break;

                                    case "Universal Cartographics":
                                        info.HasUniversalCartographics = true;
                                        break;
                                    }
                                }
                            }
                            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 ((traffic != null) && traffic.HasField("traffic"))
                {
                    traffic["traffic"].GetField(ref traffic_week, "week");
                    traffic["traffic"].GetField(ref traffic_day, "day");
                }

                // Getting Information about CMDR deaths
                int deaths_week = -1;
                int deaths_day  = -1;

                if ((deaths != null) && deaths.HasField("deaths"))
                {
                    deaths["deaths"].GetField(ref deaths_week, "week");
                    deaths["deaths"].GetField(ref deaths_day, "day");
                }

                // Constructing message
                infoembed.Color = Var.BOTCOLOR;
                infoembed.Title = string.Format("__**System Info for {0}**__", system_name);
                infoembed.Url   = string.Format("https://www.edsm.net/en/system/id/{0}/name/{1}", system_id, system_name_link);
                infoembed.AddField("General Info", string.Format("{0}Star Type: {1}\nSecurity: {2}", system_requirepermit ? string.Format("**Requires Permit**: {0}\n", system_permit) : string.Empty, startype, 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)
                {
                    infoembed.AddField("Closest Orbital Large Pad", bestOrbitalLarge.ToString());
                }
                if (provideInfoOnMedium)
                {
                    infoembed.AddField("Closest Orbital Medium Pad", bestOrbitalMedium.ToString());
                }
                if (provideInfoOnPlanetary)
                {
                    infoembed.AddField("Closest Planetary Large Pad", bestPlanetary.ToString());
                }
                if (!provideInfoOnLarge && !provideInfoOnMedium && !provideInfoOnPlanetary)
                {
                    infoembed.AddField("No Stations in this System!", "- / -");
                }
                if (traffic_day != -1 && traffic_week != -1)
                {
                    infoembed.AddField("Traffic Report", string.Format("Last 7 days: {0} CMDRs, last 24 hours: {1} CMDRs", traffic_week, traffic_day));
                }
                else
                {
                    infoembed.AddField("No Traffic Report Available", "- / -");
                }
                if (deaths_day != -1 && deaths_week != -1)
                {
                    infoembed.AddField("CMDR Deaths Report", string.Format("Last 7 days: {0} CMDRs, last 24 hours: {1} CMDRs", deaths_week, deaths_day));
                }
                else
                {
                    infoembed.AddField("No CMDR Deaths Report Available", "- / -");
                }

                if (stationsFound && stationInfos.Count > 0)
                {
                    foreach (StationInfo stationInfo in stationInfos)
                    {
                        listembed.Add(new EmbedField(stationInfo.Title_NoLink, stationInfo.Services_Link));
                    }
                }
            }
            else
            {
                infoembed.Description = string.Format("Could not get name & id from JSON. Here have the source json data: ```json\n{0}```", system.Print(true));
                infoembed.Color       = Var.ERRORCOLOR;
            }

            await context.Channel.SendEmbedAsync(infoembed);

            if (listStations && stationsFound)
            {
                await context.Channel.SendSafeEmbedList("Stations in " + system_name, listembed);
            }
        }