public async Task GetStats(long?uniqueId) { StringBuilder sb = new StringBuilder(); var userStats = await _rlsClient.GetPlayerAsync(RlsPlatform.Steam, uniqueId.ToString()); if (userStats != null) { try { EmbedBuilder embed = await RlEmbedApi(userStats); //await InsertStats(userStats); await _cc.Reply(Context, embed); } catch (Exception ex) { await _cc.Reply(Context, "Sorry, something went wrong!"); Console.WriteLine(ex.Message); } return; } else { sb.AppendLine($"Unable to find steam user for steam name/id: {uniqueId}!"); await _cc.Reply(Context, sb.ToString()); return; } }
/// <summary> /// Will call RLS Api to get current season statistics /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public async void GetRocketLeagueStats(object sender, RoutedEventArgs e) { string results = ""; try { var client = new RLSClient(rocketLeagueAPIKey); var player = await client.GetPlayerAsync(RlsPlatform.Steam, userKey.ToString()); var currentSeason = player.RankedSeasons.FirstOrDefault(x => x.Key == RlsSeason.Seven); if (currentSeason.Value != null) { Debug.Write("Rocket League player name: " + player.DisplayName); results += ("Welcome " + player.DisplayName + "!\n\n"); foreach (var playerRank in currentSeason.Value) { Debug.Write(playerRank.Key + ": " + playerRank.Value.RankPoints + " rating"); results += (playerRank.Key + ": " + playerRank.Value.RankPoints + " rating\n"); } } } catch (Exception error) { Debug.Print(error.Message); MessageBoxResult errBox = MessageBox.Show("No player found"); } RLStatsLabel.Content = results; }
public async Task SetStats(string name, string platform) { try { string channel = Context.Channel.Name; string userName = Context.User.Username; ulong discordUserId = Context.User.Id; StringBuilder sb = new StringBuilder(); using (var db = new NinjaBotEntities()) { switch (platform.ToLower()) { case "steam": { var getPlayer = await _rlsClient.GetPlayerAsync(RlsPlatform.Steam, name); try { var addUser = new RlStat(); var rlUser = db.RlStats.Where(r => (ulong)r.DiscordUserID == discordUserId).FirstOrDefault(); if (rlUser == null) { addUser.DiscordUserName = userName; addUser.DiscordUserID = (long)discordUserId; addUser.SteamID = long.Parse(getPlayer.UniqueId); addUser.DiscordUserID = (long)Context.User.Id; addUser.Platform = RlsPlatform.Steam.ToString(); addUser.RlPlayerName = getPlayer.DisplayName; db.RlStats.Add(addUser); } else { rlUser.SteamID = long.Parse(getPlayer.UniqueId); rlUser.DiscordUserID = (long)discordUserId; rlUser.RlPlayerName = getPlayer.DisplayName; rlUser.Platform = RlsPlatform.Steam.ToString(); } db.SaveChanges(); sb.AppendLine($"{Context.User.Mention}, you've associated [**{getPlayer.DisplayName}**(steam)] with your Discord name!"); await _cc.Reply(Context, sb.ToString()); } catch (Exception ex) { Console.WriteLine($"RL Stats: Error setting name -> {ex.Message}"); sb.AppendLine($"{Context.User.Mention}, something went wrong, sorry :("); await _cc.Reply(Context, sb.ToString()); } break; } } } } catch (Exception ex) { Console.WriteLine($"{ex.Message}"); } }
//Get the player out of the Information entered above public static async Task <Player> getPlayerTask() { client = new RLSClient(config.key); bar.Value = 2; player = await client.GetPlayerAsync(plat, name); return(player); }
public async Task rlstats([Remainder] string steamid = null) { string token = File.ReadAllText("RLToken.txt"); if (steamid != null) { var _client = new RLSClient(token); //string msg = ""; //string stats = ""; var player = await _client.GetPlayerAsync(RlsPlatform.Steam, steamid); //var tier = await _client.GetTiersAsync(); //var playerSeasonFive = player.RankedSeasons.FirstOrDefault(x => x.Key == RlsSeason.Seven); //stats = $"**Wins**: {player.Stats.Wins}\n" + // $"**Mvps**: {player.Stats.Mvps}\n" + // $"**Goals**: {player.Stats.Goals}\n" + // $"**Assists**: {player.Stats.Assists}\n" + // $"**Saves**: {player.Stats.Saves}\n" + // $"**Shots**: {player.Stats.Shots}"; //if (playerSeasonFive.Value != null) //{ // foreach (var playerRank in playerSeasonFive.Value) // { // var displayTier = tier.FirstOrDefault(x => x.Id == playerRank.Value.Tier); // msg += $"**{playerRank.Key}**: {displayTier.Name} Div. {playerRank.Value.Division + 1}\n" + // $"\n"; // } //} //var embed1 = new EmbedBuilder() //.WithColor(new Color(color)) //.WithTitle(player.DisplayName) //.WithDescription($"For more info head over to [Rocket League tracker](https://rocketleague.tracker.network/profile/steam/{steamid})") //.WithThumbnailUrl(player.Avatar) //.AddInlineField("Stats", stats) //.AddInlineField("Ranking", msg); //await Context.Channel.SendMessageAsync("", embed: embed1); await Context.Channel.SendMessageAsync("http://signature.rocketleaguestats.com/normal/steam/" + player.UniqueId + ".png"); } }
private static async Task Run() { // Grabs RLS api key from environment variables. var apiKey = Environment.GetEnvironmentVariable("RLS_API_KEY"); // Initialize RLSClient. var client = new RLSClient(apiKey); // Retrieve a single player. var player = await client.GetPlayerAsync(RlsPlatform.Steam, "76561198033338223"); var playerSeasonSix = player.RankedSeasons.FirstOrDefault(x => x.Key == RlsSeason.Seven); if (playerSeasonSix.Value != null) { Console.WriteLine($"# Player: {player.DisplayName}"); foreach (var playerRank in playerSeasonSix.Value) { Console.WriteLine($"{playerRank.Key}: {playerRank.Value.RankPoints} rating"); } } // Retrieve multiple players. var players = await client.GetPlayersAsync(new[] { new PlayerBatchRequest(RlsPlatform.Steam, "76561198033338223"), new PlayerBatchRequest(RlsPlatform.Ps4, "Wizwonk"), new PlayerBatchRequest(RlsPlatform.Xbox, "Loubleezy") }); Console.WriteLine("Finished multiple players."); // Search for players. var players2 = await client.SearchPlayerAsync("AeonLucid"); Console.WriteLine("Finished search for players."); // Retrieve the top 100 players of a ranked playlist. var topPlayers = await client.GetLeaderboardRankedAsync(RlsPlaylistRanked.Standard); Console.WriteLine("Finished top 100 players of a ranked playlist."); // Retrieve the top 100 players of a stat type. var topPlayers2 = await client.GetLeaderboardStatAsync(RlsStatType.Wins); Console.WriteLine("Finished top 100 players of a stat type."); // Retrieve platform data. var platforms = await client.GetPlatformsAsync(); Console.WriteLine("Finished platform data."); // Retrieve seasons data. var seasons = await client.GetSeasonsAsync(); Console.WriteLine("Finished seasons data."); // Retrieve playlist (& population) data. var playlists = await client.GetPlaylistsAsync(); Console.WriteLine("Finished playlists data."); // Retrieve tiers data. var tiers = await client.GetTiersAsync(); Console.WriteLine("Finished tiers data."); // Retrieve tier data of a specific season. var tiers2 = await client.GetTiersAsync(RlsSeason.One); Console.WriteLine("Finished tier data of a specific season."); Console.WriteLine("Finished."); }
public async Task LinkAsync() { await Context.Channel.TriggerTypingAsync(); var user = Context.Message.Author as SocketGuildUser; try { // check if discord id is already in the database var userinfo = await Database.GetUserInfoAsync(user.Id); if (userinfo == null) { await ReplyAsync($"{user.Mention}, no account info provided."); return; } // check if there are still unlinked playlists if (userinfo.Elo1s != -1 && userinfo.Elo2s != -1 && userinfo.Elo3s != -1) { await ReplyAsync($"{user.Mention}, you've already linked all your rocket league playlists to your discord."); return; } // get the platform from the user RlsPlatform platform = RlsPlatform.Steam; if (user.Roles.Contains(Context.Guild.GetRole(386067580630073356))) { platform = RlsPlatform.Steam; } else if (user.Roles.Contains(Context.Guild.GetRole(386067821035126784))) { platform = RlsPlatform.Xbox; } else if (user.Roles.Contains(Context.Guild.GetRole(386067907093856256))) { platform = RlsPlatform.Ps4; } else { await ReplyAsync($"{user.Mention}, couldn't retrieve your platform."); return; } // try to retrieve the account info and check if previously unranked playlists are now ranked var player = await _RLSClient.GetPlayerAsync(platform, userinfo.UniqueID); if (player == null) { await ReplyAsync($"Failed to retrieve player information!"); return; } if (!player.RankedSeasons.TryGetValue(Enum.GetValues(typeof(RlsSeason)).Cast <RlsSeason>().Max(), out var season)) { await ReplyAsync($"{user.Mention}, the account was found, but no information could be retrieved for the current season."); return; } List <IRole> roles = new List <IRole>(); int rp1 = userinfo.Elo1s; if (rp1 == -1 && season.TryGetValue(RlsPlaylistRanked.Duel, out PlayerRank duel)) { rp1 = duel.RankPoints; roles.Add(Context.Guild.GetRole(Global.GetRank(RlsPlaylistRanked.Duel, duel.RankPoints).RoleID)); } int rp2 = userinfo.Elo2s; if (rp2 == -1 && season.TryGetValue(RlsPlaylistRanked.Doubles, out PlayerRank doubles)) { rp2 = doubles.RankPoints; roles.Add(Context.Guild.GetRole(Global.GetRank(RlsPlaylistRanked.Doubles, doubles.RankPoints).RoleID)); } int rp3 = userinfo.Elo3s; if (rp3 == -1 && season.TryGetValue(RlsPlaylistRanked.Standard, out PlayerRank standard)) { rp3 = standard.RankPoints; roles.Add(Context.Guild.GetRole(Global.GetRank(RlsPlaylistRanked.Standard, standard.RankPoints).RoleID)); } if (rp1 == userinfo.Elo1s && rp2 == userinfo.Elo2s && rp3 == userinfo.Elo3s) { await ReplyAsync($"{user.Mention}, no new playlists have been linked."); return; } // try to add the user to the database with their current elo await Database.UpdateUserInfoAsync(user.Id, (short)rp1, (short)rp2, (short)rp3); // give the roles to the user await user.AddRolesAsync(roles); await ReplyAsync($"{user.Mention}, new playlists have been linked!"); } catch (Exception ex) { await ReplyAsync($"{user.Mention}, " + ex.Message); } }