public static Configuration Load() { if (!File.Exists(GamesFile)) { SaveDefaultGameData(); } var gameData = LoadGameData(); var settingsData = LoadSettingsData(); var library = SteamLibrary.Locate(); var games = SteamGameInfo.LocateGames(gameData, library); if (games.Count == 0) { throw new SteamException("No supported steam games found on this system."); } var users = SteamUserInfo.LocateUsers(library); if (users.Count == 0) { throw new SteamException("No steam users found on this system."); } var settings = ApplicationSettings.FromKeyValue(settingsData, games, users); return(new Configuration(games, users, settings)); }
private IImageSupplier DetermineImageSupplier(BasicInfo basicInfo) { basicInfo.ThrowIfNull(nameof(basicInfo)); return(basicInfo switch { OmdbMovieInfo _ => new OmdbImageSupplier(), TmdbMovieInfo _ => new TmdbImageSupplier(TmdbServiceConfiguration.Configuration), SteamGameInfo _ => new SteamImageSupplier(), _ => throw new ArgumentOutOfRangeException(nameof(basicInfo), basicInfo, "Got unknown type to process.") });
/// <inheritdoc /> public override async Task <bool> GetResponse(BufferBlock <string> entitiesQueue, BufferBlock <BasicInfo> responsesQueue, bool outputResults) { if (SteamAppsStorage.IsEmpty) { SteamAppBriefInfoList steamAppsList = await _steamApiClient.GetAppListAsync(); SteamAppsStorage.FillStorage(steamAppsList); } // Use HashSet to avoid duplicated data which can produce errors in further work. var searchResults = new HashSet <BasicInfo>(); while (await entitiesQueue.OutputAvailableAsync()) { string game = await entitiesQueue.ReceiveAsync(); SteamApp response; try { int appId = SteamAppsStorage.GetAppIdByName(game); response = await _steamApiClient.GetSteamAppAsync( appId, CountryCode.Russia, Language.English ); } catch (Exception ex) { _logger.Warn(ex, $"{game} wasn't processed."); GlobalMessageHandler.OutputMessage($"{game} wasn't processed."); continue; } if (outputResults) { GlobalMessageHandler.OutputMessage($"Got {response} from {Tag}"); } SteamGameInfo extractedInfo = _dataMapper.Transform(response); if (searchResults.Add(extractedInfo)) { await responsesQueue.SendAsync(extractedInfo); } } return(searchResults.Count != 0); }
public async Task SteamGameAsync(EventContext context) { DateTime requestStart = DateTime.Now; string[] args = context.arguments.Split(' '); IDiscordEmbed embed = Utils.Embed; embed.SetAuthor("Steam Game", steamAuthorIcon, ""); SteamGameInfo gameInfo = await steam.GetGameInfo(args[0]); embed.SetDescription(gameInfo.Name); embed.SetThumbnailUrl(gameInfo.HeaderImage); embed.SetFooter("Request took in " + Math.Round((DateTime.Now - requestStart).TotalMilliseconds) + "ms", ""); embed.QueueToChannel(context.Channel); }
/// <inheritdoc /> public override List <BasicInfo> GetResponse(List <string> entities, bool outputResults) { if (SteamAppsStorage.IsEmpty) { SteamAppBriefInfoList steamAppsList = _steamApiClient.GetAppListAsync().Result; SteamAppsStorage.FillStorage(steamAppsList); } // Use HashSet to avoid duplicated data which can produce errors in further work. var searchResults = new HashSet <BasicInfo>(); foreach (string game in entities) { SteamApp response; try { int appId = SteamAppsStorage.GetAppIdByName(game); response = _steamApiClient.GetSteamAppAsync( appId, CountryCode.Russia, Language.English ).Result; } catch (Exception ex) { _logger.Warn(ex, $"{game} wasn't processed."); GlobalMessageHandler.OutputMessage($"{game} wasn't processed."); continue; } if (outputResults) { GlobalMessageHandler.OutputMessage($"Got {response} from {Tag}"); } SteamGameInfo extractedInfo = _dataMapper.Transform(response); searchResults.Add(extractedInfo); } return(searchResults.ToList()); }