Exemplo n.º 1
0
        public async Task CompareStats(params string[] Players)
        {
            if (Players == null)
            {
                await ReplyAsync(Strings.PlayersNamesRequired);

                return;
            }
            var players = await PubgHelper.GetPlayersByName(Players);

            if (players.Count() == 0)
            {
                await ReplyAsync(Strings.PlayerNotFound);

                return;
            }
            else
            {
                foreach (var player in players)
                {
                    var playerRep = new PlayerRepository(player);
                    await playerRep.GetPlayerStats();

                    player.DuoStats   = playerRep.Player.DuoStats;
                    player.SquadStats = playerRep.Player.SquadStats;
                    player.SoloStats  = playerRep.Player.SoloStats;
                }
                await ReplyAsync(embed : EmbedHelper.GetCompare($"Compare", players, Color.Red));
            }
        }
Exemplo n.º 2
0
        void GetMatches(PubgPlayer player)
        {
            var list = new List <PlayerMatch>();

            using (var con = new PubgDbContext())
            {
                foreach (var matchId in player.MatchIds)
                {
                    var matchFound = con.Matches.Find(matchId);
                    if (matchFound == null)
                    {
                        matchFound = PubgHelper.GetPubgMatch(matchId);
                    }
                    else
                    {
                        con.Matches.Attach(matchFound);
                    }
                    list.Add(new PlayerMatch()
                    {
                        Player = this, Match = matchFound
                    });
                }
                Matches = list;
            }
        }
Exemplo n.º 3
0
        public async Task GetMatches(PubgPlayer player = null)
        {
            if (Player.Matches == null)
            {
                Player.Matches = new List <PlayerMatch>();
            }

            if (Player.LastMatchUpdate == null || Player.LastMatchUpdate < DateTime.Now.AddMinutes(-Config.PlayerRefreshTime))
            {
                if (player == null)
                {
                    player = await PubgHelper.GetPubgPlayer(Player.Id);
                }

                foreach (var matchId in player.MatchIds.Take(Config.NumberOfRecentMatches))
                {
                    Match matchFound = null;

                    matchFound = await PubgDB.Matches.Where(m => m.Id == matchId).FirstOrDefaultAsync();

                    if (matchFound == null)
                    {
                        matchFound = await PubgHelper.GetPubgMatch(matchId);
                    }

                    if (!Player.Matches.Any(m => m.MatchId == matchFound.Id))
                    {
                        Player.Matches.Add(new PlayerMatch()
                        {
                            Player = Player, Match = matchFound
                        });
                        await PubgHelper.SavePubgMatch(matchFound);

                        PubgDB.Attach(matchFound);
                    }
                }
                Player.LastMatchUpdate = DateTime.Now;
            }
        }
Exemplo n.º 4
0
        public async Task GetPlayerByName(string name)
        {
            Player = await PubgDB.Players
                     .Where(p => p.Name == name)
                     .Include(p => p.DuoStats)
                     .Include(p => p.SoloStats)
                     .Include(p => p.SquadStats)
                     .Include(p => p.Matches)
                     .FirstOrDefaultAsync();


            if (Player == null)
            {
                var onlinePlayer = await PubgHelper.GetPubgPlayer(name : name);

                if (onlinePlayer != null)
                {
                    Player = new Player()
                    {
                        Name = name, Id = onlinePlayer.Id
                    };
                    await GetPlayerStats();
                    await GetMatches(onlinePlayer);

                    PubgDB.Players.Add(Player);
                }
            }
            else
            {
                await GetPlayerStats();
                await GetMatches();

                PubgDB.Players.Update(Player);
            }
            await PubgDB.SaveChangesAsync();
        }