Example #1
0
        public async void GetPlayer_Psn_AutoDetect_Should_Return_Correct_Page()
        {
            var result = await _client.GetPlayerAsync(psnUsername);

            Assert.Equal(psnUrl, result.ProfileUrl);
            Assert.Equal(Platform.Psn, result.Platform);
        }
Example #2
0
        public async void GetPlayer_Psn_AutoDetect_Should_Return_Correct_Private_Page_With_Other_Platforms_Listed()
        {
            var result = await Client.GetPlayerAsync(cootesPsnUsername);

            Assert.Equal(cootesPsnUrl, result.ProfileUrl);
            Assert.Equal(Platform.Psn, result.Platform);
            Assert.True(result.IsProfilePrivate);
            Assert.Contains(result.Aliases, x => x.Platform == Platform.Pc);
            var otherProfiles = await Client.GetOtherProfilesAsync(result);

            Assert.NotEmpty(otherProfiles);
            Assert.Contains(otherProfiles, x => x.ProfileUrl == cootesPcUrl);
            Assert.Contains(otherProfiles, x => x.Username == cootesPcUsername);
        }
 public async void GetPlayer_Username_Only_Overload_With_Battletag_Argument_And_No_Pc_Region_Should_Throw_Exception()
 {
     using (var owClient = new OverwatchClient(Platform.Psn, Platform.Xbl))
     {
         await Assert.ThrowsAsync <ArgumentException>(async() => await owClient.GetPlayerAsync("moiph#1288"));
     }
 }
        public async void GetPlayer_Username_Only_Overload_With_Battletag_Argument_Returns_Valid_Page()
        {
            using (var owClient = new OverwatchClient())
            {
                var result = await owClient.GetPlayerAsync("moiph#1288");

                Assert.Equal("https://playoverwatch.com/en-gb/career/pc/moiph-1288", result.ProfileUrl);
            }
        }
Example #5
0
        public async void GetPlayer_Username_Only_Overload_With_Battletag_Argument_And_Config_With_No_Pc_Region_Should_Throw_Exception()
        {
            var config = new OverwatchConfig.Builder()
                         .WithPlatforms(Platform.Psn, Platform.Xbl);
            var mockWebClient = new MockProfileClient(config);

            using (var owClient = new OverwatchClient(mockWebClient, config))
            {
                await Assert.ThrowsAsync <ArgumentException>(async() => await owClient.GetPlayerAsync("SirDoombox#2603"));
            }
        }
Example #6
0
        public async void GetPlayer_Username_Only_Overload_With_Battletag_Argument_Returns_Valid_Page()
        {
            var config        = new OverwatchConfig.Builder().Default();
            var mockWebClient = new MockProfileClient(config);

            using (var owClient = new OverwatchClient(mockWebClient, config))
            {
                var result = await owClient.GetPlayerAsync("SirDoombox#2603");

                Assert.Equal("https://playoverwatch.com/en-gb/career/pc/eu/SirDoombox-2603", result.ProfileUrl);
            }
        }
Example #7
0
        public async Task Overwatch(CommandContext ctx, string battletag, [RemainingText] string query)
        {
            if (string.IsNullOrWhiteSpace(battletag))
            {
                await BotServices.SendErrorEmbedAsync(ctx, ":warning: Battletag is required! Try **.ow CriticalFlaw#11354** (case-sensitive)");
            }
            else
            {
                var overwatch = new OverwatchClient();
                var player    = await overwatch.GetPlayerAsync(battletag);

                if (player == null)
                {
                    await BotServices.SendErrorEmbedAsync(ctx, ":mag: Player not found! Remember, battletags are case-sensitive.");
                }
                else
                {
                    await ctx.TriggerTypingAsync();

                    var output = new DiscordEmbedBuilder()
                                 .WithTitle(player.Username)
                                 .AddField("Level", player.PlayerLevel.ToString(), true)
                                 .AddField("Competitive", player.CompetitiveRank.ToString(), true)
                                 .AddField("Platform", player.Platform.ToString().ToUpper(), true)
                                 .AddField("Achievements", player.Achievements.Count.ToString(), true)
                                 .WithThumbnailUrl(player.ProfilePortraitUrl)
                                 .WithUrl(player.ProfileUrl)
                                 .WithColor(DiscordColor.Gold);
                    // Add Casual or Competitive stats if a query is present
                    switch (query.ToUpperInvariant())
                    {
                    case "CASUAL":
                        output.AddField("Healing Done", player.CasualStats.GetStatExact("All Heroes", "Assists", "Healing Done").Value.ToString(), true);
                        output.WithFooter("Casual stats shown are for All Heroes");
                        break;

                    case "COMP":
                    case "COMPETITIVE":
                        output.AddField("Healing Done", player.CompetitiveStats.GetStatExact("All Heroes", "Assists", "Healing Done").Value.ToString(), true);
                        output.WithFooter("Competitive stats shown are for All Heroes");
                        break;

                    default:
                        // Do nothing...
                        break;
                    }
                    await ctx.RespondAsync(embed : output.Build());
                }
            }
        }
Example #8
0
        public async Task OverwatchPlayer(string gamer)
        {
            var    config   = GuildConfig.GetOrCreateConfig(Context.Guild.Id);
            var    owClient = new OverwatchClient();
            Player player   = await owClient.GetPlayerAsync(gamer);

            var embed = new EmbedBuilder();

            embed.WithTitle($"{gamer}'s Overwatch \"stats\"!");
            embed.AddField("Level", player.PlayerLevel);
            embed.AddField("Platform", player.Platform);
            embed.AddField("Profile URL", player.ProfileUrl);
            embed.AddField("Achievements", player.Achievements.Count);
            embed.WithThumbnailUrl(player.CompetitiveRankImageUrl);
            embed.WithFooter(Bot.Utilities.GetFormattedLocaleMsg("CommandFooter", Context.User.Username));
            embed.WithColor(new Color(config.EmbedColour1, config.EmbedColour2, config.EmbedColour3));

            await ReplyAsync("", false, embed);
        }
        private async void Login_Click(object sender, RoutedEventArgs e) // this code is kinda spaghetti but it handles the login pretty well so imma leave it
        {
            var btn = sender as Button;

            if (Scorecard.UserLoggedIn)
            {
                Scorecard.Player       = null;
                Scorecard.UserLoggedIn = false;

                InfoBox_Modify("Logged Out");
                btn.Content = "Login";
                return;
            }

            try
            {
                OverwatchClient owClient = new OverwatchClient();
                InfoBox_Modify("Logging in...");
                Scorecard.Player = await owClient.GetPlayerAsync(Settings.Default.BattleTag, Platform.Pc);
            }
            catch (Exception ex)
            {
                InfoBox_Modify("Error: " + ex.Message, Brushes.Red);
                return;
            }


            if (Scorecard.Player.IsProfilePrivate)
            {
                InfoBox_Modify("Error: Private Profile", Brushes.Red);
            }
            else
            {
                InfoBox_Modify("Login Successful", Brushes.Green);
                Scorecard.CurrentSR    = Scorecard.Player.CompetitiveRank;
                Scorecard.UserLoggedIn = true;
                btn.Content            = "Logout";
            }
        }
Example #10
0
        public static async Task <Player> GetPlayer(string btag)
        {
            Player player = await owClient.GetPlayerAsync(btag);

            return(await owClient.GetPlayerAsync(btag));
        }