private async Task <SteamAppSummary> GetRandomGame(CancellationToken token, bool onlySafeForWork)
        {
            var steamApps = await _steamList.Value;
            var randomApp = steamApps.OrderBy(x => Guid.NewGuid()).First();
            var appId     = randomApp.AppId;

            try
            {
                if (onlySafeForWork && await _steamClient.IsAppAdultOnly(appId, token))
                {
                    return(null);
                }
            }
            catch (SteamClientException e)
            {
                _logger.LogWarning(e, "Error getting is adult only flag");
                return(null);
            }

            SteamAppDetails steamAppDetails;

            try
            {
                steamAppDetails = await _steamClient.GetAppDetails(randomApp.AppId, token);
            }
            catch (SteamClientException e)
            {
                _logger.LogWarning(e, "Error getting app details");
                return(null);
            }

            if (steamAppDetails.Type != "game")
            {
                return(null);
            }

            if (steamAppDetails.ReleaseDate.ComingSoon)
            {
                return(null);
            }

            if (steamAppDetails.RequiredAge >= 18 && onlySafeForWork)
            {
                return(null);
            }

            return(randomApp);
        }
Esempio n. 2
0
 public async Task TestGetAppDetailsNotFound()
 {
     await Assert.ThrowsAsync <SteamClientException>(() => _steamClient.GetAppDetails(uint.MaxValue, CancellationToken.None));
 }