/// <summary> /// Retrieves Pubgplayer data form Pubg corp database /// </summary> /// public static async Task <PubgPlayer> GetPubgPlayer(string id = null, string name = null) { PubgPlayer player = null; try { var playerService = new PubgPlayerService(); if (id != null) { player = await playerService.GetPlayerAsync(PubgPlatform.Steam, id, Config.PubgToken); } else if (name != null) { var result = await playerService.GetPlayersAsync(PubgPlatform.Steam, new GetPubgPlayersRequest { ApiKey = Config.PubgToken, PlayerNames = new string[] { name } }); player = result.FirstOrDefault(); } } catch (Exception ss) { } return(player); }
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; } }
public async Task GetMatches(EduardoContext context, string username, PubgPlatform platform) { PubgPlayer player = await GetPlayerFromApiAsync(username, platform); if (player == null) { await context.Channel.SendMessageAsync($"No player found with username \"{username}\""); return; } List <Embed> embeds = new List <Embed>(); foreach (string matchId in player.MatchIds.Take(_pubgData.MaxMatches)) { PubgMatch match = await GetMatchFromApiAsync(matchId, platform); TimeSpan matchDuration = TimeSpan.FromSeconds(match.Duration); PubgRoster roster = match.Rosters.FirstOrDefault(r => r.Participants.Any(p => p.Stats.PlayerId == player.Id)); PubgParticipant participant = match.Rosters.SelectMany(r => r.Participants).FirstOrDefault(p => p.Stats.PlayerId == player.Id); TimeSpan timeSurvived = TimeSpan.FromSeconds(participant?.Stats.TimeSurvived ?? 0); embeds.Add(new EmbedBuilder() .WithTitle(match.GameMode.ToString()) .WithColor(Color.Orange) .AddField("Started", DateTime.Parse(match.CreatedAt), true) .AddField("Duration", $"{matchDuration.Minutes:D2}m {matchDuration.Seconds:D2}s", true) .AddField("Player Count", match.Rosters.Count(), true) .AddField("Placement", roster != null ? $"#{roster.Stats.Rank}" : "Unknown", true) .AddConditionalField("Death Reason", participant?.Stats.DeathType.ToString() ?? "Unknown", participant != null && participant.Stats.DeathType == PubgParticipantDeathType.Alive, true) .AddField("Kills", participant?.Stats.Kills.ToString() ?? "Unknown", true) .AddField("Damage Dealt", participant != null ? Math.Round(participant.Stats.DamageDealt, 2).ToString(CultureInfo.InvariantCulture) : "Unknown", true) .AddField("Headshot %", participant != null ? participant.Stats.Kills > 0 ? (participant.Stats.HeadshotKills / participant.Stats.Kills * 100).ToString() : "0%" : "Unknown", true) .AddField("Time Survived", participant != null ? $"{timeSurvived.Minutes:D2}m {timeSurvived.Seconds:D2}s" : "Unknown", true) .AddField("Distance Travelled", participant != null ? Math.Round(participant.Stats.RideDistance + participant.Stats.WalkDistance, 2).ToString(CultureInfo.InvariantCulture) : "Unknown", true) .AddField("DBNOs", participant?.Stats.DBNOs.ToString() ?? "Unknown", true) .AddField("Heals Used", participant?.Stats.Heals.ToString() ?? "Unknown", true) .AddField("Boosts Used", participant?.Stats.Boosts.ToString() ?? "Unknown", true) .WithFooter($"Match Data for {participant?.Stats.Name ?? "Unknown"} for match {matchId}", "https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/U5dt5ZoFC4oMbrTPSSvVHVfyGSakHWV_1680x8400") .Build()); } await context.SendMessageOrPaginatedAsync(embeds); }
public static async Task <PubgPlayerSeason> GetPlayerSeason(PubgPlayer player, PubgRegion region, PubgSeason season) { var cacheKey = new PlayerSeasonKey(player.Id, region, season.Id); if (cachedPlayerSeasons.ContainsKey(cacheKey) && DateTime.Now - cachedPlayerSeasons[cacheKey].Item2 < cacheTimeout) { System.Console.WriteLine("Cache hit for player season {0}", player.Name); return(cachedPlayerSeasons[cacheKey].Item1); } var pubgPlayerSeason = await _playerService.GetPlayerSeasonAsync(region, player.Id, season.Id); cachedPlayerSeasons[cacheKey] = new Tuple <PubgPlayerSeason, DateTime>(pubgPlayerSeason, DateTime.Now); return(pubgPlayerSeason); }
public async Task GetPlayer(EduardoContext context, string username, PubgPlatform platform) { PubgPlayer player = await GetPlayerFromApiAsync(username, platform); if (player == null) { await context.Channel.SendMessageAsync($"No player found with username \"{username}\""); return; } await context.Channel.SendMessageAsync(embed : new EmbedBuilder() .WithTitle(player.Name) .WithColor(Color.Orange) .WithDescription($"You can view recent matches for this player using `{Constants.CMD_PREFIX}pubg matches {player.Name} {platform}`") .AddField("Account ID", player.Id, true) .WithFooter($"Player Profile for {player.Name}", "https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/U5dt5ZoFC4oMbrTPSSvVHVfyGSakHWV_1680x8400") .Build()); }
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; } }