public async Task <OverwatchProfileData> GetProfile(OverwatchProfile profile)
        {
            if (string.IsNullOrEmpty(profile.BattleTag))
            {
                throw new FormatException("You must type a battletag to get the information.");
            }
            var collection = new NameValueCollection
            {
                { "platform", profile.Platform.ToPlatformString() },
                { "region", profile.Region.ToRegionString() },
                { "battletag", profile.BattleTag }
            };
            var url = await _site.GetUri(new Uri($"{BaseUri}{ConvertOwUri.ToUrlString(collection)}/profile"));

            if (!url.IsSuccess)
            {
                throw new WebException("The profile you called for failed to function.");
            }

            return(JsonConvert.DeserializeObject <OverwatchProfileData>(url.JsonData));
        }
Beispiel #2
0
        public async Task View(string BattleTag = null)
        {
            using (Context.Channel.EnterTypingState())
            {
                OverwatchViewModel Data;
                OverwatchProfile   OverwatchProfile;
                User User = _Db.Users.Find(u => u.Id == Context.User.Id);

                //Default value, when command has no parameter
                if (BattleTag == null)
                {
                    if (User.OverwatchProfile == null)
                    {
                        await ReplyAsync("You currently don't have an Overwatch profile");
                        await ReplyAsync("Type !owcreate [BattleTag] to make one");

                        return;
                    }
                    OverwatchProfile = User.OverwatchProfile;
                }
                else
                {
                    //Temporary OW profile
                    OverwatchProfile = new OverwatchProfile
                    {
                        BattleTag   = BattleTag,
                        ProfileLink = "https://playoverwatch.com/en-us/career/pc/" + BattleTag.Replace("#", "-")
                    };
                }

                Data = await OverwatchScraper.GetOverwatchData(OverwatchProfile.ProfileLink, BattleTag);


                if (Data == null) //TODO: if Data == null, it might be the scraper is not working, not that the user doesn't exist
                {
                    await ReplyAsync(OverwatchProfile.BattleTag + " does not exist.");

                    return;
                }

                //The general template of an OW response
                var embedBuilder = new EmbedBuilder()
                {
                    Author = new EmbedAuthorBuilder()
                    {
                        Name = OverwatchProfile.BattleTag,
                        Url  = OverwatchProfile.ProfileLink
                    },
                    Color        = new Color(255, 176, 51),
                    Url          = OverwatchProfile.ProfileLink,
                    Title        = "View full stats",
                    Timestamp    = DateTime.Now,
                    ThumbnailUrl = Data.PortraitLink,
                    Footer       = new EmbedFooterBuilder()
                    {
                        Text = "HanzoMain™"
                    }
                };
                embedBuilder.AddField("Level", Data.Level, true);
                embedBuilder.AddField("Rank", Data.RankPoint + " - " + Data.Rank, true);
                embedBuilder.AddField("Time Played", Data.TimePlayed, true);
                embedBuilder.AddField("Games Won", Data.GamesWon, true);
                embedBuilder.ImageUrl = Data.FavouriteHeroImage;
                Embed Embed = embedBuilder.Build();

                await ReplyAsync("", false, Embed);
            }
        }