private async void LoadSteamDetailsAsync() { if (!IsApiKeySet()) { return; } _steamWeb = new SteamWebInterfaceFactory(Settings.ApiKey); _steamUser = _steamWeb.CreateSteamWebInterface <SteamUser>(); _steamPlayerService = _steamWeb.CreateSteamWebInterface <PlayerService>(); _steamStore = _steamWeb.CreateSteamStoreInterface(); PlayerDetails = new ApplicationPlayerDetails(); if (IsUsernameSet()) { if (!await UpdateProfile(Settings.Username)) { ApplicationConstants.MessageInvalidUsername(); Settings.Username = null; } } FetchApps(); }
public SteamApi(Configuration config, HttpClient http) { var factory = new SteamWebInterfaceFactory(config.Steam?.WebApiKey ?? throw new ArgumentNullException(nameof(config.Steam.WebApiKey))); _user = factory.CreateSteamWebInterface <SteamUser>(http); _stats = factory.CreateSteamWebInterface <SteamUserStats>(http); _players = factory.CreateSteamWebInterface <PlayerService>(http); _store = factory.CreateSteamStoreInterface(http); _steamStoreCache = new FluidCache <StoreAppDetailsDataModel>( 1024, TimeSpan.FromSeconds(60), TimeSpan.FromDays(30), () => DateTime.UtcNow ); _steamStoreCacheById = _steamStoreCache.AddIndex("byId", a => a.SteamAppId); _recentlyPlayedGames = new FluidCache <RecentlyPlayedGamesCacheItem>( 128, TimeSpan.FromSeconds(60), TimeSpan.FromHours(1), () => DateTime.UtcNow ); _recentlyPlayedGamesById = _recentlyPlayedGames.AddIndex("byId", a => a.Id); }
public SteamWebApiHelper(ILoggerFactory loggerFactory, SteamHelper config) { _logger = loggerFactory.CreateLogger <SteamWebApiHelper>(); _client = new HttpClient(); _caches.Add( PublishedFileCacheKey, SteamItemCache.Create <PublishedFileDetailsModel>( loggerFactory.CreateLogger <SteamItemCache>(), PublishedFileCacheKey, config.SlidingExpirationHours, config.FileCachePath)); _caches.Add( PlayerSummaryCacheKey, SteamItemCache.Create <PlayerSummaryModel>( loggerFactory.CreateLogger <SteamItemCache>(), PlayerSummaryCacheKey, config.SlidingExpirationHours, config.FileCachePath)); _caches.Add( StoreAppDetailsCacheKey, SteamItemCache.Create <SteamAppDetails>( loggerFactory.CreateLogger <SteamItemCache>(), StoreAppDetailsCacheKey, config.SlidingExpirationHours, config.FileCachePath)); SteamWebInterfaceFactory = new SteamWebInterfaceFactory(config.Token); SteamRemoteStorage = SteamWebInterfaceFactory.CreateSteamWebInterface <SteamRemoteStorage>(_client); SteamUser = SteamWebInterfaceFactory.CreateSteamWebInterface <SteamUser>(_client); SteamStore = SteamWebInterfaceFactory.CreateSteamStoreInterface(_client); }
private static async Task <Steam.Models.SteamStore.StoreAppDetailsDataModel> GetSteamAppModel(string appID) { uint uintAppID = (uint)Int32.Parse(appID); var steamStore = new SteamStore(); var appDetais = await steamStore.GetStoreAppDetailsAsync(uintAppID); return(appDetais); }
public SteamStoreTests() { var mapperConfig = new MapperConfiguration(config => { config.AddProfile <SteamStoreProfile>(); }); var mapper = mapperConfig.CreateMapper(); steamStore = new SteamStore(mapper); }
/// <remarks>https://github.com/babelshift/SteamWebAPI2/issues/81</remarks> public static async Task <StoreAppDetailsDataModel> GetSteamAppAsync(string query) { SteamInterface = new SteamWebInterfaceFactory(TokenHandler.Tokens.SteamToken); //var steam = SteamInterface.CreateSteamWebInterface<SteamStore>(new HttpClient()); //var appId = SteamAppList.FirstOrDefault(n => string.Equals(n.Value, query, StringComparison.InvariantCultureIgnoreCase)).Key; var steam = SteamInterface.CreateSteamWebInterface <SteamApps>(new HttpClient()); var store = new SteamStore(); var list = await steam.GetAppListAsync(); var appId = list.Data.FirstOrDefault(n => string.Equals(n.Name, query, StringComparison.InvariantCultureIgnoreCase)).AppId; return(await store.GetStoreAppDetailsAsync(appId).ConfigureAwait(false)); }
public async Task SteamGame(CommandContext ctx) { var check = false; while (check == false) { try { var rnd = new Random(); var store = new SteamStore(); var app = await store.GetStoreAppDetailsAsync(GlobalVariables.SteamAppList.Keys.ToArray()[rnd.Next(0, GlobalVariables.SteamAppList.Keys.Count - 1)]); await ctx.TriggerTypingAsync(); var output = new DiscordEmbedBuilder() .WithTitle(app.Name) .WithThumbnailUrl(app.HeaderImage) .WithUrl($"http://store.steampowered.com/app/{app.SteamAppId}") .WithFooter($"App ID: {app.SteamAppId}") .WithColor(DiscordColor.MidnightBlue); if (!string.IsNullOrWhiteSpace(app.DetailedDescription)) { output.WithDescription(Regex.Replace(app.DetailedDescription.Length <= 500 ? app.DetailedDescription : $"{app.DetailedDescription.Substring(0, 500)}...", "<[^>]*>", "")); } if (app.Developers.Length > 0 && !string.IsNullOrWhiteSpace(app.Developers[0])) { output.AddField("Developers", app.Developers[0], true); } if (app.Publishers.Length > 0 && !string.IsNullOrWhiteSpace(app.Publishers[0])) { output.AddField("Publisher", app.Publishers[0], true); } if (!string.IsNullOrWhiteSpace(app.ReleaseDate.Date)) { output.AddField("Release Date", app.ReleaseDate.Date, true); } if (app.Metacritic != null) { output.AddField("Metacritic", app.Metacritic.Score.ToString(), true); } await ctx.RespondAsync(embed : output.Build()); check = true; } catch { check = false; } } }
public SteamApi([NotNull] Configuration config) { _user = new SteamUser(config.Steam.WebApiKey); _store = new SteamStore(); _stats = new SteamUserStats(config.Steam.WebApiKey); }