Beispiel #1
0
        public async Task StatsPSNPlunder([Remainder] string userName)
        {
            var jsonAsString =
                await ApiProcessor.GetUser(
                    $"https://api.tracker.gg/api/v2/warzone/standard/profile/psn/{userName}");

            var apiData = JsonConvert.DeserializeObject <ModerWarfareApiOutput>(jsonAsString);

            var name     = apiData.Data.PlatformInfo.PlatformUserHandle;
            var pfp      = apiData.Data.PlatformInfo.AvatarUrl;
            var levelImg = apiData.Data.Segment[0].Stats.Level.Metadata.IconUrl;

            var client   = new ModernWarfareClient();
            var allStats = await client.GetWarzoneStatsAsync(Platform.PSN, userName);

            var plunderStats = allStats.PlunderStats;

            var converter         = new HtmlConverter();
            var generationStrings = new StatsGenerationFiles();

            string css  = generationStrings.WarzoneCss(allStats.LifetimeStats.LevelProgression.DisplayValue);
            string html = String.Format(generationStrings.PlunderHtml(name, pfp, plunderStats.TimePlayed.DisplayValue, plunderStats.GamesPlayed.DisplayValue, levelImg.ToString(),
                                                                      allStats.LifetimeStats.Level.DisplayValue, allStats.LifetimeStats.LevelProgression.DisplayValue, plunderStats.KdRatio.DisplayValue, plunderStats.Kills.DisplayValue, plunderStats.WlRatio.DisplayValue, plunderStats.Wins.DisplayValue, plunderStats.Deaths.DisplayValue, plunderStats.AvarageLife.DisplayValue, plunderStats.Score.DisplayValue, plunderStats.ScorePerGame.DisplayValue, plunderStats.ScorePerMinute.DisplayValue, plunderStats.Downs.DisplayValue, plunderStats.Cash.DisplayValue,
                                                                      plunderStats.Contracts.DisplayValue));

            int width = 520;
            var bytes = converter.FromHtmlString(css + html, width, CoreHtmlToImage.ImageFormat.Png);

            File.WriteAllBytes("Resources/PSNPlunderStats.png", bytes);
            await Context.Channel.SendFileAsync(new MemoryStream(bytes), "Resources/PSNPlunderStats.png");
        }
Beispiel #2
0
        public async Task StatsBNWarzone([Remainder] string userName)
        {
            if (userName.Contains("#"))
            {
                userName = userName.Replace("#", "%23");
            }
            else
            {
                var errorEmbed = new EmbedBuilder();
                errorEmbed.WithTitle("Ouch! An error occurred.");
                errorEmbed.WithDescription("Invalid BattleNet username.");
                errorEmbed.WithColor(255, 0, 0);
                await Context.Channel.SendMessageAsync("", false, errorEmbed.Build());

                return;
            }

            var jsonAsString =
                await ApiProcessor.GetUser(
                    $"https://api.tracker.gg/api/v2/warzone/standard/profile/battlenet/{userName}");

            var apiData = JsonConvert.DeserializeObject <ModerWarfareApiOutput>(jsonAsString);

            var name      = apiData.Data.PlatformInfo.PlatformUserHandle;
            var pfp       = apiData.Data.PlatformInfo.AvatarUrl;
            var playTime  = apiData.Data.Segment[0].Stats.TimePlayed.DisplayValue;
            var matches   = apiData.Data.Segment[0].Stats.GamesPlayed.DisplayValue;
            var levelImg  = apiData.Data.Segment[0].Stats.Level.Metadata.IconUrl;
            var level     = apiData.Data.Segment[0].Stats.Level.DisplayValue;
            var levelper  = apiData.Data.Segment[0].Stats.LevelProgression.DisplayValue;
            var kd        = apiData.Data.Segment[0].Stats.KdRatio.DisplayValue;
            var kills     = apiData.Data.Segment[0].Stats.Kills.DisplayValue;
            var WinPer    = apiData.Data.Segment[0].Stats.WlRatio.DisplayValue;
            var wins      = apiData.Data.Segment[0].Stats.Wins.DisplayValue;
            var deaths    = apiData.Data.Segment[0].Stats.Deaths.DisplayValue;
            var avgLife   = apiData.Data.Segment[0].Stats.AverageLife.DisplayValue;
            var score     = apiData.Data.Segment[0].Stats.Score.DisplayValue;
            var scoreGame = apiData.Data.Segment[0].Stats.ScorePerGame.DisplayValue;
            var top5      = apiData.Data.Segment[0].Stats.TopFive.DisplayValue;
            var top10     = apiData.Data.Segment[0].Stats.TopTen.DisplayValue;
            var downs     = apiData.Data.Segment[0].Stats.Downs.DisplayValue;
            var contracts = apiData.Data.Segment[0].Stats.Contracts.DisplayValue;


            var    converter         = new HtmlConverter();
            var    generationStrings = new StatsGenerationFiles();
            string css  = generationStrings.WarzoneCss(levelper);
            string html = String.Format(generationStrings.WarzoneHtml(name, pfp, playTime, matches, levelImg.ToString(),
                                                                      level, levelper, kd, kills, WinPer, wins, deaths, avgLife, score, top5, top10, downs, scoreGame,
                                                                      contracts));
            int width = 520;
            var bytes = converter.FromHtmlString(css + html, width, CoreHtmlToImage.ImageFormat.Png);

            File.WriteAllBytes("Resources/BNWarzoneStats.png", bytes);
            await Context.Channel.SendFileAsync(new MemoryStream(bytes), "Resources/BNWarzoneStats.png");
        }
