Exemplo n.º 1
0
        private async Task <bool> ProcessLocation(long radiusId, JsonZKill.Killmail kill, KillFeedGroup @group, KillMailFilter filter, string groupName)
        {
            var mode      = RadiusMode.Range;
            var isUrlOnly = group.FeedUrlsOnly;
            var radius    = filter.Radius;

            if (radiusId <= 0)
            {
                await LogHelper.LogError("Radius feed must have systemId!", Category);

                return(false);
            }

            var km = new KillDataEntry();
            await km.Refresh(Reason, kill);

            var routeLength = 0;

            JsonClasses.ConstellationData rConst = null;
            JsonClasses.RegionData        rRegion;
            var srcSystem = mode == RadiusMode.Range ? await APIHelper.ESIAPI.GetSystemData(Reason, radiusId) : null;

            if (radiusId == km.systemId)
            {
                //right there
                rConst = km.rSystem.constellation_id == 0 ? null : await APIHelper.ESIAPI.GetConstellationData(Reason, km.rSystem.constellation_id);

                rRegion = rConst?.region_id == null || rConst.region_id == 0 ? null : await APIHelper.ESIAPI.GetRegionData(Reason, rConst.region_id);
            }
            else
            {
                switch (mode)
                {
                case RadiusMode.Range:

                    if (radius == 0 || km.isUnreachableSystem || (srcSystem?.IsUnreachable() ?? true))     //Thera WH Abyss
                    {
                        return(false);
                    }

                    var route = await APIHelper.ESIAPI.GetRawRoute(Reason, radiusId, km.systemId);

                    if (string.IsNullOrEmpty(route))
                    {
                        return(false);
                    }
                    JArray data;
                    try
                    {
                        data = JArray.Parse(route);
                    }
                    catch (Exception ex)
                    {
                        await LogHelper.LogEx("Route parse: " + ex.Message, ex, Category);

                        return(false);
                    }

                    routeLength = data.Count - 1;
                    //not in range
                    if (routeLength > radius)
                    {
                        return(false);
                    }

                    var rSystemName = radiusId > 0 ? srcSystem?.name ?? LM.Get("Unknown") : LM.Get("Unknown");
                    km.dic.Add("{radiusSystem}", rSystemName);
                    km.dic.Add("{radiusJumps}", routeLength.ToString());

                    break;

                case RadiusMode.Constellation:
                    if (km.rSystem.constellation_id != radiusId)
                    {
                        return(false);
                    }
                    break;

                case RadiusMode.Region:
                    if (km.rSystem.DB_RegionId > 0)
                    {
                        if (km.rSystem.DB_RegionId != radiusId)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        rConst = await APIHelper.ESIAPI.GetConstellationData(Reason, km.rSystem.constellation_id);

                        if (rConst == null || rConst.region_id != radiusId)
                        {
                            return(false);
                        }
                    }

                    break;
                }
                rConst = rConst ?? await APIHelper.ESIAPI.GetConstellationData(Reason, km.rSystem.constellation_id);

                rRegion = await APIHelper.ESIAPI.GetRegionData(Reason, rConst.region_id);
            }

            //var rSystemName = rSystem?.name ?? LM.Get("Unknown");

            km.dic.Add("{isRangeMode}", (mode == RadiusMode.Range).ToString());
            km.dic.Add("{isConstMode}", (mode == RadiusMode.Constellation).ToString());
            km.dic.Add("{isRegionMode}", (mode == RadiusMode.Region).ToString());
            km.dic.AddOrUpdateEx("{constName}", rConst?.name);
            km.dic.AddOrUpdateEx("{regionName}", rRegion?.name);

            var template = isUrlOnly ? null : await TemplateHelper.GetTemplatedMessage(MessageTemplateType.KillMailRadius, km.dic);

            var channels = filter.DiscordChannels.Any() ? filter.DiscordChannels : group.DiscordChannels;

            foreach (var channel in channels)
            {
                if (isUrlOnly)
                {
                    await APIHelper.DiscordAPI.SendMessageAsync(channel, kill.zkb.url);
                }
                else
                {
                    if (template != null)
                    {
                        await APIHelper.DiscordAPI.SendMessageAsync(channel, group.ShowGroupName?groupName : " ", template).ConfigureAwait(false);
                    }
                    else
                    {
                        var jumpsText = routeLength > 0 ? $"{routeLength} {LM.Get("From")} {srcSystem?.name}" : $"{LM.Get("InSmall")} {km.sysName} ({km.systemSecurityStatus})";
                        await APIHelper.DiscordAPI.SendEmbedKillMessage(new List <ulong> {
                            channel
                        }, new Color(0x989898), km, string.IsNullOrEmpty(jumpsText)? "-" : jumpsText, group.ShowGroupName?groupName : " ");
                    }
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private bool?CheckLocation(JsonClasses.SystemName rSystem, JsonZKill.Killmail kill, KillMailFilter filter, string groupName, string filterName)
        {
            if (rSystem == null)
            {
                LogHelper.LogError($"System not found: {kill.solar_system_id}!", Category).GetAwaiter().GetResult();
                return(false);
            }

            if (!filter.ShowHighsecSystem && rSystem.security_status >= .5f)
            {
                return(false);
            }
            if (!filter.ShowLowsecSystem && rSystem.security_status >= .1f)
            {
                return(false);
            }
            if (!filter.ShowWormholeSystem && rSystem.IsWormhole())
            {
                return(false);
            }
            if (!filter.ShowAbyssSystem && rSystem.IsAbyss())
            {
                return(false);
            }
            if (!filter.ShowNullsecSystem && rSystem.security_status <= 0f)
            {
                return(false);
            }

            //Region
            var fRegions = GetTier2RegionIds(ParsedLocationLists, groupName, filterName);

            if (fRegions.Any() && rSystem.DB_RegionId.HasValue && fRegions.Contains(rSystem.DB_RegionId.Value))
            {
                return(true);
            }
            //Constellation
            var fConsts = GetTier2ConstellationIds(ParsedLocationLists, groupName, filterName);

            if (fConsts.Any() && fConsts.Contains(rSystem.constellation_id))
            {
                return(true);
            }
            //System
            var fSystems = GetTier2SystemIds(ParsedLocationLists, groupName, filterName);

            if (fSystems.Any() && fSystems.Contains(kill.solar_system_id))
            {
                return(true);
            }

            return(fSystems.Any() || fConsts.Any() || fRegions.Any() ? false : (bool?)null);
        }