コード例 #1
0
        private async Task CMD_Armory(string identity, LookupType type) // Main Armory Lookup
        {
            try
            {
                this.Context.Logger.LogInformation($"Armory Command requested by {this.Context.Message.Author}");
                string[]   character = identity.Split(new[] { '-' }, 2);                                      // Split CharacterName-Realm. Example: splits Frostchiji-Wyrmrest-Accord into [0]Frostchiji [1]Wyrmrest-Accord (keeps second dash).
                ArmoryData info      = await this.Context.API.ArmoryLookup(character[0], character[1], type); // Main Blizzard API Lookup: Name, Realm, LookupType.PVE/PVP

                var eb = new EmbedBuilder();                                                                  // Build embedded discord msg
                eb.WithTitle(info.CharInfo.Name);
                eb.WithDescription($"{info.CharInfo.ItemLevel} | {info.CharInfo.Renown}");
                switch (type)
                {
                case LookupType.PVE:
                    if (info.RaidInfo.Raids.Count == 0)
                    {
                        eb.AddField("Raids", "None", true);                                     // None placeholder if no raids logged
                    }
                    else
                    {
                        foreach (RaidItem raid in info.RaidInfo.Raids)      // Add a field for each raid
                        {
                            eb.AddField(raid.Name, raid.ToString(), true);  // inline, up to 3 columns per row
                        }
                    }
                    eb.AddField("Mythic+", info.MythicPlus, false);
                    eb.AddField("PVE Achievements", info.Achievements, false);
                    break;

                case LookupType.PVP:
                    eb.AddField("Rated PVP", info.PVPRating, false);
                    eb.AddField("PVP Stats", info.PVPStats, false);
                    eb.AddField("PVP Achievements", info.Achievements, false);
                    break;
                }
                eb.WithFooter($"{this.Context.Prefix}armory help | https://github.com/imerzan/ArmoryBot"); // Display help information in footer
                eb.WithThumbnailUrl(info.AvatarUrl);                                                       // Set Character Avatar as Thumbnail Picture
                eb.WithUrl(info.CharInfo.ArmoryUrl);                                                       // Set Armory URL (Clickable on title)
                await this.Context.Message.Channel.SendMessageAsync("", false, eb.Build());                // Send message to requestor with Armory Info (embed)
            }
            catch (Exception ex)
            {
                await this.SendErrorResponse(ex.ToString());
            }
        }
コード例 #2
0
ファイル: BlizzardAPI.cs プロジェクト: imerzan/ArmoryBot
        // ** Public Access Methods **
        //
        public async Task <ArmoryData> ArmoryLookup(string character, string realm, LookupType type) // Main Armory Lookup Method exposed to ArmoryBot.cs
        {
            try
            {
                ArmoryData           info       = new ArmoryData();                             // This method makes a number of separate API Calls. All the data is stored to this ArmoryData class to easily pass to the calling function.
                Task <CharacterInfo> CharInfo   = this.GetCharacter(character, realm);          // Gets basic character info (Player name, race, class, spec, etc.)
                Task <string>        AvatarInfo = this.GetAvatar(character, realm);             // Gets character avatar image URL
                Task <string>        AchievInfo = this.GetAchievements(character, realm, type); // Gets Achievements
                switch (type)
                {
                case LookupType.PVE:
                    Task <RaidData> RaidInfo   = this.GetRaids(character, realm);         // Gets all raid info from Current Expansion
                    Task <string>   MythicPlus = this.GetMythicPlus(character, realm);    // Gets all M+ info from Current Season
                    await Task.WhenAll(RaidInfo, MythicPlus);                             // Wait for all PVE tasks to finish up

                    info.RaidInfo = RaidInfo.Result; info.MythicPlus = MythicPlus.Result; // Move results into class:ArmoryData
                    break;

                case LookupType.PVP:
                    Task <string> PvpInfo  = this.GetPVP(character, realm);           // Gets all rated PVP bracket info
                    Task <string> PVPStats = this.GetPvpStats(character, realm);      // Gets all PVP Character Stats info (Versatility,etc.)
                    await Task.WhenAll(PvpInfo, PVPStats);                            // Wait for all PVP tasks to finish up

                    info.PVPRating = PvpInfo.Result; info.PVPStats = PVPStats.Result; // Move results into class:ArmoryData
                    break;
                }
                await Task.WhenAll(CharInfo, AvatarInfo, AchievInfo);                                                       // Wait for all other tasks to finish up

                info.CharInfo = CharInfo.Result; info.AvatarUrl = AvatarInfo.Result; info.Achievements = AchievInfo.Result; // Move results into class:ArmoryData
                return(info);                                                                                               // Return class:ArmoryData to calling function
            }
            catch
            {
                await this.CheckToken(); // Make sure token is valid

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