Beispiel #3
0
        public async Task StatsBattleNetBattleRoyale([Remainder] string arg = "")
        {
            SocketUser target      = null;
            var        mentionUser = Context.Message.MentionedUsers.FirstOrDefault();

            target = mentionUser ?? Context.User;

            var account       = UserAccounts.GetAccount(target);
            var serverAccount = ServerAccounts.GetAccount(Context.Guild);

            if (string.IsNullOrEmpty(account.GameUsername))
            {
                var errorEmbed = new EmbedBuilder();
                errorEmbed.WithTitle("Ouch! An error occurred.");
                errorEmbed.WithDescription($"User not registered.");
                errorEmbed.WithColor(255, 0, 0);
                await Context.Channel.SendMessageAsync("", false, errorEmbed.Build());

                return;
            }



            var jsonAsString = await ApiProcessor.GetUser($"https://api.tracker.gg/api/v2/warzone/standard/profile/{account.Platform}/{account.GameUsername}");

            var apiData = JsonConvert.DeserializeObject <ModerWarfareApiOutput>(jsonAsString);

            var name     = apiData.Data.PlatformInfo.PlatformUserHandle;
            var pfp      = apiData.Data.PlatformInfo.AvatarUrl;
            var levelImg = apiData.Data.Segment[0].Stats.Level.Metadata.IconUrl;

            Platform platform = Platform.BattleNet;

            if (account.Platform == "atvi")
            {
                platform = Platform.Activision;
            }
            else if (account.Platform == "psn")
            {
                platform = Platform.PSN;
            }
            else if (account.Platform == "xbl")
            {
                platform = Platform.XBL;
            }

            var client   = new ModernWarfareClient();
            var allStats = await client.GetWarzoneStatsAsync(platform, account.GameUsername);

            var battleRoyalStats = allStats.BattleRoyalStats;

            var converter         = new HtmlConverter();
            var generationStrings = new StatsGenerationFiles();

            string css  = generationStrings.WarzoneCss(allStats.LifetimeStats.LevelProgression.DisplayValue);
            string html = String.Format(generationStrings.BattleRoyaleHtml(name, pfp,
                                                                           battleRoyalStats.TimePlayed.DisplayValue, battleRoyalStats.GamesPlayed.DisplayValue,
                                                                           levelImg.ToString(), allStats.LifetimeStats.Level.DisplayValue,
                                                                           allStats.LifetimeStats.LevelProgression.DisplayValue, battleRoyalStats.KdRatio.DisplayValue,
                                                                           battleRoyalStats.Kills.DisplayValue, battleRoyalStats.WlRatio.DisplayValue,
                                                                           battleRoyalStats.Wins.DisplayValue, battleRoyalStats.Deaths.DisplayValue,
                                                                           battleRoyalStats.AvarageLife.DisplayValue, battleRoyalStats.Score.DisplayValue,
                                                                           battleRoyalStats.Top5.DisplayValue, battleRoyalStats.Top10.DisplayValue,
                                                                           battleRoyalStats.Downs.DisplayValue, battleRoyalStats.Top25.DisplayValue,
                                                                           battleRoyalStats.Contracts.DisplayValue));

            int width = 520;
            var bytes = converter.FromHtmlString(css + html, width, CoreHtmlToImage.ImageFormat.Png);

            File.WriteAllBytes("Resources/BattleRoyaleStats.png", bytes);
            await Context.Channel.SendFileAsync(new MemoryStream(bytes), "Resources/BattleRoyaleStats.png");
        }