internal async Task SendEmbedKillMessage(ulong channelId, Color color, KillDataEntry km, string radiusMessage, string msg = "") { //long shipID, long kmId, string shipName, long value, string sysName, string secstatus, string killTime, string cName, string corpName //, string aTicker, bool isNpcKill, string atName, string atCorp, string atTicker, int atCount // shipID, killmailID, rShipType.name, (long) value, // sysName, systemSecurityStatus, killTime, rVictimCharacter == null ? rShipType.name : rVictimCharacter.name, rVictimCorp.name, // rVictimAlliance == null ? "" : $"[{rVictimAlliance.ticker}]", isNPCKill, rAttackerCharacter.name, rAttackerCorp.name, // rAttackerAlliance == null ? null : $"[{rAttackerAlliance.ticker}]", attackers.Length msg = msg ?? ""; var aTicker = km.rVictimAlliance == null ? "" : $"[{km.rVictimAlliance.ticker}]"; var atTicker = km.rAttackerAlliance == null ? null : $"[{km.rAttackerAlliance.ticker}]"; var killString = LM.Get("killFeedString", !string.IsNullOrEmpty(radiusMessage) ? "R " : null, km.rShipType?.name, km.value, km.rVictimCharacter == null ? km.rShipType?.name : km.rVictimCharacter.name, km.rVictimCorp.name, string.IsNullOrEmpty(aTicker) ? null : aTicker, km.sysName, km.systemSecurityStatus, km.killTime); var killedBy = km.isNPCKill ? null : LM.Get("killFeedBy", km.rAttackerCharacter.name, km.rAttackerCorp.name, string.IsNullOrEmpty(atTicker) ? null : atTicker, km.attackers.Length); var builder = new EmbedBuilder() .WithColor(color) .WithThumbnailUrl($"https://image.eveonline.com/Type/{km.shipID}_32.png") .WithAuthor(author => { author.WithName($"{killString} {killedBy}") .WithUrl($"https://zkillboard.com/kill/{km.killmailID}/"); if (km.isNPCKill) { author.WithIconUrl("http://www.panthernet.org/uf/npc2.jpg"); } }); if (!string.IsNullOrEmpty(radiusMessage)) { builder.AddField(LM.Get("radiusInfoHeader"), radiusMessage, true); } var embed = builder.Build(); var channel = GetGuild()?.GetTextChannel(channelId); if (channel != null) { await SendMessageAsync(channel, msg, embed).ConfigureAwait(false); } }
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); }
private async Task ProcessKill(JsonZKill.Killmail kill) { try { // kill = JsonConvert.DeserializeObject<JsonZKill.Killmail>(File.ReadAllText("testkm.txt")); var hasBeenPosted = false; foreach (var(groupName, group) in Settings.LiveKillFeedModule.Groups) { if (Settings.ZKBSettingsModule.AvoidDupesAcrossAllFeeds && ZKillLiveFeedModule.IsInSharedPool(kill.killmail_id)) { return; } if (hasBeenPosted && Settings.LiveKillFeedModule.StopOnFirstGroupMatch) { break; } if (UpdateLastPosted(groupName, kill.killmail_id)) { continue; } var isPveKill = kill.zkb.npc; var isPvpKill = !kill.zkb.npc; if ([email protected] && isPveKill || [email protected] && isPvpKill) { continue; } if (!group.FeedAwoxKills && kill.zkb.awox) { continue; } if (!group.FeedNotAwoxKills && !kill.zkb.awox) { continue; } if (!group.FeedSoloKills && kill.zkb.solo) { continue; } if (!group.FeedGroupKills && !kill.zkb.solo) { continue; } foreach (var(filterName, filter) in group.Filters) { var isInclusive = filter.Inclusive; var isLoss = false; var isPassed = false; var isFirstMatchOnly = !filter.AllMustMatch; var isCertifiedToFeed = false; #region Person checks //exclusions var exList = GetTier2CharacterIds(ParsedExcludeAttackersLists, groupName, filterName); if (exList.ContainsAnyFromList(kill.attackers.Select(a => a.character_id).Distinct())) { continue; } exList = GetTier2CorporationIds(ParsedExcludeAttackersLists, groupName, filterName); if (exList.ContainsAnyFromList(kill.attackers.Select(a => a.corporation_id).Distinct())) { continue; } exList = GetTier2AllianceIds(ParsedExcludeAttackersLists, groupName, filterName); if (exList.ContainsAnyFromList(kill.attackers.Where(a => a.alliance_id > 0).Select(a => a.alliance_id).Distinct())) { continue; } exList = GetTier2CharacterIds(ParsedExcludeVictimsLists, groupName, filterName); if (exList.Contains(kill.victim.character_id)) { continue; } exList = GetTier2CorporationIds(ParsedExcludeVictimsLists, groupName, filterName); if (exList.Contains(kill.victim.corporation_id)) { continue; } if (kill.victim.alliance_id > 0) { exList = GetTier2AllianceIds(ParsedExcludeVictimsLists, groupName, filterName); if (exList.Contains(kill.victim.alliance_id)) { continue; } } exList = GetTier2SystemIds(ParsedExcludeLocationLists, groupName, filterName); if (exList.Contains(kill.solar_system_id)) { continue; } var rSystem = await APIHelper.ESIAPI.GetSystemData(Reason, kill.solar_system_id); exList = GetTier2ConstellationIds(ParsedExcludeLocationLists, groupName, filterName); if (rSystem != null && exList.Contains(rSystem.constellation_id)) { continue; } exList = GetTier2RegionIds(ParsedExcludeLocationLists, groupName, filterName); if (rSystem?.DB_RegionId != null && exList.Contains(rSystem.DB_RegionId.Value)) { continue; } exList = GetTier2TypeIds(ParsedExcludeShipsLists, groupName, filterName); if (exList.Contains(kill.victim.ship_type_id)) { continue; } //character check var fChars = GetTier2CharacterIds(ParsedAttackersLists, groupName, filterName); if (fChars.Any()) { var attackers = kill.attackers.Select(a => a.character_id); if (isInclusive) { if (!fChars.ContainsAnyFromList(attackers)) { if (!isFirstMatchOnly) { continue; } } else { isPassed = true; isCertifiedToFeed = isFirstMatchOnly; } } if (!isInclusive && fChars.ContainsAnyFromList(attackers)) { continue; } } if (!isCertifiedToFeed) { fChars = GetTier2CharacterIds(ParsedVictimsLists, groupName, filterName); if (fChars.Any()) { if (isInclusive) { if (!fChars.Contains(kill.victim.character_id)) { if (!isFirstMatchOnly) { continue; } } else { isLoss = true; isPassed = true; isCertifiedToFeed = isFirstMatchOnly; } } if (!isInclusive && fChars.Contains(kill.victim.character_id)) { continue; } } } //corp check if (!isPassed && !isCertifiedToFeed) { fChars = GetTier2CorporationIds(ParsedAttackersLists, groupName, filterName); if (fChars.Any()) { var attackers = kill.attackers.Select(a => a.corporation_id); if (isInclusive) { if (!fChars.ContainsAnyFromList(attackers)) { if (!isFirstMatchOnly) { continue; } } else { isPassed = true; isCertifiedToFeed = isFirstMatchOnly; } } if (!isInclusive && fChars.ContainsAnyFromList(attackers)) { continue; } } if (!isCertifiedToFeed) { fChars = GetTier2CorporationIds(ParsedVictimsLists, groupName, filterName); if (fChars.Any()) { if (isInclusive) { if (!fChars.Contains(kill.victim.corporation_id)) { if (!isFirstMatchOnly) { continue; } } else { isLoss = true; isPassed = true; isCertifiedToFeed = isFirstMatchOnly; } } if (!isInclusive && fChars.Contains(kill.victim.corporation_id)) { continue; } } } } //alliance check if (!isPassed && !isCertifiedToFeed) { fChars = GetTier2AllianceIds(ParsedAttackersLists, groupName, filterName); if (fChars.Any()) { var attackers = kill.attackers.Where(a => a.alliance_id > 0).Select(a => a.alliance_id); if (isInclusive) { if (!fChars.ContainsAnyFromList(attackers)) { if (!isFirstMatchOnly) { continue; } } else { isPassed = true; isCertifiedToFeed = isFirstMatchOnly; } } if (!isInclusive && fChars.ContainsAnyFromList(attackers)) { continue; } } if (!isCertifiedToFeed) { fChars = GetTier2AllianceIds(ParsedVictimsLists, groupName, filterName); if (fChars.Any()) { if (isInclusive) { if (!isFirstMatchOnly && kill.victim.alliance_id == 0) { continue; } if (kill.victim.alliance_id > 0) { if (!fChars.Contains(kill.victim.alliance_id)) { if (!isFirstMatchOnly) { continue; } } else { isLoss = true; isPassed = true; isCertifiedToFeed = isFirstMatchOnly; } } } if (!isInclusive && fChars.Contains(kill.victim.alliance_id)) { continue; } } } } isPassed = false; #endregion //value checks if (!isCertifiedToFeed) { if (isLoss && filter.MinimumLossValue >= kill.zkb.totalValue) { continue; } if (filter.MaximumLossValue > 0 && isLoss && filter.MaximumLossValue <= kill.zkb.totalValue) { continue; } if (!isLoss && filter.MinimumKillValue >= kill.zkb.totalValue) { continue; } if (filter.MaximumKillValue > 0 && !isLoss && filter.MaximumKillValue <= kill.zkb.totalValue) { continue; } if (isFirstMatchOnly && (filter.MinimumKillValue > 0 || filter.MinimumLossValue > 0 || filter.MaximumLossValue > 0 || filter.MaximumKillValue > 0)) { isCertifiedToFeed = true; } } #region Location checks (except system radius) if (!isCertifiedToFeed) { var check = CheckLocation(rSystem, kill, isInclusive, groupName, filterName); //if have some location criteria if (check != null) { if (check == false) { if (filter.Radius == 0 && !isFirstMatchOnly) { continue; } } else if (isInclusive && isFirstMatchOnly) { isCertifiedToFeed = true; } } } #endregion #region Type checks var types = GetTier2TypeIds(ParsedShipsLists, groupName, filterName); if (types.Any() && !isCertifiedToFeed) { if (isInclusive && !types.Contains(kill.victim.ship_type_id)) { if (!isFirstMatchOnly) { continue; } } if (!isInclusive && types.Contains(kill.victim.ship_type_id)) { continue; } if (isInclusive && isFirstMatchOnly) { isCertifiedToFeed = true; } } #endregion //haven't hit any criteria for 1-hit mode if (!isCertifiedToFeed && isFirstMatchOnly) { continue; } var discordChannels = filter.DiscordChannels.Any() ? filter.DiscordChannels : group.DiscordChannels; if (filter.Radius > 0) { #region Process system radius check var msgType = MessageTemplateType.KillMailRadius; var isDone = false; foreach (var radiusSystemId in GetTier2SystemIds(ParsedLocationLists, groupName, filterName)) { if (await ProcessLocation(radiusSystemId, kill, group, filter, groupName)) { isDone = true; hasBeenPosted = true; if (Settings.ZKBSettingsModule.AvoidDupesAcrossAllFeeds) { ZKillLiveFeedModule.UpdateSharedIdPool(kill.killmail_id); } await LogHelper.LogInfo($"Posting {(isLoss ? "RLoss" : "RKill")}: {kill.killmail_id} Value: {kill.zkb.totalValue:n0} ISK", Category); break; } } if (isDone && group.StopOnFirstFilterMatch) { break; //goto next group } #endregion } else { if (group.FeedUrlsOnly) { foreach (var channel in discordChannels) { await APIHelper.DiscordAPI.SendMessageAsync(channel, kill.zkb.url); } } else { var hasTemplate = !string.IsNullOrWhiteSpace(group.MessageTemplateFileName); var msgColor = isLoss ? new Color(0xD00000) : new Color(0x00FF00); var msgType = !hasTemplate ? MessageTemplateType.KillMailGeneral : MessageTemplateType.Custom; var km = new KillDataEntry(); if (await km.Refresh(Reason, kill)) { km.dic["{isLoss}"] = isLoss ? "true" : "false"; var isDone = hasTemplate ? await TemplateHelper.PostTemplatedMessage(group.MessageTemplateFileName, km.dic, discordChannels, group.ShowGroupName?groupName : " ") : await TemplateHelper.PostTemplatedMessage(msgType, km.dic, discordChannels, group.ShowGroupName?groupName : " "); if (!isDone) { await APIHelper.DiscordAPI.SendEmbedKillMessage(discordChannels, msgColor, km, null); } } } if (Settings.ZKBSettingsModule.AvoidDupesAcrossAllFeeds) { ZKillLiveFeedModule.UpdateSharedIdPool(kill.killmail_id); } await LogHelper.LogInfo($"Posting {(isLoss ? "Loss" : "Kill")}: {kill.killmail_id} Value: {kill.zkb.totalValue:n0} ISK", Category); hasBeenPosted = true; if (group.StopOnFirstFilterMatch) { break; //goto next group } } continue; //goto next filter } } } catch (Exception ex) { await LogHelper.LogEx(ex.Message, ex, Category); await LogHelper.LogWarning($"Error processing kill ID {kill?.killmail_id} ! Msg: {ex.Message}", Category); } }
private async Task ProcessLocation(long radiusId, RadiusMode mode, JsonZKill.Killmail kill, RadiusGroup @group, string groupName) { var isUrlOnly = group.FeedUrlsOnly; var radius = group.Radius; var minimumValue = group.MinimumValue; if (radiusId <= 0) { await LogHelper.LogError("Radius feed must have systemId, constId or regionId defined!", Category); return; } var km = new KillDataEntry(); await km.Refresh(Reason, kill); //validity check if (minimumValue > 0 && km.value < minimumValue) { return; } 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 { if (radius == 0 || km.isUnreachableSystem || (srcSystem?.IsUnreachable() ?? false)) //Thera WH Abyss { return; } switch (mode) { case RadiusMode.Range: var route = await APIHelper.ESIAPI.GetRawRoute(Reason, radiusId, km.systemId); if (string.IsNullOrEmpty(route)) { return; } JArray data; try { data = JArray.Parse(route); } catch (Exception ex) { await LogHelper.LogEx("Route parse: " + ex.Message, ex, Category); return; } routeLength = data.Count - 1; //not in range if (routeLength > radius) { return; } 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; } break; case RadiusMode.Region: rConst = await APIHelper.ESIAPI.GetConstellationData(Reason, km.rSystem.constellation_id); if (rConst == null || rConst.region_id != radiusId) { return; } 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.Add("{constName}", rConst?.name); km.dic.Add("{regionName}", rRegion?.name); var template = isUrlOnly ? null : await TemplateHelper.GetTemplatedMessage(MessageTemplateType.KillMailRadius, km.dic); foreach (var channel in group.RadiusChannels) { 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(channel, new Color(0x989898), km, jumpsText, group.ShowGroupName?groupName : " "); } } } await LogHelper.LogInfo($"Posting Radius Kill: {kill.killmail_id} Value: {km.value:n0} ISK", Category); }
internal async Task SendEmbedKillMessage(List <ulong> channelIds, Color color, KillDataEntry km, string radiusMessage, string msg = "") { try { msg = msg ?? ""; var victimName = $"{LM.Get("killFeedName", $"[{km.rVictimCharacter?.name}]({GetKillMailLink(km.victimCharacterID, KillMailLinkTypes.character)})")}"; var victimCorp = $"{LM.Get("killFeedCorp", $"[{km.rVictimCorp?.name}]({GetKillMailLink(km.victimCorpID, KillMailLinkTypes.corporation)})")}"; var victimAlliance = km.rVictimAlliance == null ? "" : $"{LM.Get("killFeedAlliance", $"[{km.rVictimAlliance?.name}]")}({GetKillMailLink(km.victimAllianceID, KillMailLinkTypes.alliance)})"; var victimShip = $"{LM.Get("killFeedShip", $"[{km.rVictimShipType?.name}]({GetKillMailLink(km.victimShipID, KillMailLinkTypes.ship)})")}"; string[] victimStringArray = new string[] { victimName, victimCorp, victimAlliance, victimShip }; var attackerName = $"{LM.Get("killFeedName", $"[{km.rAttackerCharacter?.name}]({GetKillMailLink(km.finalBlowAttackerCharacterId, KillMailLinkTypes.character)})")}"; var attackerCorp = $"{LM.Get("killFeedCorp", $"[{km.rAttackerCorp?.name}]({GetKillMailLink(km.finalBlowAttackerCorpId, KillMailLinkTypes.corporation)})")}"; var attackerAlliance = km.rAttackerAlliance == null || km.finalBlowAttackerAllyId == 0 ? null : $"{LM.Get("killFeedAlliance", $"[{km.rAttackerAlliance?.name}]({GetKillMailLink(km.finalBlowAttackerAllyId, KillMailLinkTypes.alliance)})")}"; var attackerShip = $"{LM.Get("killFeedShip", $"[{km.rAttackerShipType?.name}]({GetKillMailLink(km.attackerShipID, KillMailLinkTypes.ship)})")}"; string[] attackerStringArray = new string[] { attackerName, attackerCorp, attackerAlliance, attackerShip }; var killFeedDetails = LM.Get("killFeedDetails", km.killTime, km.value.ToString("#,##0 ISk")); var killFeedDetailsSystem = LM.Get("killFeedDetailsSystem", $"[{km.sysName}]({GetKillMailLink(km.systemId, KillMailLinkTypes.system)})"); string[] detailsStringArray = new string[] { killFeedDetails, killFeedDetailsSystem }; var builder = new EmbedBuilder() .WithColor(color) .WithThumbnailUrl($"https://image.eveonline.com/Type/{km.victimShipID}_64.png") .WithAuthor(author => { author.WithName(LM.Get("killFeedHeader", km.rVictimShipType?.name, km.rSystem?.name)) .WithUrl($"https://zkillboard.com/kill/{km.killmailID}/"); if (km.isNPCKill) { author.WithIconUrl("http://www.panthernet.org/uf/npc2.jpg"); } }) .AddField(LM.Get("Victim"), string.Join("\n", victimStringArray.Where(c => !string.IsNullOrWhiteSpace(c)))) .AddField(LM.Get("Finalblow"), string.Join("\n", attackerStringArray.Where(c => !string.IsNullOrWhiteSpace(c)))) .AddField(LM.Get("Details"), string.Join("\n", detailsStringArray.Where(c => !string.IsNullOrWhiteSpace(c)))); if (!string.IsNullOrEmpty(radiusMessage)) { builder.AddField(LM.Get("radiusInfoHeader"), radiusMessage); } var embed = builder.Build(); foreach (var id in channelIds) { var channel = GetGuild()?.GetTextChannel(id); if (channel != null) { await SendMessageAsync(channel, msg, embed).ConfigureAwait(false); } } } catch (Exception ex) { await LogHelper.LogEx(nameof(SendEmbedKillMessage), ex, LogCat.Discord); } }
private async Task ProcessKill(JsonZKill.Killmail kill) { try { RunningRequestCount++; // var text = JsonConvert.SerializeObject(kill); //kill = JsonConvert.DeserializeObject<JsonZKill.Killmail>(File.ReadAllText("testkm_pvp.txt")); var hasBeenPosted = false; foreach (var(groupName, group) in Settings.LiveKillFeedModule.GetEnabledGroups()) { if (Settings.ZKBSettingsModule.AvoidDupesAcrossAllFeeds && ZKillLiveFeedModule.IsInSharedPool(kill.killmail_id)) { return; } if (hasBeenPosted && Settings.LiveKillFeedModule.StopOnFirstGroupMatch) { break; } if (UpdateLastPosted(groupName, kill.killmail_id)) { continue; } var isPveKill = kill.zkb.npc; var isPvpKill = !kill.zkb.npc; if ([email protected] && isPveKill || [email protected] && isPvpKill) { continue; } if (!group.FeedAwoxKills && kill.zkb.awox) { continue; } if (!group.FeedNotAwoxKills && !kill.zkb.awox) { continue; } if (!group.FeedSoloKills && kill.zkb.solo) { continue; } if (!group.FeedGroupKills && !kill.zkb.solo) { continue; } foreach (var(filterName, filter) in group.Filters) { var isLoss = false; var isCertifiedToFeed = false; #region Person & Value checks #region Exclusions var exList = GetTier2CharacterIds(ParsedExcludeAttackersLists, groupName, filterName); if (exList.ContainsAnyFromList(kill.attackers.Select(a => a.character_id).Distinct())) { continue; } exList = GetTier2CorporationIds(ParsedExcludeAttackersLists, groupName, filterName); if (exList.ContainsAnyFromList(kill.attackers.Select(a => a.corporation_id).Distinct())) { continue; } exList = GetTier2AllianceIds(ParsedExcludeAttackersLists, groupName, filterName); if (exList.ContainsAnyFromList(kill.attackers.Where(a => a.alliance_id > 0) .Select(a => a.alliance_id).Distinct())) { continue; } exList = GetTier2CharacterIds(ParsedExcludeVictimsLists, groupName, filterName); if (exList.Contains(kill.victim.character_id)) { continue; } exList = GetTier2CorporationIds(ParsedExcludeVictimsLists, groupName, filterName); if (exList.Contains(kill.victim.corporation_id)) { continue; } if (kill.victim.alliance_id > 0) { exList = GetTier2AllianceIds(ParsedExcludeVictimsLists, groupName, filterName); if (exList.Contains(kill.victim.alliance_id)) { continue; } } exList = GetTier2SystemIds(ParsedExcludeLocationLists, groupName, filterName); if (exList.Contains(kill.solar_system_id)) { continue; } var rSystem = await APIHelper.ESIAPI.GetSystemData(Reason, kill.solar_system_id); exList = GetTier2ConstellationIds(ParsedExcludeLocationLists, groupName, filterName); if (rSystem != null && exList.Contains(rSystem.constellation_id)) { continue; } exList = GetTier2RegionIds(ParsedExcludeLocationLists, groupName, filterName); if (rSystem?.DB_RegionId != null && exList.Contains(rSystem.DB_RegionId.Value)) { continue; } exList = GetTier2TypeIds(ParsedExcludeVictimShipsLists, groupName, filterName); if (exList.Contains(kill.victim.ship_type_id)) { continue; } exList = GetTier2TypeIds(ParsedExcludeAttackerShipsLists, groupName, filterName); if (kill.attackers.Select(a => a.ship_type_id).ContainsAnyFromList(exList)) { continue; } #endregion //value checks if (filter.MinimumIskValue > kill.zkb.totalValue) { continue; } if (filter.MaximumIskValue > 0 && filter.MaximumIskValue < kill.zkb.totalValue) { continue; } //if (filter.EnableMatchOnFirstConditionMet && (filter.MinimumIskValue > 0 || filter.MaximumIskValue > 0 )) // isCertifiedToFeed = true; //character check var hasAttackerMatch = false; var hasPartyCheck = false; List <long> entityIds; if (!isCertifiedToFeed) { entityIds = GetTier2CharacterIds(ParsedAttackersLists, groupName, filterName); if (entityIds.Any()) { hasPartyCheck = true; var attackers = kill.attackers.Select(a => a.character_id); if (entityIds.ContainsAnyFromList(attackers)) { if (filter.EnableMatchOnFirstConditionMet) { isCertifiedToFeed = true; } hasAttackerMatch = true; } } } var hasVictimMatch = false; if (!isCertifiedToFeed) { entityIds = GetTier2CharacterIds(ParsedVictimsLists, groupName, filterName); if (entityIds.Any()) { hasPartyCheck = true; if (entityIds.Contains(kill.victim.character_id)) { if (filter.EnableMatchOnFirstConditionMet) { isCertifiedToFeed = true; } hasVictimMatch = true; isLoss = true; } } } //corp check if ((!hasVictimMatch || !hasAttackerMatch) && !isCertifiedToFeed) { if (!hasAttackerMatch) { entityIds = GetTier2CorporationIds(ParsedAttackersLists, groupName, filterName); if (entityIds.Any()) { hasPartyCheck = true; var attackers = kill.attackers.Select(a => a.corporation_id); if (entityIds.ContainsAnyFromList(attackers)) { if (filter.EnableMatchOnFirstConditionMet) { isCertifiedToFeed = true; } hasAttackerMatch = true; } } } if (!isCertifiedToFeed && !hasVictimMatch) { entityIds = GetTier2CorporationIds(ParsedVictimsLists, groupName, filterName); if (entityIds.Any()) { hasPartyCheck = true; if (entityIds.Contains(kill.victim.corporation_id)) { if (filter.EnableMatchOnFirstConditionMet) { isCertifiedToFeed = true; } hasVictimMatch = true; isLoss = true; } } } } //alliance check if ((!hasVictimMatch || !hasAttackerMatch) && !isCertifiedToFeed) { if (!hasAttackerMatch) { entityIds = GetTier2AllianceIds(ParsedAttackersLists, groupName, filterName); if (entityIds.Any()) { hasPartyCheck = true; var attackers = kill.attackers.Where(a => a.alliance_id > 0) .Select(a => a.alliance_id); if (entityIds.ContainsAnyFromList(attackers)) { if (filter.EnableMatchOnFirstConditionMet) { isCertifiedToFeed = true; } hasAttackerMatch = true; } } } if (!isCertifiedToFeed && !hasVictimMatch) { entityIds = GetTier2AllianceIds(ParsedVictimsLists, groupName, filterName); if (entityIds.Any()) { hasPartyCheck = true; if (entityIds.Contains(kill.victim.alliance_id)) { if (filter.EnableMatchOnFirstConditionMet) { isCertifiedToFeed = true; } hasVictimMatch = true; isLoss = true; } } } } //has no strict match = continue if (hasPartyCheck && !isCertifiedToFeed && filter.EnableStrictPartiesCheck && (!hasAttackerMatch || !hasVictimMatch)) { continue; } //has no party match on check if (hasPartyCheck && !isCertifiedToFeed && !filter.EnableStrictPartiesCheck && !hasAttackerMatch && !hasVictimMatch) { continue; } #endregion #region Location checks (except system radius) if (!isCertifiedToFeed) { var check = CheckLocation(rSystem, kill, filter, groupName, filterName); //if have some location criteria if (check != null) { if (check.Value) //match { if (filter.EnableMatchOnFirstConditionMet) { isCertifiedToFeed = true; } } else //no match { //no radius checks planned if (filter.Radius == 0) { continue; } } } } #endregion #region Type checks bool hasTypesCheck = false; bool hasVictimTypeMatch = false; bool hasAttackerTypeMatch = false; var types = GetTier2TypeIds(ParsedVictimShipsLists, groupName, filterName); if (types.Any() && !isCertifiedToFeed) { hasTypesCheck = true; if (types.Contains(kill.victim.ship_type_id)) { hasVictimTypeMatch = true; if (filter.EnableMatchOnFirstConditionMet) { isCertifiedToFeed = true; } } } types = GetTier2TypeIds(ParsedAttackerShipsLists, groupName, filterName); if (types.Any() && !isCertifiedToFeed) { hasTypesCheck = true; if (types.ContainsAnyFromList(kill.attackers.Select(a => a.ship_type_id))) { hasAttackerTypeMatch = true; if (filter.EnableMatchOnFirstConditionMet) { isCertifiedToFeed = true; } } } if (hasTypesCheck && !isCertifiedToFeed && filter.EnableStrictShipTypesCheck && (!hasAttackerTypeMatch || !hasVictimTypeMatch)) { continue; } if (hasTypesCheck && !isCertifiedToFeed && !filter.EnableStrictShipTypesCheck && !hasAttackerTypeMatch && !hasVictimTypeMatch) { continue; } #endregion //haven't hit any criteria for 1-hit mode // if(!isCertifiedToFeed && filter.EnableMatchOnFirstConditionMet) continue; var discordChannels = filter.DiscordChannels.Any() ? filter.DiscordChannels : group.DiscordChannels; if (filter.Radius > 0) { #region Process system radius check //var msgType = MessageTemplateType.KillMailRadius; var isDone = false; foreach (var radiusSystemId in GetTier2SystemIds(ParsedLocationLists, groupName, filterName)) { if (await ProcessLocation(radiusSystemId, kill, group, filter, groupName)) { isDone = true; hasBeenPosted = true; if (Settings.ZKBSettingsModule.AvoidDupesAcrossAllFeeds) { ZKillLiveFeedModule.UpdateSharedIdPool(kill.killmail_id); } await LogHelper.LogInfo( $"Posting {(isLoss ? "RLoss" : "RKill")}: {kill.killmail_id} Value: {kill.zkb.totalValue:n0} ISK", Category); break; } } if (isDone && group.StopOnFirstFilterMatch) { break; //goto next group } #endregion } else { if (group.FeedUrlsOnly) { foreach (var channel in discordChannels) { await APIHelper.DiscordAPI.SendMessageAsync(channel, kill.zkb.url); } await LogHelper.LogInfo( $"U.Posted {(isLoss ? "Loss" : "Kill")}: {kill.killmail_id} Value: {kill.zkb.totalValue:n0} ISK", Category); } else { var hasTemplate = !string.IsNullOrWhiteSpace(group.MessageTemplateFileName); var msgColor = isLoss ? new Color(0xD00000) : new Color(0x00FF00); var km = new KillDataEntry(); if (await km.Refresh(Reason, kill)) { km.dic["{isLoss}"] = isLoss ? "true" : "false"; if (hasTemplate) { hasBeenPosted = await TemplateHelper.PostTemplatedMessage( group.MessageTemplateFileName, km.dic, discordChannels, group.ShowGroupName?groupName : " "); if (hasBeenPosted) { await LogHelper.LogInfo( $"T.Posted {(isLoss ? "Loss" : "Kill")}: {kill.killmail_id} Value: {kill.zkb.totalValue:n0} ISK", Category); } } else { await SendEmbedKillMessage(discordChannels, msgColor, km, group.ShowGroupName?groupName : " "); hasBeenPosted = true; await LogHelper.LogInfo( $"N.Posted {(isLoss ? "Loss" : "Kill")}: {kill.killmail_id} Value: {kill.zkb.totalValue:n0} ISK", Category); } } } if (Settings.ZKBSettingsModule.AvoidDupesAcrossAllFeeds) { ZKillLiveFeedModule.UpdateSharedIdPool(kill.killmail_id); } if (group.StopOnFirstFilterMatch) { break; //goto next group } } continue; //goto next filter } } } catch (Exception ex) { await LogHelper.LogEx(ex.Message, ex, Category); await LogHelper.LogWarning($"Error processing kill ID {kill?.killmail_id} ! Msg: {ex.Message}", Category); } finally { RunningRequestCount--; } }
private async Task ProcessKill(JsonZKill.Killmail kill) { try { if (_lastPosted == kill.killmail_id) { return; } var postedGlobalBigKill = false; var bigKillGlobalValue = SettingsManager.Settings.LiveKillFeedModule.BigKill; var bigKillGlobalChan = SettingsManager.Settings.LiveKillFeedModule.BigKillChannel; var isNPCKill = kill.zkb.npc; var km = new KillDataEntry(); foreach (var groupPair in Settings.LiveKillFeedModule.GroupsConfig) { var group = groupPair.Value; if ((!group.FeedPveKills && isNPCKill) || (!group.FeedPvpKills && !isNPCKill)) { continue; } var minimumValue = group.MinimumValue; var minimumLossValue = group.MinimumLossValue; var allianceIdList = group.AllianceID; var corpIdList = group.CorpID; var bigKillValue = group.BigKillValue; var c = group.DiscordChannel; var sendBigToGeneral = group.BigKillSendToGeneralToo; var bigKillChannel = group.BigKillChannel; var discordGroupName = groupPair.Key; var isUrlOnly = group.FeedUrlsOnly; if (c == 0) { await LogHelper.LogWarning($"Group {groupPair.Key} has no 'discordChannel' specified! Kills will be skipped.", Category); continue; } var value = kill.zkb.totalValue; if (bigKillGlobalChan != 0 && bigKillGlobalValue != 0 && value >= bigKillGlobalValue && !postedGlobalBigKill) { postedGlobalBigKill = true; if (isUrlOnly) { await APIHelper.DiscordAPI.SendMessageAsync(bigKillGlobalChan, kill.zkb.url); } else { if (await km.Refresh(Reason, kill) && !await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailBig, km.dic, bigKillGlobalChan, discordGroupName)) { await APIHelper.DiscordAPI.SendEmbedKillMessage(bigKillGlobalChan, new Color(0xFA2FF4), km, null); } } await LogHelper.LogInfo($"Posting Global Big Kill: {kill.killmail_id} Value: {value:n0} ISK", Category); } if (!allianceIdList.Any() && !corpIdList.Any()) { if (value >= minimumValue) { if (isUrlOnly) { await APIHelper.DiscordAPI.SendMessageAsync(c, kill.zkb.url); } else if (await km.Refresh(Reason, kill) && !await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailGeneral, km.dic, c, discordGroupName)) { await APIHelper.DiscordAPI.SendEmbedKillMessage(c, new Color(0x00FF00), km, null); } await LogHelper.LogInfo($"Posting Global Kills: {kill.killmail_id} Value: {value:n0} ISK", Category); } } else { //ally & corp //Losses //Big if (bigKillChannel != 0 && bigKillValue != 0 && value >= bigKillValue) { if (kill.victim.alliance_id != 0 && allianceIdList.Contains(kill.victim.alliance_id) || corpIdList.Contains(kill.victim.corporation_id)) { if (isUrlOnly) { await APIHelper.DiscordAPI.SendMessageAsync(bigKillChannel, kill.zkb.url); if (sendBigToGeneral && c != bigKillChannel) { await APIHelper.DiscordAPI.SendMessageAsync(c, kill.zkb.url); } } else if (await km.Refresh(Reason, kill)) { km.dic["{isLoss}"] = "true"; try { if (!await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailBig, km.dic, bigKillChannel, discordGroupName)) { await APIHelper.DiscordAPI.SendEmbedKillMessage(bigKillChannel, new Color(0xD00000), km, null, groupPair.Value.ShowGroupName?discordGroupName : " "); if (sendBigToGeneral && c != bigKillChannel) { if (!await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailBig, km.dic, c, discordGroupName)) { await APIHelper.DiscordAPI.SendEmbedKillMessage(c, new Color(0xD00000), km, null, groupPair.Value.ShowGroupName?discordGroupName : " "); } } } } finally { km.dic.Remove("{isLoss}"); } } await LogHelper.LogInfo($"Posting Big Loss: {kill.killmail_id} Value: {value:n0} ISK", Category); continue; } } //Common if (minimumLossValue == 0 || minimumLossValue <= value) { if (kill.victim.alliance_id != 0 && allianceIdList.Contains(kill.victim.alliance_id) || corpIdList.Contains(kill.victim.corporation_id)) { if (isUrlOnly) { await APIHelper.DiscordAPI.SendMessageAsync(c, kill.zkb.url); } else if (await km.Refresh(Reason, kill)) { km.dic["{isLoss}"] = "true"; try { if (!await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailGeneral, km.dic, c, discordGroupName)) { await APIHelper.DiscordAPI.SendEmbedKillMessage(c, new Color(0xFF0000), km, null, groupPair.Value.ShowGroupName?discordGroupName : " "); } } finally { km.dic.Remove("{isLoss}"); } } await LogHelper.LogInfo($"Posting Loss: {kill.killmail_id} Value: {value:n0} ISK", Category); continue; } } //Kills foreach (var attacker in kill.attackers.ToList()) { if (bigKillChannel != 0 && bigKillValue != 0 && value >= bigKillValue && !isNPCKill) { if ((attacker.alliance_id != 0 && allianceIdList.Contains(attacker.alliance_id)) || (!allianceIdList.Any() && corpIdList.Contains(attacker.corporation_id))) { if (isUrlOnly) { await APIHelper.DiscordAPI.SendMessageAsync(bigKillChannel, kill.zkb.url); if (sendBigToGeneral && c != bigKillChannel) { await APIHelper.DiscordAPI.SendMessageAsync(c, kill.zkb.url); } } else if (await km.Refresh(Reason, kill)) { km.dic["{isLoss}"] = "false"; try { if (!await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailBig, km.dic, bigKillChannel, discordGroupName)) { await APIHelper.DiscordAPI.SendEmbedKillMessage(bigKillChannel, new Color(0x00D000), km, null, groupPair.Value.ShowGroupName?discordGroupName : " "); if (sendBigToGeneral && c != bigKillChannel) { if (!await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailBig, km.dic, c, discordGroupName)) { await APIHelper.DiscordAPI.SendEmbedKillMessage(c, new Color(0x00D000), km, null, groupPair.Value.ShowGroupName?discordGroupName : " "); } } await LogHelper.LogInfo($"Posting Big Kill: {kill.killmail_id} Value: {value:#,##0} ISK", Category); } } finally { km.dic.Remove("{isLoss}"); } } break; } } else if (!isNPCKill && attacker.alliance_id != 0 && allianceIdList.Any() && allianceIdList.Contains(attacker.alliance_id) || !isNPCKill && !allianceIdList.Any() && corpIdList.Contains(attacker.corporation_id)) { if (isUrlOnly) { await APIHelper.DiscordAPI.SendMessageAsync(c, kill.zkb.url); } else if (await km.Refresh(Reason, kill)) { km.dic["{isLoss}"] = "false"; try { if (!await TemplateHelper.PostTemplatedMessage(MessageTemplateType.KillMailGeneral, km.dic, c, discordGroupName)) { await APIHelper.DiscordAPI.SendEmbedKillMessage(c, new Color(0x00FF00), km, null, groupPair.Value.ShowGroupName?discordGroupName : " "); } } finally { km.dic.Remove("{isLoss}"); } } await LogHelper.LogInfo($"Posting Kill: {kill.killmail_id} Value: {value:#,##0} ISK", Category); break; } } } } _lastPosted = kill.killmail_id; } catch (Exception ex) { await LogHelper.LogEx(ex.Message, ex, Category); await LogHelper.LogWarning($"Error processing kill ID {kill?.killmail_id} ! Msg: {ex.Message}", Category); } }