예제 #1
0
        public async Task UnwatchAsync(
            [Summary("The token address")] string address)
        {
            if (address == "all")
            {
                _tokenWatcher.RemoveAll(x => x.UserId == Context.Message.Author.Id);

                var embed = new EmbedBuilder {
                    Title       = "Address watchlist cleared",
                    Description = "All addresses have been removed from the watchlist.",
                    Color       = Color.Green
                }.WithCurrentTimestamp();;

                await this.ReplyAsync(embed : embed.Build());
            }
            else
            {
                // We can also access the channel from the Command Context.
                _tokenWatcher.RemoveAll(x => x.Address == address);

                var embed = new EmbedBuilder {
                    Title       = "Address removed from watchlist",
                    Description = $"Address **{address}** is no longer being watched.",
                    Color       = Color.Green
                }.WithCurrentTimestamp();;

                await this.ReplyAsync(embed : embed.Build());
            }
        }
예제 #2
0
        private async Task Request()
        {
            foreach (var token in this._tokenWatcher.GetWatchedTokens())
            {
                var tokenData = await this.GetTokenData(token.Address);

                var watchedToken = this._tokenWatcher.GetWatchedToken(token.Address);

                if (watchedToken == null || tokenData == null)
                {
                    continue;
                }

                if (tokenData.PriceUsd > watchedToken.TargetPrice)
                {
                    var embed = new EmbedBuilder()
                    {
                        Title       = $"{tokenData.Name} Price Alert",
                        Description =
                            $"{new TokenAddress(token.Address).AsEmbed(tokenData.Name)} has hit a price of ${tokenData.PriceUsd}.",
                    };

                    await _client.GetGuild(834456582552813588).GetTextChannel(834456582552813591)
                    .SendMessageAsync($"<@{token.UserId}>", embed: embed.Build());

                    _tokenWatcher.RemoveAll(x => x.Address == token.Address);
                }
            }
        }