Exemple #1
0
        private DiscordEmbed BuildEmbedPokemonFromAlarm(PokemonData pokemon, AlarmObject alarm)
        {
            var pkmn = _db.Pokemon[pokemon.Id.ToString()];

            if (pkmn == null)
            {
                _logger.Error($"Failed to lookup Pokemon '{pokemon.Id}' in database.");
                return(null);
            }

            var eb = new DiscordEmbedBuilder
            {
                Title        = alarm == null || string.IsNullOrEmpty(alarm.Name) ? "DIRECTIONS" : alarm.Name,
                Description  = $"{pkmn.Name}{pokemon.Gender.GetPokemonGenderIcon()} {pokemon.CP}CP {pokemon.IV} LV{pokemon.Level} has spawned!",
                Url          = string.Format(Strings.GoogleMaps, pokemon.Latitude, pokemon.Longitude),
                ImageUrl     = string.Format(Strings.GoogleMapsStaticImage, pokemon.Latitude, pokemon.Longitude),
                ThumbnailUrl = string.Format(Strings.PokemonImage, pokemon.Id, 0),
                Color        = DiscordHelpers.BuildColor(pokemon.IV)
            };

            eb.AddField($"{pkmn.Name} (#{pokemon.Id}, {pokemon.Gender})", $"CP: {pokemon.CP} IV: {pokemon.IV} (Sta: {pokemon.Stamina}/Atk: {pokemon.Attack}/Def: {pokemon.Defense}) LV: {pokemon.Level}");
            if (!string.IsNullOrEmpty(pokemon.FormId))
            {
                var form = pokemon.Id.GetPokemonForm(pokemon.FormId);
                if (!string.IsNullOrEmpty(form))
                {
                    eb.AddField("Form:", form);
                }
            }

            if (pkmn.Types.Count > 0)
            {
                var types = new List <string>();
                pkmn.Types.ForEach(x =>
                {
                    types.Add(Strings.TypeEmojis[x.Type.ToLower()]);
                });
                eb.AddField("Types: ", string.Join("/", types));
            }

            eb.AddField("Despawn:", $"{pokemon.DespawnTime.ToLongTimeString()} ({pokemon.SecondsLeft.ToReadableString(true)} left)");
            eb.AddField("Location:", $"{Math.Round(pokemon.Latitude, 5)},{Math.Round(pokemon.Longitude, 5)}");
            eb.WithImageUrl(string.Format(Strings.GoogleMapsStaticImage, pokemon.Latitude, pokemon.Longitude) + $"&key={_config.GmapsKey}");
            var embed = eb.Build();

            return(embed);
        }
