Пример #1
0
        /// <summary>
        /// Loop that will listen for new corp kills on zkill.
        /// </summary>
        /// <returns></returns>
        async Task ZkillLoop(CancellationToken token)
        {
            while (true)
            {
                string json = "";
                while (true)
                {
                    if (webSocket.State == WebSocketState.Aborted && !await TryConnectWebSocket(token))
                    {
                        await LogModule.LogError("Fatal: Unable to connect to zkill websocket api after five attempts.", "debug");

                        return;
                    }

                    byte[] buffer = new byte[2048];
                    WebSocketReceiveResult result = await webSocket.ReceiveAsync(buffer, token);

                    json += Encoding.UTF8.GetString(buffer);

                    if (result.EndOfMessage)
                    {
                        break;
                    }
                }

                // Remove empty space, and replace it with less empty space.
                json = json.Replace((char)0x00, ' ');

                KillMail km = JsonSerializer.Deserialize <KillMail>(json);
                if ((Config.TargetCorp == 0 || km.Attackers.Exists(a => a.CorporationID == Config.TargetCorp)) && km.Attackers.Any(x => x.FinalBlow && x.CharacterID != 0))
                {
                    Embed embed = await BuildKillmailEmbed(km);

                    await LogModule.LogMessage("", Config.LogChannel, embed : embed);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Create a embed for a killmail
        /// </summary>
        /// <param name="km"></param>
        /// <returns></returns>
        async Task <Embed> BuildKillmailEmbed(KillMail km)
        {
            Attacker finalBlow = km.Attackers.Find(a => a.FinalBlow);
            DateTime killTime  = DateTime.Parse(km.Time);

            List <EsiCharacter> chars = await GetCharacters(new List <object>()
            {
                km.Victim.CharacterID.ToString(),
                finalBlow.CharacterID.ToString(),
            });

            List <EsiCorporation> corps = await GetCorporations(new List <object>()
            {
                km.Victim.CorporationID.ToString(),
                finalBlow.CorporationID.ToString(),
            });

            List <EsiAlliance> alliances = await GetAlliances(corps.Select(x => x.AllianceId).Cast <object>().ToList());

            List <EsiItem> ships = await GetShips(new List <object>()
            {
                km.Victim.ShipType.ToString(),
                finalBlow.ShipType.ToString(),
            });

            EsiSystem system = (await ApiModule.Esi.Path("/universe/systems/{system_id}/").Get <EsiSystem>(("system_id", km.Solarsystem.ToString()))).FirstPage;

            return(new KillmailEmbedBuilder()
                   .AddVictim(chars[0].Name, (int)km.Victim.CharacterID, corps[0].Name, (int)km.Victim.CorporationID, alliances[0].Name, km.Victim.ShipType)
                   .AddFinalBlow(chars[1].Name, (int)finalBlow.CharacterID, corps[1].Name, (int)finalBlow.CorporationID, alliances[1].Name, finalBlow.ShipType, ships[1].Name, finalBlow.ShipType)
                   .AddDetails(km.Zkb.Awox, km.Zkb.TotalValue, killTime, km.KillmailId)
                   .AddTitle(ships[0].Name, system.Name, km.KillmailId)
                   .AddThumbnail(km.Victim.ShipType)
                   .AddFooter((int)finalBlow.CorporationID)
                   .Build());
        }