private string GetEditedPercentes(List <Model.Coinmarketcap.Data> datas, string criteria) { string result = string.Empty; List <double> percentes = new List <double>(); switch (criteria) { case "change1h": datas.ForEach(x => percentes.Add(x.Quote.First().Value.Change1h)); break; case "change24h": datas.ForEach(x => percentes.Add(x.Quote.First().Value.Change24h)); break; case "change7d": datas.ForEach(x => percentes.Add(x.Quote.First().Value.Change7d)); break; } foreach (var item in percentes) { result += item > 0 ? DiscordText.GreenLine($"{Numbers.EditToReadablePercent(item)}% ▲") : DiscordText.RedLine($"{Numbers.EditToReadablePercent(item)}% ▼"); } return(result); }
public async Task Crypto(CommandContext ctx, [Description("Abbreviation of a specific cryptocurrency")] string abbreviation) { var api = new CoinmarketcapAPI(); try { string json = api.QuotesLatest(abbreviation); //Try to get currency var cryptocurrency = JsonConvert.DeserializeObject <Cryptocurrency>(json); var id = cryptocurrency.Data.First().Value.Id; var rank = cryptocurrency.Data.First().Value.Rank; var name = cryptocurrency.Data.First().Value.Name; var slug = cryptocurrency.Data.First().Value.Slug; var symbol = cryptocurrency.Data.First().Value.Symbol; var price = cryptocurrency.Data.First().Value.Quote["USD"].Price; var change1h = cryptocurrency.Data.First().Value.Quote["USD"].Change1h; var change24h = cryptocurrency.Data.First().Value.Quote["USD"].Change24h; var change7d = cryptocurrency.Data.First().Value.Quote["USD"].Change7d; var volume24h = cryptocurrency.Data.First().Value.Quote["USD"].Volume24h; var marketCap = cryptocurrency.Data.First().Value.Quote["USD"].MarketCap; var circulatingSupply = cryptocurrency.Data.First().Value.CirculatingSupply; var totalSupply = cryptocurrency.Data.First().Value.TotalSupply; var maxSupply = cryptocurrency.Data.First().Value.MaxSupply; var dateAdded = cryptocurrency.Data.First().Value.DateAdded; //Create Embed var embed = new DiscordEmbedBuilder() { Author = new DiscordEmbedBuilder.EmbedAuthor { IconUrl = $"https://s2.coinmarketcap.com/static/img/coins/64x64/{id}.png", Name = $"#{rank} - {name} ({symbol})", Url = $"https://coinmarketcap.com/currencies/{slug}/" }, Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = $"https://s2.coinmarketcap.com/static/img/coins/64x64/{id}.png", Height = 100, Width = 100 }, Timestamp = cryptocurrency.Data.First().Value.LastUpdated, Title = DiscordText.Bold($"Price {DiscordText.UnderLine($"${Numbers.EditToReadableNumber(price)}")}"), }; //Price info embed.AddField( $"Change{DiscordText.BoldItalic("(1h)")}", change1h > 0 ? DiscordText.GreenLine($"{Numbers.EditToReadablePercent(change1h)}% ▲") : DiscordText.RedLine($"{Numbers.EditToReadablePercent(change1h)}% ▼"), true); embed.AddField( $"Change{DiscordText.BoldItalic("(24h)")}", change24h > 0 ? DiscordText.GreenLine($"{Numbers.EditToReadablePercent(change24h)}% ▲") : DiscordText.RedLine($"{Numbers.EditToReadablePercent(change24h)}% ▼"), true); embed.AddField( $"Change{DiscordText.BoldItalic("(7d)")}", change7d > 0 ? DiscordText.GreenLine($"{Numbers.EditToReadablePercent(change7d)}% ▲") : DiscordText.RedLine($"{Numbers.EditToReadablePercent(change7d)}% ▼"), true); embed.AddField( $"Volume{DiscordText.BoldItalic("(24h)")}", DiscordText.Bold($"${Numbers.EditToReadableNumber(volume24h)}"), true); embed.AddField($"⠀", "⠀", true); embed.AddField( $"Market cap", DiscordText.Bold($"${Numbers.EditToReadableNumber(marketCap)}"), true); embed.AddField( $"Circulating Supply", DiscordText.Bold(DiscordText.SingleLineCode($"{Numbers.EditToReadableNumber(circulatingSupply)} {symbol}")), true); embed.AddField( $"Total Supply", DiscordText.Bold(DiscordText.SingleLineCode($"{Numbers.EditToReadableNumber(totalSupply)} {symbol}")), true); embed.AddField( $"Max Supply", DiscordText.Bold(DiscordText.SingleLineCode($"{Numbers.EditToReadableNumber(maxSupply)} {symbol}")), true); //Coin info string info = $"{DiscordText.Bold("Date added:")} {dateAdded.ToShortDateString()}"; if (cryptocurrency.Data.First().Value.Platform != null) { info += Environment.NewLine + DiscordText.Bold("Platform: ") + DiscordText.SingleLineCode(cryptocurrency.Data.First().Value.Platform.Name); } embed.AddField(DiscordText.BoldUnderLine($"Coin data:"), info); //Change color if (change7d < 0) { embed.Color = DiscordColor.Red; } else if (change7d > 0) { embed.Color = DiscordColor.Green; } else { embed.Color = DiscordColor.Gray; } await ctx.Channel.SendMessageAsync(embed : embed); } catch (WebException) { await Prompt.SendPromptAsync(ctx.Channel, ctx.User, "To view the cryptocurrency rate, enter the correct abbreviated name"); } catch (Exception ex) { BotLoging.PrintError(ctx.Client, ctx.User, ex); } }