Beispiel #1
0
        /// <summary>
        /// Запрос данных и возврат их в качестве поля
        /// </summary>
        /// <returns></returns>
        public async Task <DiscordEmbedBuilder> AffixRequest()
        {
            var embed = new DiscordEmbedBuilder
            {
                Color = new DiscordColor("#3AE6DB"),
                Title = "Модификаторы эпохальных подземелий",
                //Description = "11",
                Timestamp = DateTime.UtcNow
            };
            var plusAddiction   = new[] { " (+2) ", " (+4) ", " (+7) ", " (+10) " };
            var responseContent =
                RioRequest.Request("https://raider.io/api/v1/mythic-plus/affixes?region=eu&locale=ru").Result;

            // Собираем ответ
            using var reader = new StreamReader(await responseContent.ReadAsStreamAsync());
            var  serializedAffixes = Affixes.FromJson(await reader.ReadToEndAsync());
            long affix4            = 0;
            long affix7            = 0;

            for (var i = 0; i < serializedAffixes.AffixDetails.Length; i++)
            {
                var namePlusAffixLevel = plusAddiction[i] + serializedAffixes.AffixDetails[i].Name;
                embed.AddField(namePlusAffixLevel, serializedAffixes.AffixDetails[i].Description);
                switch (i)
                {
                case 1: affix4 = serializedAffixes.AffixDetails[i].Id; break;

                case 2: affix7 = serializedAffixes.AffixDetails[i].Id; break;
                }
            }
            embed.WithFooter("by Raider.IO", "https://cdnassets.raider.io/images/brand/Mark_2ColorWhite.png");
            embed.AddField("Модификаторы следующей недели:", NextWeekAffix(affix4, affix7));
            return(embed);
        }
Beispiel #2
0
        public async Task <DiscordEmbedBuilder> MythicPlusRequest(string name, string[] serverNameInput)
        {
            string serverName;

            try
            { serverName = ServerName.RioServerNameConvert(serverNameInput); }
            catch (Exception e)
            {
                return(new DiscordEmbedBuilder
                {
                    Color = new DiscordColor("#3AE6DB"),
                    Title = "Ошибка запроса",
                    Description = e.Message,
                    Timestamp = DateTime.UtcNow,
                });
            }

            var encodedName = HttpUtility.UrlPathEncode(name.First().ToString().ToUpper() + name.Substring(1));

            var responseContent =
                RioRequest.Request(
                    "https://raider.io/api/v1/characters/profile?region=eu&realm="
                    + serverName + "&name=" + encodedName
                    + "&fields=mythic_plus_scores_by_season%3Acurrent%2Cmythic_plus_best_runs%3Aall").Result;

            using var reader = new StreamReader(await responseContent.ReadAsStreamAsync());
            var serializedStats = MythicPlusStats.FromJson(await reader.ReadToEndAsync());
            DiscordEmbedBuilder embed;

            try
            {
                embed = CreateEmbed(serializedStats);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            return(embed);
        }