Beispiel #1
0
        public async Task Top(CommandContext ctx)
        {
            var api = new CoinmarketcapAPI();

            try
            {
                string json = api.ListingsLatest(1, 15);

                //Try to get currencies
                var cryptocurrencies = JsonConvert.DeserializeObject <Listing>(json);

                var embed = new DiscordEmbedBuilder()
                {
                    Author = new DiscordEmbedBuilder.EmbedAuthor
                    {
                        IconUrl = "https://i.ibb.co/wQ3JJ7c/podium.png",
                        Url     = "https://coinmarketcap.com/",
                        Name    = "CoinMarketCap"
                    },
                    Color     = DiscordColor.Orange,
                    Timestamp = DateTime.Now,
                    Title     = $"Top 15 cryptocurrecies by Market Cap"
                };

                embed.AddField($"{DiscordText.BoldUnderLine("# - Name")}",
                               $":first_place: **- {cryptocurrencies.DataList[0].Name} {cryptocurrencies.DataList[0].Symbol}**",
                               true);
                embed.AddField($"{DiscordText.BoldUnderLine($"Price {DiscordText.Italic("(USD)")}")}",
                               $"**${Numbers.EditToReadableNumber(cryptocurrencies.DataList[0].Quote["USD"].Price)}**",
                               true);
                embed.AddField($"{DiscordText.BoldUnderLine($"Market Cap {DiscordText.Italic("(USD)")}")}",
                               $"**${Numbers.EditToReadableNumber(cryptocurrencies.DataList[0].Quote["USD"].MarketCap)}**",
                               true);

                for (int z = 0, i = 1, k = 2; z < 7; z++, i = i + 2, k = k + 2)
                {
                    string line1 = string.Empty;
                    string line2 = string.Empty;

                    if (cryptocurrencies.DataList[i].Rank == 2 && cryptocurrencies.DataList[k].Rank == 3)
                    {
                        line1 = $":second_place: {DiscordText.Bold($"- {cryptocurrencies.DataList[i].Name} {cryptocurrencies.DataList[i].Symbol}")}";
                        line2 = $":third_place: {DiscordText.Bold($"- {cryptocurrencies.DataList[k].Name} {cryptocurrencies.DataList[k].Symbol}")}";
                    }
                    else
                    {
                        line1 = $"{DiscordText.Bold($"{cryptocurrencies.DataList[i].Rank} - {cryptocurrencies.DataList[i].Name} {cryptocurrencies.DataList[i].Symbol}")}";
                        line2 = $"{DiscordText.Bold($"{cryptocurrencies.DataList[k].Rank} - {cryptocurrencies.DataList[k].Name} {cryptocurrencies.DataList[k].Symbol}")}";
                    }

                    embed.AddField(line1, line2, true);

                    embed.AddField(
                        $"{DiscordText.Bold($"${Numbers.EditToReadableNumber(cryptocurrencies.DataList[i].Quote["USD"].Price)}")}",
                        $"{DiscordText.Bold($"${Numbers.EditToReadableNumber(cryptocurrencies.DataList[k].Quote["USD"].Price)}")}",
                        true);

                    embed.AddField(
                        $"{DiscordText.Bold($"${Numbers.EditToReadableNumber(cryptocurrencies.DataList[i].Quote["USD"].MarketCap)}")}",
                        $"{DiscordText.Bold($"${Numbers.EditToReadableNumber(cryptocurrencies.DataList[k].Quote["USD"].MarketCap)}")}",
                        true);
                }

                await ctx.Channel.SendMessageAsync(embed : embed);
            }
            catch (Exception ex)
            {
                BotLoging.PrintError(ctx.Client, ctx.User, ex);
            }
        }