コード例 #1
0
        public async Task Conversion(CommandContext ctx,
                                     [Description("Abbreviation of the currency to be converted")] string abbreviation,
                                     [Description("Amount of cryptocurrency")] double amount,
                                     [Description("Abbreviation of the currency to convert to")] string convert)
        {
            var api = new CoinmarketcapAPI();

            try
            {
                string json = api.PriceConversion(abbreviation, amount, convert);

                //Try to get currency
                var conversion = JsonConvert.DeserializeObject <Conversion>(json);

                var embed = new DiscordEmbedBuilder()
                {
                    Author = new DiscordEmbedBuilder.EmbedAuthor
                    {
                        IconUrl = $"https://s2.coinmarketcap.com/static/img/coins/64x64/{conversion.Data.Id}.png",
                        Name    = conversion.Data.Name
                    },

                    Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail
                    {
                        Url    = $"https://s2.coinmarketcap.com/static/img/coins/64x64/{conversion.Data.Id}.png",
                        Height = 100,
                        Width  = 100
                    },

                    Title     = $"Price for {DiscordText.BoldUnderLine(amount.ToString())} {DiscordText.Bold(conversion.Data.Symbol)}",
                    Color     = DiscordColor.Black,
                    Timestamp = DateTime.Now,
                };

                embed.AddField(
                    DiscordText.Bold($"({conversion.Data.Symbol}/{convert.ToUpper()})"),
                    DiscordText.SingleLineCode($"{Numbers.EditToReadableNumber(conversion.Data.Quote[convert.ToString().ToUpper()].Price)} {convert.ToUpper()}"),
                    true);

                await ctx.Channel.SendMessageAsync(embed : embed);
            }
            catch (WebException)
            {
                await Prompt.SendPromptAsync(ctx.Channel, ctx.User, "Type the correct currency abbreviation and non negative amount");
            }
            catch (Exception ex)
            {
                BotLoging.PrintError(ctx.Client, ctx.User, ex);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
0
        public async Task Earn(CommandContext ctx)
        {
            var duration = TimeSpan.FromSeconds(600);

            try
            {
                var earns      = Headlines.Earn;
                var embedsList = new List <DiscordEmbed>();

                if (earns == null)
                {
                    throw new Exception("Earn companies has not been uploaded yet");
                }

                for (int j = 0; j < earns.Count; j++)
                {
                    embedsList.Add(
                        new DiscordEmbedBuilder
                    {
                        Author = new DiscordEmbedBuilder.EmbedAuthor
                        {
                            Name    = earns[j].Name + " " + earns[j].Symbol,
                            IconUrl = earns[j].IconUrl,
                            Url     = earns[j].Url
                        },

                        Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail
                        {
                            Url = earns[j].IconUrl,
                        },

                        Footer = new DiscordEmbedBuilder.EmbedFooter
                        {
                            Text = $"Page {j + 1} / {earns.Count}"
                        },

                        Description = earns[j].Description,
                        ImageUrl    = earns[j].ImageUrl,
                        Color       = DiscordColor.Purple
                    }
                        .AddField(DiscordText.BoldUnderLine("Campaign status:"), (earns[j].Live) ? DiscordText.Bold(DiscordText.MultyLineCode("LIVE")) : DiscordText.Bold(DiscordText.MultyLineCode("DONE")))
                        .Build());
                }

                int messageIterator = 0;

                var message = await ctx.Channel.SendMessageAsync(embed : embedsList[messageIterator]).ConfigureAwait(false);

                var toFirstEmoji    = DiscordEmoji.FromName(ctx.Client, ":one:");
                var arrowLeftEmoji  = DiscordEmoji.FromName(ctx.Client, ":arrow_backward:");
                var arrowRightEmoji = DiscordEmoji.FromName(ctx.Client, ":arrow_forward:");

                await message.CreateReactionAsync(toFirstEmoji).ConfigureAwait(false);

                await message.CreateReactionAsync(arrowLeftEmoji).ConfigureAwait(false);

                await message.CreateReactionAsync(arrowRightEmoji).ConfigureAwait(false);

                await Task.Delay(400);

                var interactivity = ctx.Client.GetInteractivity();

                while (true)
                {
                    var reactionResult = await interactivity.WaitForReactionAsync(
                        x => x.Message == message && (
                            x.Emoji == toFirstEmoji |
                            x.Emoji == arrowLeftEmoji |
                            x.Emoji == arrowRightEmoji), duration)
                                         .ConfigureAwait(false);

                    if (reactionResult.Result == null)
                    {
                        break;
                    }

                    if (reactionResult.Result.Emoji == toFirstEmoji)
                    {
                        messageIterator = 0;

                        await message.DeleteReactionAsync(toFirstEmoji, reactionResult.Result.User).ConfigureAwait(false);
                    }
                    else if (reactionResult.Result.Emoji == arrowLeftEmoji)
                    {
                        _ = (messageIterator > 0) ? messageIterator-- : messageIterator = 9;

                        await message.DeleteReactionAsync(arrowLeftEmoji, reactionResult.Result.User).ConfigureAwait(false);
                    }
                    else if (reactionResult.Result.Emoji == arrowRightEmoji)
                    {
                        _ = (messageIterator < 9) ? messageIterator++ : messageIterator = 0;

                        await message.DeleteReactionAsync(arrowRightEmoji, reactionResult.Result.User).ConfigureAwait(false);
                    }

                    await message.ModifyAsync(embedsList[messageIterator]).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                BotLoging.PrintError(ctx.Client, ctx.User, ex);
            }
        }