Exemple #2
0
        public async Task <DiscordEmbed> BuildPokemonMessage(PokemonData pokemon, ulong userId)
        {
            var pkmn = _db.Pokemon[pokemon.Id.ToString()];

            if (pkmn == null)
            {
                _logger.Error($"Failed to lookup Pokemon '{pokemon.Id}' in database.");
                return(null);
            }

            var user = await _client.GetMemberFromUserId(userId);

            if (user == null)
            {
                _logger.Error($"Failed to get discord member object from user id {userId}.");
                return(null);
            }

            //var loc = Utils.GetGoogleAddress(pokemon.Latitude, pokemon.Longitude, _config.GmapsKey);
            var loc = _geofenceSvc.GetGeofence(new Location(pokemon.Latitude, pokemon.Longitude));

            if (loc == null)
            {
                _logger.Error($"Failed to lookup city from coordinates {pokemon.Latitude},{pokemon.Longitude} {pkmn.Name} {pokemon.IV}, skipping...");
                return(null);
            }

            if (!_config.CityRoles.Exists(x => string.Compare(x, loc.Name, true) == 0))
            {
                File.AppendAllText("cities.txt", $"City: {loc.Name}\r\n");
                return(null);
            }

            //if (!_client.HasRole(user, SanitizeCityName(loc.Name)))
            if (!_client.HasRole(user, loc.Name))
            {
                _logger.Debug($"Skipping user {user.DisplayName} ({user.Id}) for {pkmn.Name} {pokemon.IV}, no city role '{loc.Name}'.");
                return(null);
            }

            var form = pokemon.Id.GetPokemonForm(pokemon.FormId);
            var eb   = new DiscordEmbedBuilder
            {
                Title = loc == null || string.IsNullOrEmpty(loc.Name) ? "DIRECTIONS" : loc.Name,
                //Description = $"{pkmn.Name}{pokemon.Gender.GetPokemonGenderIcon()} {pokemon.CP}CP {pokemon.IV} Despawn: {pokemon.DespawnTime.ToLongTimeString()}",
                Url          = string.Format(Strings.GoogleMaps, pokemon.Latitude, pokemon.Longitude),
                ImageUrl     = string.Format(Strings.GoogleMapsStaticImage, pokemon.Latitude, pokemon.Longitude),
                ThumbnailUrl = string.Format(Strings.PokemonImage, pokemon.Id, Convert.ToInt32(string.IsNullOrEmpty(pokemon.FormId) ? "0" : pokemon.FormId)),
                Color        = DiscordHelpers.BuildColor(pokemon.IV)
            };

            if (pokemon.IV == "?")
            {
                eb.Description = $"{pkmn.Name} {form}{pokemon.Gender.GetPokemonGenderIcon()} Despawn: {pokemon.DespawnTime.ToLongTimeString()}\r\n";
            }
            else
            {
                eb.Description  = $"{pkmn.Name} {form}{pokemon.Gender.GetPokemonGenderIcon()} {pokemon.IV} L{pokemon.Level} Despawn: {pokemon.DespawnTime.ToLongTimeString()}\r\n\r\n";
                eb.Description += $"**Details:** CP: {pokemon.CP} IV: {pokemon.IV} LV: {pokemon.Level}\r\n";
            }
            eb.Description += $"**Despawn:** {pokemon.DespawnTime.ToLongTimeString()} ({pokemon.SecondsLeft.ToReadableStringNoSeconds()} left)\r\n";
            if (pokemon.Attack != "?" && pokemon.Defense != "?" && pokemon.Stamina != "?")
            {
                eb.Description += $"**IV Stats:** Atk: {pokemon.Attack}/Def: {pokemon.Defense}/Sta: {pokemon.Stamina}\r\n";
            }

            if (!string.IsNullOrEmpty(form))
            {
                eb.Description += $"**Form:** {form}\r\n";
            }

            if (int.TryParse(pokemon.Level, out int lvl) && lvl >= 30)
            {
                eb.Description += $":white_sun_rain_cloud: Boosted\r\n";
            }

            var maxCp     = _db.MaxCpAtLevel(pokemon.Id, 40);
            var maxWildCp = _db.MaxCpAtLevel(pokemon.Id, 35);

            eb.Description += $"**Max Wild CP:** {maxWildCp}, **Max CP:** {maxCp} \r\n";

            if (pkmn.Types.Count > 0)
            {
                var types = new List <string>();
                pkmn.Types.ForEach(x =>
                {
                    if (Strings.TypeEmojis.ContainsKey(x.Type.ToLower()))
                    {
                        types.Add($"{Strings.TypeEmojis[x.Type.ToLower()]} {x.Type}");
                    }
                });
                eb.Description += $"**Types:** {string.Join("/", types)}\r\n";
            }

            if (float.TryParse(pokemon.Height, out float height) && float.TryParse(pokemon.Weight, out float weight))
            {
                var size = _db.GetSize(pokemon.Id, height, weight);
                eb.Description += $"**Size:** {size}\r\n";
            }

            var fastMove = _db.Movesets.ContainsKey(pokemon.FastMove) ? _db.Movesets[pokemon.FastMove] : null;

            if (fastMove != null)
            {
                //var fastMoveIcon = Strings.TypeEmojis.ContainsKey(fastMove.Type.ToLower()) ? Strings.TypeEmojis[fastMove.Type.ToLower()] : fastMove.Type;
                eb.Description += $"**Fast Move:** {fastMove.Name} ({fastMove.Type})\r\n";
            }

            var chargeMove = _db.Movesets.ContainsKey(pokemon.ChargeMove) ? _db.Movesets[pokemon.ChargeMove] : null;

            if (chargeMove != null)
            {
                //var chargeMoveIcon = Strings.TypeEmojis.ContainsKey(chargeMove.Type.ToLower()) ? Strings.TypeEmojis[chargeMove.Type.ToLower()] : chargeMove.Type;
                eb.Description += $"**Charge Move:** {chargeMove.Name} ({chargeMove.Type})\r\n";
            }

            eb.Description += $"**Location:** {Math.Round(pokemon.Latitude, 5)},{Math.Round(pokemon.Longitude, 5)}";
            eb.ImageUrl     = string.Format(Strings.GoogleMapsStaticImage, pokemon.Latitude, pokemon.Longitude) + $"&key={_config.GmapsKey}";
            eb.Footer       = new DiscordEmbedBuilder.EmbedFooter
            {
                Text = $"versx | {DateTime.Now}"
            };
            var embed = eb.Build();

            return(embed);
        }