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 virtual async Task <IEnumerable <PubgPlayer> > GetPlayersAsync(PubgPlatform platform, GetPubgPlayersRequest filter, CancellationToken cancellationToken = default(CancellationToken)) { var url = RequestBuilder.BuildRequestUrl(Api.Players.PlayersEndpoint(platform), filter); var apiKey = string.IsNullOrEmpty(filter.ApiKey) ? ApiKey : filter.ApiKey; var collectionJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey).ConfigureAwait(false); return(JsonConvert.DeserializeObject <IEnumerable <PubgPlayer> >(collectionJson, new JsonApiSerializerSettings())); }
public async Task <PubgMatchSample> GetMatchSamplesAsync(PubgPlatform platform, GetSamplesRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var url = RequestBuilder.BuildRequestUrl(Api.Samples.SamplesEndpoint(platform), request); var apiKey = string.IsNullOrEmpty(request.ApiKey) ? ApiKey : request.ApiKey; var collectionJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey).ConfigureAwait(false); return(JsonConvert.DeserializeObject <IEnumerable <PubgMatchSample> >(collectionJson, new JsonApiSerializerSettings()).FirstOrDefault()); }
public virtual IEnumerable <PubgPlayer> GetPlayers(PubgPlatform platform, GetPubgPlayersRequest filter) { var url = RequestBuilder.BuildRequestUrl(Api.Players.PlayersEndpoint(platform), filter); var apiKey = string.IsNullOrEmpty(filter.ApiKey) ? ApiKey : filter.ApiKey; var collectionJson = HttpRequestor.GetString(url, apiKey); return(JsonConvert.DeserializeObject <IEnumerable <PubgPlayer> >(collectionJson, new JsonApiSerializerSettings())); }
public PubgMatchSample GetMatchSamples(PubgPlatform platform, GetSamplesRequest request) { var url = RequestBuilder.BuildRequestUrl(Api.Samples.SamplesEndpoint(platform), request); var apiKey = string.IsNullOrEmpty(request.ApiKey) ? ApiKey : request.ApiKey; var collectionJson = HttpRequestor.GetString(url, apiKey); return(JsonConvert.DeserializeObject <IEnumerable <PubgMatchSample> >(collectionJson, new JsonApiSerializerSettings()).FirstOrDefault()); }
public virtual async Task <PubgStatEntity> GetPlayerLifetimeStatsAsync(PubgPlatform platform, string playerId, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken)) { var url = Api.Players.PlayerSeasonsEndpoint(platform, playerId, LIFETIME_SEASON_NAME); apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey; var seasonJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey).ConfigureAwait(false); return(JsonConvert.DeserializeObject <PubgStatEntity>(seasonJson, new JsonApiSerializerSettings())); }
public virtual PubgLeaderboard GetGameModeLeaderboard(PubgPlatform platform, PubgGameMode gameMode, string apiKey = null) { var url = Api.Leaderboard.LeaderboardEndpoint(platform, gameMode); apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey; var leaderboardJson = HttpRequestor.GetString(url, apiKey); return(JsonConvert.DeserializeObject <PubgLeaderboard>(leaderboardJson, new JsonApiSerializerSettings())); }
public virtual async Task <PubgPlayer> GetPlayerAsync(PubgPlatform platform, string playerId, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken)) { var url = Api.Players.PlayersEndpoint(platform, playerId); apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey; var playerJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey).ConfigureAwait(false); return(JsonConvert.DeserializeObject <PubgPlayer>(playerJson, new JsonApiSerializerSettings())); }
/// <summary> /// Get a list of seasons for the specified platform on the PC (default: Steam) /// </summary> /// <param name="platform">The platform you wish to get the seasons for</param> /// <param name="apiKey">Your api key (optional)</param> /// <returns>A list of seasons and their information</returns> /// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception> /// <exception cref="Pubg.Net.Exceptions.PubgTooManyRequestsException">You have exceeded your rate limit</exception> /// <exception cref="Pubg.Net.Exceptions.PubgUnauthorizedException">Invalid API Key</exception> public virtual IEnumerable <PubgSeason> GetSeasonsPC(PubgPlatform platform = PubgPlatform.Steam, string apiKey = null) { var url = Api.Seasons.SeasonsPCEndpoint(platform); apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey; var seasonJson = HttpRequestor.GetString(url, apiKey); return(JsonConvert.DeserializeObject <IEnumerable <PubgSeason> >(seasonJson, new JsonApiSerializerSettings())); }
/// <summary> /// Get a specified match from the Api from the specified platform asychronously /// </summary> /// <param name="region">The platform the match is on</param> /// <param name="matchId">The ID for the specified match</param> /// <param name="apiKey">Your Api Key (optional, not needed if specified elsewhere)</param> /// <returns>PubgMatch object for the specified ID</returns> /// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception> /// <exception cref="Pubg.Net.Exceptions.PubgNotFoundException">The api is unable to find the specified match</exception> /// <exception cref="Pubg.Net.Exceptions.PubgTooManyRequestsException">You have exceeded your rate limit</exception> /// <exception cref="Pubg.Net.Exceptions.PubgUnauthorizedException">Invalid API Key</exception> public async virtual Task <PubgMatch> GetMatchAsync(PubgPlatform region, string matchId, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken)) { var url = Api.Matches.MatchesEndpoint(region, matchId); apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey; var matchJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey).ConfigureAwait(false); return(JsonConvert.DeserializeObject <IEnumerable <PubgMatch> >(matchJson, new JsonApiSerializerSettings()).FirstOrDefault()); }
/// <summary> /// Get a specified match from the Api from the specified platform /// </summary> /// <param name="region">The platform the match is on</param> /// <param name="matchId">The ID for the specified match</param> /// <param name="apiKey">Your Api Key (optional, not needed if specified elsewhere)</param> /// <returns>PubgMatch object for the specified ID</returns> /// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception> /// <exception cref="Pubg.Net.Exceptions.PubgNotFoundException">The api is unable to find the specified match</exception> /// <exception cref="Pubg.Net.Exceptions.PubgTooManyRequestsException">You have exceeded your rate limit</exception> /// <exception cref="Pubg.Net.Exceptions.PubgUnauthorizedException">Invalid API Key</exception> public virtual PubgMatch GetMatch(PubgPlatform platform, string matchId, string apiKey = null) { var url = Api.Matches.MatchesEndpoint(platform, matchId); apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey; var matchJson = HttpRequestor.GetString(url, apiKey); return(JsonConvert.DeserializeObject <IEnumerable <PubgMatch> >(matchJson, new JsonApiSerializerSettings()).FirstOrDefault()); }
/// <summary> /// Get a list of seasons for the specified platform on the PC (default: Steam) /// </summary> /// <param name="platform">The platform you wish to get the seasons for</param> /// <param name="apiKey">Your api key (optional)</param> /// <returns>A list of seasons and their information</returns> /// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception> /// <exception cref="Pubg.Net.Exceptions.PubgTooManyRequestsException">You have exceeded your rate limit</exception> /// <exception cref="Pubg.Net.Exceptions.PubgUnauthorizedException">Invalid API Key</exception> public async virtual Task <IEnumerable <PubgSeason> > GetSeasonsPCAsync(PubgPlatform platform = PubgPlatform.Steam, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken)) { var url = Api.Seasons.SeasonsPCEndpoint(platform); apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey; var seasonJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey).ConfigureAwait(false); return(JsonConvert.DeserializeObject <IEnumerable <PubgSeason> >(seasonJson, new JsonApiSerializerSettings())); }
public virtual async Task <PubgLeaderboard> GetGameModeLeaderboardAsync(PubgPlatform platform, PubgGameMode gameMode, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken)) { var url = Api.Leaderboard.LeaderboardEndpoint(platform, gameMode); apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey; var leaderboardJson = await HttpRequestor.GetStringAsync(url, cancellationToken, apiKey).ConfigureAwait(false); return(JsonConvert.DeserializeObject <PubgLeaderboard>(leaderboardJson, new JsonApiSerializerSettings())); }
/// <summary> /// Gets the players season stats and matches for the specified platform /// </summary> /// <param name="platform">The platform on which the season took place</param> /// <param name="playerId">The ID of the player you wish to retrieve the season stats for</param> /// <param name="seasonId">The ID of the season you wish to recieve stats and matches for</param> /// <param name="apiKey">Your API key (optional)</param> /// <returns>Stats and matches for a given player during a given season</returns> /// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception> /// <exception cref="Pubg.Net.Exceptions.PubgNotFoundException">The api is unable to find the specified player</exception> /// <exception cref="Pubg.Net.Exceptions.PubgTooManyRequestsException">You have exceeded your rate limit</exception> /// <exception cref="Pubg.Net.Exceptions.PubgUnauthorizedException">Invalid API Key</exception> public virtual PubgPlayerSeason GetPlayerSeason(PubgPlatform platform, string playerId, string seasonId, string apiKey = null) { var url = Api.Players.PlayerSeasonsEndpoint(platform, playerId, seasonId); apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey; var seasonJson = HttpRequestor.GetString(url, apiKey); return(JsonConvert.DeserializeObject <PubgPlayerSeason>(seasonJson, new JsonApiSerializerSettings())); }
public virtual PubgStatEntity GetPlayerLifetimeStats(PubgPlatform platform, string playerId, string apiKey = null) { var url = Api.Players.PlayerSeasonsEndpoint(platform, playerId, LIFETIME_SEASON_NAME); apiKey = string.IsNullOrEmpty(apiKey) ? ApiKey : apiKey; var seasonJson = HttpRequestor.GetString(url, apiKey); return(JsonConvert.DeserializeObject <PubgStatEntity>(seasonJson, new JsonApiSerializerSettings())); }
public IEnumerable <PlayerResult> GetResult() { PubgPlatform platform = GetPubgPlatform(); PubgMatch match = GetMatch(platform); if (match == null) { yield break; } foreach (PlayerResult playerResult in GetPlayerResultFromMatch(match)) { yield return(playerResult); } }
public static PubgMatchSample GetSamples(PubgPlatform platform) { var samples = StoredItems.OfType <PubgMatchSample>().FirstOrDefault(p => p.ShardId == platform.Serialize()); if (samples != null) { return(samples); } var sampleService = new PubgSamplesService(ApiKey); samples = sampleService.GetMatchSamples(platform); StoredItems.Add(samples); return(samples); }
public static PubgPlayer GetPlayer(PubgPlatform platform) { var player = StoredItems.OfType<PubgPlayer>().FirstOrDefault(p => p.ShardId == platform.Serialize()); if (player != null) return player; var playerService = new PubgPlayerService(ApiKey); var region = platform == PubgPlatform.Xbox ? PubgRegion.XboxEurope : PubgRegion.PCEurope; var playerNames = GetMatch(platform).Rosters.SelectMany(r => r.Participants).Select(p => p.Stats.Name).Take(5); var players = playerService.GetPlayers(platform, new GetPubgPlayersRequest { PlayerNames = playerNames.ToArray() }); StoredItems.AddRange(players); return players.FirstOrDefault(); }
public static PubgMatch GetMatch(PubgPlatform platform) { var match = StoredItems.OfType<PubgMatch>().FirstOrDefault(p => p.ShardId == platform.Serialize()); if (match != null) return match; var region = platform == PubgPlatform.Xbox ? PubgRegion.XboxEurope : PubgRegion.PCEurope; var samples = GetSamples(region); var matchService = new PubgMatchService(ApiKey); match = matchService.GetMatch(platform, samples.MatchIds.First()); StoredItems.Add(match); return match; }
public static PubgMatch GetMatch(PubgPlatform platform) { var match = StoredItems.OfType <PubgMatch>().FirstOrDefault(p => p.ShardId == platform.Serialize()); if (match != null) { return(match); } var samples = GetSamples(platform); var matchService = new PubgMatchService(ApiKey); match = matchService.GetMatch(platform, samples.MatchIds.First()); StoredItems.Add(match); return(match); }
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()); }
private PubgMatch GetMatch(PubgPlatform platform) { var matchService = new PubgMatchService(); PubgMatch match; try { match = matchService.GetMatch(platform, myOptions.MatchId); } catch (PubgNotFoundException) //when ( e.HttpStatusCode == HttpStatusCode.NotFound ) { // Errorcode not set, we wont parse strings though! Console.WriteLine($"Can not find match. (Id = {myOptions.MatchId})"); return(null); } catch (Exception e) { Console.WriteLine($"Can not process match. (Id = {myOptions.MatchId})"); Console.WriteLine(e.Message); return(null); } return(match); }
public Task <PubgMatchSample> GetMatchSamplesAsync(PubgPlatform platform, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken)) => GetMatchSamplesAsync(platform, new GetSamplesRequest { ApiKey = apiKey }, cancellationToken);
public PubgMatchSample GetMatchSamples(PubgPlatform platform, string apiKey = null) => GetMatchSamples(platform, new GetSamplesRequest { ApiKey = apiKey });
public async Task MatchesCommand( [Summary("The username of the player to get matches from")] string username, [Summary("The platform and region to search in")] PubgPlatform platform) { await _service.GetMatches(Context, username, platform); }
internal static string SeasonsPCEndpoint(PubgPlatform platform) => string.Format(ShardedBaseUrl + "/seasons", platform.Serialize());
/// <summary> /// Gets the players season stats and matches for the specified platform /// /// **NOTE**: This method has been deprecated and will be removed in the next major version. /// </summary> /// <param name="platform">The platform on which the season took place</param> /// <param name="playerId">The ID of the player you wish to retrieve the season stats for</param> /// <param name="seasonId">The ID of the season you wish to recieve stats and matches for</param> /// <param name="apiKey">Your API key (optional)</param> /// <returns>Stats and matches for a given player during a given season</returns> /// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception> /// <exception cref="Pubg.Net.Exceptions.PubgNotFoundException">The api is unable to find the specified player</exception> /// <exception cref="Pubg.Net.Exceptions.PubgTooManyRequestsException">You have exceeded your rate limit</exception> /// <exception cref="Pubg.Net.Exceptions.PubgUnauthorizedException">Invalid API Key</exception> public virtual PubgPlayerSeason GetPlayerSeasonPC(PubgPlatform platform, string playerId, string seasonId, string apiKey = null) => GetPlayerSeason(platform, playerId, seasonId, apiKey);
/// <summary> /// Gets the players season stats and matches for the specified platform asynchronusly /// /// **NOTE**: This method has been deprecated and will be removed in the next major version. /// </summary> /// <param name="platform">The platform on which the season took place</param> /// <param name="playerId">The ID of the player you wish to retrieve the season stats for</param> /// <param name="seasonId">The ID of the season you wish to recieve stats and matches for</param> /// <param name="apiKey">Your API key (optional)</param> /// <returns>Stats and matches for a given player during a given season</returns> /// <exception cref="Pubg.Net.Exceptions.PubgException">Exception thrown on the API side, details included on object</exception> /// <exception cref="Pubg.Net.Exceptions.PubgNotFoundException">The api is unable to find the specified player</exception> /// <exception cref="Pubg.Net.Exceptions.PubgTooManyRequestsException">You have exceeded your rate limit</exception> /// <exception cref="Pubg.Net.Exceptions.PubgUnauthorizedException">Invalid API Key</exception> public async virtual Task <PubgPlayerSeason> GetPlayerSeasonPCAsync(PubgPlatform platform, string playerId, string seasonId, string apiKey = null, CancellationToken cancellationToken = default(CancellationToken)) => await GetPlayerSeasonAsync(platform, playerId, seasonId, apiKey, cancellationToken);
private static async Task <PubgMatch> GetMatchFromApiAsync(string matchId, PubgPlatform platform) { PubgMatchService service = new PubgMatchService(); return(await service.GetMatchAsync(platform, matchId)); }
private static async Task <PubgPlayer> GetPlayerFromApiAsync(string username, PubgPlatform platform) { PubgPlayerService service = new PubgPlayerService(); List <PubgPlayer> players = (await service.GetPlayersAsync(platform, new GetPubgPlayersRequest { PlayerNames = new[] { username } })).ToList(); return(players.FirstOrDefault()); }