Exemple #1
0
        /// <summary>
        /// Generate a Discord embed Pokemon message
        /// </summary>
        /// <param name="guildId">Guild the notification is for</param>
        /// <param name="client">Discord client</param>
        /// <param name="whConfig">Webhook config</param>
        /// <param name="alarm">Webhook alarm</param>
        /// <param name="city">City the Pokemon was found in</param>
        /// <returns>DiscordEmbedNotification object to send</returns>
        public async Task <DiscordEmbedNotification> GeneratePokemonMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city)
        {
            // If IV has value then use alarmText if not null otherwise use default. If no stats use default missing stats alarmText
            var server          = whConfig.Servers[guildId];
            var alertType       = IsMissingStats ? AlertMessageType.PokemonMissingStats : AlertMessageType.Pokemon;
            var alert           = alarm?.Alerts[alertType] ?? server.DmAlerts?[alertType] ?? AlertMessage.Defaults[alertType];
            var pokemonImageUrl = IconFetcher.Instance.GetPokemonIcon(server.IconStyle, Id, FormId, 0, Gender, Costume, false);
            var properties      = await GetProperties(new MessageProperties
            {
                Guild    = client.Guilds[guildId],
                Config   = whConfig,
                City     = city,
                ImageUrl = pokemonImageUrl,
            });

            var eb = new DiscordEmbedBuilder
            {
                Title        = DynamicReplacementEngine.ReplaceText(alert.Title, properties),
                Url          = DynamicReplacementEngine.ReplaceText(alert.Url, properties),
                ImageUrl     = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties),
                ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties),
                Description  = DynamicReplacementEngine.ReplaceText(alert.Content, properties),
                Color        = MatchesGreatLeague || MatchesUltraLeague
                    ? GetPvPColor(GreatLeague, UltraLeague, server)
                    : IV.BuildPokemonIVColor(server),
                Footer = new DiscordEmbedBuilder.EmbedFooter
                {
                    Text    = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text, properties),
                    IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl, properties)
                }
            };
            var username    = DynamicReplacementEngine.ReplaceText(alert.Username, properties);
            var iconUrl     = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties);
            var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties);

            return(await Task.FromResult(new DiscordEmbedNotification(username, iconUrl, description, new List <DiscordEmbed> {
                eb.Build()
            })));
        }