예제 #1
0
        private async Task CMD_Token()
        {
            try
            {
                this.Context.Logger.LogInformation($"Token Command requested by {this.Context.Message.Author}");
                WoWToken token = await this.Context.API.WoWTokenLookup();

                var eb = new EmbedBuilder(); // Build embedded discord msg
                eb.WithTitle("WoW Token");
                eb.AddField("Quote", $"• Price: {token.Price}\n• Last Updated: {token.Last_Updated}", false);
                eb.WithFooter($"{this.Context.Prefix}armory help | https://github.com/imerzan/ArmoryBot"); // Display help information in footer
                eb.WithThumbnailUrl(Globals.WowTokenIconUrl);
                await this.Context.Message.Channel.SendMessageAsync("", false, eb.Build());                // Send embed message to requestor
            }
            catch (Exception ex)
            {
                await this.SendErrorResponse(ex.ToString());
            }
        }
예제 #2
0
        public async Task <WoWToken> WoWTokenLookup() // Gets current WoW token price and returns to requestor
        {
            try
            {
                var          info     = new WoWToken();
                WoWTokenJson wowtoken = await this.Call($"https://{this.Config.Region}.api.blizzard.com/data/wow/token/index", Namespace.Dynamic, typeof(WoWTokenJson));

                info.Price = (wowtoken.Price / 10000).ToString("N0");
                DateTime origin     = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                DateTime lastupdate = origin.AddMilliseconds(wowtoken.LastUpdatedTimestamp).ToUniversalTime();
                TimeSpan span       = DateTime.Now.ToUniversalTime() - lastupdate;
                info.Last_Updated = $"{lastupdate} ({span.Minutes} minutes ago)";
                return(info);
            }
            catch
            {
                await this.CheckToken(); // Make sure *access* token is valid

                throw;                   // Re-throw exception, will be caught in calling function
            }
        }