public async Task GetPlayerBansAsync_Should_Succeed() { var response = await steamInterface.GetPlayerBansAsync(76561198050013009); Assert.NotNull(response); Assert.NotNull(response.Data); }
private static async Task ParseNewSteamIds() { List <string> SteamIdsToParse = FetchSteamIds(true); using (BatchQueryBuilder batchQuerybuilder = new BatchQueryBuilder(config.ConnString)) { var steamInterface = new SteamUser(config.SteamWebApiKey, null); foreach (string i in SteamIdsToParse) { if (i == "0") { continue; } try { Console.WriteLine($"Parsing Steam ID {i}"); var playerSummaryResponseData = (await steamInterface.GetPlayerSummaryAsync(UInt64.Parse(i))).Data; var playerBansResponseData = (await steamInterface.GetPlayerBansAsync(UInt64.Parse(i))).Data; IReadOnlyCollection <FriendModel> playerFriendsResponseData = null; if (playerSummaryResponseData.ProfileVisibility == Steam.Models.SteamCommunity.ProfileVisibility.Public) { playerFriendsResponseData = (await steamInterface.GetFriendsListAsync(UInt64.Parse(i))).Data; } batchQuerybuilder.AppendSqlCommand(new MySqlCommand($"UPDATE FamilyRpServerAccess.ParsedSteamAccounts SET SteamCreated = '{playerSummaryResponseData.AccountCreatedDate}',RowUpdated = NOW()," + $"SteamName = '{MySqlHelper.EscapeString(UTF8toASCII(playerSummaryResponseData.Nickname))}'," + $"SteamVisibility = '{playerSummaryResponseData.ProfileVisibility}'," + $"NumSteamFriends = {(playerFriendsResponseData != null ? playerFriendsResponseData.Count : 0)}," + $"SteamBans = {playerBansResponseData.First().NumberOfGameBans + (playerBansResponseData.First().CommunityBanned ? 1 : 0) + playerBansResponseData.First().NumberOfVACBans}," + $"isParsed = 1 " + $"WHERE SteamId = {i};")); AuditLog(null, "Steam", "Parsed", "", i, batchQuerybuilder); } catch (Exception ex) { Console.WriteLine($"Could not fetch Steam ID {i}: {ex}"); } } } }
public async Task <string> ProcessCommandAsync(string inputMessage) { if (inputMessage == "!steam") { return("!steam [command] [username] to use various Steam commands. Valid commands are 'id', 'user', 'bans', 'friends', 'achievements'."); } else if (inputMessage.StartsWith("!steam")) { var splitParsedMessage = inputMessage.Split(' '); string steamCommand = splitParsedMessage[1]; string steamCommandParameter = splitParsedMessage[2]; await steamIdContainer.ResolveAsync(steamCommandParameter); ulong steamId = steamIdContainer.To64Bit(); if (steamCommand == "id") { return($"Steam ID for {steamCommandParameter} is {steamId}"); } else if (steamCommand == "user") { var steamUser = await steamUserInterface.GetPlayerSummaryAsync(steamId); string response = $"Steam profile for {steamCommandParameter} is {steamUser.Data.ProfileUrl} . Account created on: {steamUser.Data.AccountCreatedDate.ToShortDateString()}. User status is: {steamUser.Data.UserStatus}."; if (!string.IsNullOrWhiteSpace(steamUser.Data.PlayingGameName)) { response += $" Currently playing: {steamUser.Data.PlayingGameName}."; } return(response); } else if (steamCommand == "bans") { var steamBans = await steamUserInterface.GetPlayerBansAsync(steamId); // let's just look at the first ban for now var ban = steamBans.Data.ToList()[0]; string banMessage = $"{steamCommandParameter} has {ban.NumberOfGameBans} game bans and {ban.NumberOfVACBans} VAC bans. Community banned: {ban.CommunityBanned}. VAC banned: {ban.VACBanned}. Economy banned: {ban.EconomyBan}."; if (ban.NumberOfGameBans > 0 || ban.NumberOfVACBans > 0) { banMessage += $" Days since last ban: {ban.DaysSinceLastBan}."; } return(banMessage); } else if (steamCommand == "friends") { var steamFriends = await steamUserInterface.GetFriendsListAsync(steamId); return($"{steamCommandParameter} has {steamFriends.Data.Count} friends"); } else if (steamCommand == "achievements") { var appId = uint.Parse(splitParsedMessage[3]); var steamAchievements = await steamUserStatsInterface.GetPlayerAchievementsAsync(appId, steamId); var completedAchievements = steamAchievements.Data.Achievements.Where(x => x.Achieved == 1); return($"{steamCommandParameter} has {completedAchievements.Count()} achievements in {steamAchievements.Data.GameName}"); } else if (steamCommand == "players") { var appId = uint.Parse(splitParsedMessage[2]); var steamPlayers = await steamUserStatsInterface.GetNumberOfCurrentPlayersForGameAsync(appId); var gameName = games[appId]; return($"{gameName} has {steamPlayers.Data} current players"); } else if (steamCommand == "level") { var steamLevel = await playerServiceInterface.GetSteamLevelAsync(steamId); return($"{steamCommandParameter} is level {steamLevel.Data} on Steam"); } else if (steamCommand == "badges") { var steamBadges = await playerServiceInterface.GetBadgesAsync(steamId); return($"{steamCommandParameter} is level {steamBadges.Data.PlayerLevel} which required {steamBadges.Data.PlayerXpNeededCurrentLevel} XP. {steamCommandParameter} has {steamBadges.Data.PlayerXp} XP and needs {steamBadges.Data.PlayerXpNeededToLevelUp} XP to level up."); } else if (steamCommand == "recent") { var recentGames = await playerServiceInterface.GetRecentlyPlayedGamesAsync(steamId); var gameList = recentGames.Data.RecentlyPlayedGames.Select(x => $"{x.Name} (Total: {Math.Round((double)x.PlaytimeForever / 60, 1)} hrs, 2 Wks: {Math.Round((double)x.Playtime2Weeks / 60, 1)} hrs)"); string joinedGameList = string.Join(", ", gameList); string response = $"{steamCommandParameter} has played {recentGames.Data.TotalCount} games in the last 2 weeks: {joinedGameList}."; return(response); } else if (steamCommand == "news") { var appId = uint.Parse(splitParsedMessage[2]); var gameName = games[appId]; var news = await steamNewsInterface.GetNewsForAppAsync(appId, 1); var recentNews = news.Data.NewsItems.ToList()[0]; return($"Here's the latest news for {gameName}. Author: {recentNews.Author}, Title: {recentNews.Title}, Url: {recentNews.Url} ."); } } return(string.Empty); }
private static async Task ParseNewSteamIds() { try { List <string> steamIdsToParse = FetchSteamIds(true); using (BatchQueryBuilder batchQuerybuilder = new BatchQueryBuilder(_config.ConnString)) { SteamUser steamInterface = new SteamUser(_config.SteamWebApiKey); foreach (string i in steamIdsToParse) { if (i == "0") { continue; } try { Console.WriteLine($"Parsing Steam ID {i}"); PlayerSummaryModel playerSummaryResponseData = (await steamInterface.GetPlayerSummaryAsync(ulong.Parse(i))).Data; IReadOnlyCollection <PlayerBansModel> playerBansResponseData = (await steamInterface.GetPlayerBansAsync(ulong.Parse(i))).Data; IReadOnlyCollection <FriendModel> playerFriendsResponseData = null; if (playerSummaryResponseData.ProfileVisibility == ProfileVisibility.Public) { playerFriendsResponseData = (await steamInterface.GetFriendsListAsync(ulong.Parse(i))).Data; } batchQuerybuilder.AppendSqlCommand(new MySqlCommand($"UPDATE FamilyRpServerAccess.ParsedSteamAccounts SET SteamCreated = '{playerSummaryResponseData.AccountCreatedDate:s}', RowUpdated = NOW()," + $"SteamName = '{MySqlHelper.EscapeString( Utf8ToAscii( playerSummaryResponseData.Nickname ) )}'," + $"SteamVisibility = '{playerSummaryResponseData.ProfileVisibility}'," + $"NumSteamFriends = {playerFriendsResponseData?.Count ?? 0}," + $"SteamBans = {playerBansResponseData.First().NumberOfGameBans + (playerBansResponseData.First().CommunityBanned ? 1 : 0) + playerBansResponseData.First().NumberOfVACBans}," + "isParsed = 1 " + $"WHERE SteamId = {i};")); AuditLog(null, "Steam", "Parsed", "", i, batchQuerybuilder); } catch (Exception ex) { if (!(ex.ToString().Contains("System.Net.Http.HttpRequestException") && ex.ToString().Contains("Unauthorized"))) { Console.WriteLine($"Could not fetch Steam ID {i}: {ex}"); } } } } } catch (Exception ex) { Console.WriteLine($"{ex}"); } }