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(); }
static Program() { s_VKStatus = string.Empty; s_Configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); ReadConfig(); s_SpotifyAuth = new AuthorizationCodeAuth( s_SpotifyClientId, s_SpotifyClientSecret, "http://localhost:4002", "http://localhost:4002", Scope.UserReadCurrentlyPlaying | Scope.UserReadPlaybackState ); s_VKAPI = new VkApi(new ServiceCollection().AddAudioBypass()); Log.Logger = new LoggerConfiguration() .MinimumLevel.Is(s_Configuration.GetSection("Log").Get <LogEventLevel>()) .WriteTo.Console() .CreateLogger(); var steamWebInterfaceFactory = new SteamWebInterfaceFactory(s_SteamToken); s_SteamAPI = steamWebInterfaceFactory.CreateSteamWebInterface <SteamUser>(); var loggerFactory = new LoggerFactory().AddSerilog(); s_StringLocalizer = new JsonStringLocalizer(Path.Combine(Directory.GetCurrentDirectory(), "Resources"), "test", loggerFactory.CreateLogger("test")); }
public async Task GetAvatars() { List <PlayerSummary> stringList = new List <PlayerSummary>(); string Key = ConfigurationManager.AppSettings["SteamAPIKey"]; var webInterfaceFactory = new SteamWebInterfaceFactory(Key); var steamInterface = webInterfaceFactory.CreateSteamWebInterface <SteamUser>(new HttpClient()); foreach (PlayerRow i in MasterList) { AvatarList.Add(Convert.ToUInt64(i.Steam64)); } var playerSummariesResponse = await steamInterface.GetPlayerSummariesAsync(AvatarList); var playerSummariesData = playerSummariesResponse.Data; foreach (var i in playerSummariesData) { foreach (var n in MasterList) { if (i.SteamId.ToString() == n.Steam64) { n.AvatarUrl = i.AvatarUrl; n.Name = i.Nickname; } } } }
public async Task <IActionResult> AccountSummary() { var user = await this.userManager.GetUserAsync(this.User); var login = await this.userManager.GetLoginsAsync(user); var provKey = login[0].ProviderKey; var steamId64 = this.steamInfoService.GetSteamId64(provKey); var steamId32 = this.steamInfoService.Steam64ToSteam32(steamId64); var webInterfaceFactory = new SteamWebInterfaceFactory(GlobalConstants.SteamApiKey); var steamInterface = webInterfaceFactory.CreateSteamWebInterface <SteamUser>(new HttpClient()); var playerSummaryResponse = await steamInterface.GetPlayerSummaryAsync((ulong)steamId64); var openDota = new OpenDotaApi(); var recentMatches = await openDota.Players.GetPlayerRecentMatchesAsync(steamId32); var lastMatch = recentMatches.FirstOrDefault(); var matchDetails = openDota.Matches.GetMatchByIdAsync(lastMatch.MatchId); var viewModel = new DotaAccountsViewModel { Nickname = playerSummaryResponse.Data.Nickname, Avatar = playerSummaryResponse.Data.AvatarMediumUrl, }; return(this.View(viewModel)); }
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); }
public DotaAssistansService() { webInterfaceFactory = new SteamWebInterfaceFactory(ConfigurationManager.AppSettings["steamWebApi"]); dotaEconInterface = webInterfaceFactory.CreateSteamWebInterface <DOTA2Econ>(new HttpClient()); GetHeroes(); GetItems(); }
public Client(string steamApiKey) { var webInterfaceFactory = new SteamWebInterfaceFactory(steamApiKey); _steamPlayerInterface = webInterfaceFactory.CreateSteamWebInterface <PlayerService>(); _steamUserInterface = webInterfaceFactory.CreateSteamWebInterface <SteamUser>(); }
public StatusViewComponent(HomeContext dbContext, IConfiguration configuration, IMemoryCache memoryCache, ILoggerFactory loggerFactory) { _dbContext = dbContext; _memoryCache = memoryCache; _logger = loggerFactory.CreateLogger <StatusViewComponent>(); LastfmUserName = configuration["LastfmUser"]; SteamId = configuration.GetValue <ulong>("SteamID"); TwitchUserId = configuration.GetValue <ulong>("TwitchUserId"); TwitchClientId = configuration["TwitchClientId"]; var lastfmApiKey = configuration["LastfmApiKey"]; var lastfmSecret = configuration["LastfmSharedSecret"]; if (lastfmApiKey != null && lastfmSecret != null) { Client = new LastfmClient(lastfmApiKey, lastfmSecret, s_httpClient); } var steamWebApiKey = configuration["SteamWebApiKey"]; if (steamWebApiKey != null) { SteamFactory = new SteamWebInterfaceFactory(steamWebApiKey); } }
public async Task SteamGames(uint gameid) { var webInterfaceFactory = new SteamWebInterfaceFactory(_config["steamkey"]); var steamInterface = webInterfaceFactory.CreateSteamWebInterface <SteamStore>(new HttpClient()); var searchedGame = await steamInterface.GetStoreAppDetailsAsync(gameid); await Context.Channel.SendMessageAsync(searchedGame.Name); }
public SteamWebManager() { m_webFactory = new SteamWebInterfaceFactory(Program.Document.Element("SteamAPIKey").Value); // this will map to the ISteamUser endpoint // note that you have full control over HttpClient lifecycle here m_interface = m_webFactory.CreateSteamWebInterface <SteamUser>(new HttpClient()); }
public SteamWebInterfaceFactoryTests() { var factoryOptions = new SteamWebInterfaceFactoryOptions() { SteamWebApiKey = "ABC123" }; factory = new SteamWebInterfaceFactory(Options.Create(factoryOptions)); }
public SteamCommandProcessor(string steamWebApiKey) { webInterfaceFactory = new SteamWebInterfaceFactory(steamWebApiKey); steamUserInterface = webInterfaceFactory.CreateSteamWebInterface <SteamUser>(httpClient); steamUserStatsInterface = webInterfaceFactory.CreateSteamWebInterface <SteamUserStats>(httpClient); steamIdContainer = webInterfaceFactory.CreateSteamWebInterface <SteamId>(httpClient); playerServiceInterface = webInterfaceFactory.CreateSteamWebInterface <PlayerService>(httpClient); steamNewsInterface = webInterfaceFactory.CreateSteamWebInterface <SteamNews>(httpClient); }
public GetSteamGamesService(IConfiguration configuration) { var apiKey = configuration.GetValue <string>("SteamApiKey"); userId = configuration.GetValue <ulong>("UserId"); var webInterfaceFactory = new SteamWebInterfaceFactory(apiKey); playerService = webInterfaceFactory.CreateSteamWebInterface <PlayerService>(new HttpClient()); }
public void Constructor_Should_Succeed() { var factoryOptions = new SteamWebInterfaceFactoryOptions() { SteamWebApiKey = "ABC123" }; var factory = new SteamWebInterfaceFactory(Options.Create(factoryOptions)); Assert.NotNull(factory); }
public SteamInterface(IConfiguration configuration, IMemoryCache memCache) { this.httpClient = new HttpClient(); SteamApiKey = configuration["Steam:ApiKey"]; this.memCache = memCache; steamFactory = new SteamWebInterfaceFactory(SteamApiKey); steamInterface = steamFactory.CreateSteamWebInterface <SteamUser>(new HttpClient()); }
public async Task GetActualDataAsync() { _logger.LogInformation("Start integration session with Steam API"); var steamWebInterfaceFactory = new SteamWebInterfaceFactory(_steamApiKey); var steamApps = steamWebInterfaceFactory.CreateSteamWebInterface <SteamApps>(); var ids = _appDBContext.IntegrationInfos .Where(ii => ii.ExternalSystemDescriptor.Equals(ExternalSystemDescriptor)) .Select(ii => ii.ExternalGameId); var listResponse = await steamApps.GetAppListAsync(); var appInfoList = listResponse.Data.Where(a => !ids.Any(id => id == a.AppId)); var appsCountStr = Startup.Configuration["IntegrationSettings:SteamIntegrationSettings:MaxPacketSize"]; var appsCount = 0; var isMaxSizeExists = false; if (appsCountStr != null) { appsCount = Convert.ToInt32(appsCountStr); isMaxSizeExists = true; } var steamStoreInterface = steamWebInterfaceFactory.CreateSteamStoreInterface(); var lang = "russian"; foreach (var app in appInfoList) { StoreAppDetailsDataModel appDetails = null; try { appDetails = await steamStoreInterface.GetStoreAppDetailsAsync(app.AppId, lang); } catch (NullReferenceException) { _logger.LogError("Не удалось получить информацию о приложении {0}({1})", app.Name, app.AppId); continue; } catch (Exception e) { _logger.LogError(e, "Произошла непредвиденная ошибка: "); continue; } // Skip DLC if (appDetails.Type.Equals("game")) { AppDetails.Add(appDetails); if (isMaxSizeExists && AppDetails.Count >= appsCount) { break; } } } }
// factory to be used to generate various web interfaces static void Main(string[] args) { var webInterfaceFactory = new SteamWebInterfaceFactory("2901A4BCBA478FDD1D4226CECD80A1C7"); // this will map to the ISteamUser endpoint // note that you have full control over HttpClient lifecycle here var steamInterface = webInterfaceFactory.CreateSteamWebInterface <SteamUser>(new HttpClient()); ulong brynSteamId = 76561198033967649; GetPlayerSummary(brynSteamId, steamInterface); }
public SteamService(BotConfigService cfg) { this.cacheResetTimer = new Timer(ResetCache, this, TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(15)); if (!string.IsNullOrWhiteSpace(cfg.CurrentConfiguration.SteamKey)) { var webInterfaceFactory = new SteamWebInterfaceFactory(cfg.CurrentConfiguration.SteamKey); this.users = webInterfaceFactory.CreateSteamWebInterface <SteamUser>(); this.apps = webInterfaceFactory.CreateSteamWebInterface <SteamApps>(); this.store = webInterfaceFactory.CreateSteamStoreInterface(); } }
public SteamFactory() { var builder = new ConfigurationBuilder() .AddJsonFile("appsetting.json"); IConfiguration configuration = builder.Build(); var factoryOptions = new SteamWebInterfaceFactoryOptions { SteamWebApiKey = configuration["SteamWebApiKey"] }; Factory = new SteamWebInterfaceFactory(Options.Create(factoryOptions)); }
/// <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 ValueTask <PlayerSummaryModel> ForceGetPlayerSummaryModelAsync(string steamId) { if (!ulong.TryParse(steamId, out var parsedId)) { throw new ArgumentException(nameof(steamId)); } var setting = await settingService.GetSettingAsync("SteamDevKey", true); var factory = new SteamWebInterfaceFactory(setting.SettingValue); var steamUser = factory.CreateSteamWebInterface <SteamUser>(httpClientFactory.CreateClient()); var summariesResponse = await steamUser.GetPlayerSummaryAsync(parsedId); return(summariesResponse.Data); }
public void Login(string apiKey, string userId) { Session.ApiKey = apiKey; Session.UserId = ulong.Parse(userId); var webInterfaceFactory = new SteamWebInterfaceFactory(apiKey); Session.SteamUser = webInterfaceFactory.CreateSteamWebInterface <SteamUser>(new HttpClient()); Session.SteamPlayer = webInterfaceFactory.CreateSteamWebInterface <PlayerService>(new HttpClient()); var feed = Feed <bool> .Instance; feed.Notify(true); Extensions.MoveForwards(); }
public BaseTest() { var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .AddUserSecrets <CSGOServersTests>(); configuration = builder.Build(); var factoryOptions = new SteamWebInterfaceFactoryOptions() { SteamWebApiKey = configuration["SteamWebApiKey"] }; factory = new SteamWebInterfaceFactory(Options.Create(factoryOptions)); }
public static async Task <bool> UpdateSteamAppListAsync(string token) { try { _steamInterface = new SteamWebInterfaceFactory(token); SteamAppList = await _steamInterface.CreateSteamWebInterface <SteamApps>(new HttpClient()) .GetAppListAsync(); return(true); } catch (Exception ex) { Console.WriteLine(Resources.ERR_STEAM_LIST, ex.Message); return(false); } }
public static async Task <ISteamWebResponse <PlayerSummaryModel> > GetSteamSummaryAsync(string query) { try { SteamInterface = new SteamWebInterfaceFactory(TokenHandler.Tokens.SteamToken); var steam = SteamInterface.CreateSteamWebInterface <SteamUser>(new HttpClient()); if (ulong.TryParse(query, out var steamId)) { return(await steam.GetPlayerSummaryAsync(ulong.Parse(query)).ConfigureAwait(false)); } var decode = await steam.ResolveVanityUrlAsync(query).ConfigureAwait(false); return(await steam.GetPlayerSummaryAsync(decode.Data).ConfigureAwait(false)); } catch { return(null); } }
/// <summary> /// Sets up the <see cref="SteamService"/> /// </summary> public static void SetupSteam() { if (IsEnabled) { return; } if (!string.IsNullOrWhiteSpace(Config.bot.Apis.ApiSteamKey)) { SteamWebInterfaceFactory webInterface = new SteamWebInterfaceFactory(Config.bot.Apis.ApiSteamKey); steamUserInterface = webInterface.CreateSteamWebInterface <SteamUser>(Global.HttpClient); steamPlayerInterface = webInterface.CreateSteamWebInterface <PlayerService>(Global.HttpClient); IsEnabled = true; } else { throw new Exception("The config doesn't have the Steam API key set!"); } }
/// <summary> /// Handles the Click event of the doneButton control. /// Makes sure that the Steam API key is valid and closes this form to allow the next form to open. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private async void doneButton_Click(object sender, EventArgs e) { try { SteamWebInterfaceFactory webInterfaceFactory = new SteamWebInterfaceFactory(apiKeyTextBox.Text); SteamUser steamInterface = webInterfaceFactory.CreateSteamWebInterface <SteamUser>(new HttpClient()); await steamInterface.GetPlayerSummaryAsync(76561197977699530).ConfigureAwait(false); // SteamId of https://steamcommunity.com/id/valve Program.SteamApiKey = apiKeyTextBox.Text; Invoke(new MethodInvoker(() => Close())); } catch { if (MessageBox.Show("Encountered an error while trying to use the API Key. Would you like to continue without an API Key?", "API Key Error", MessageBoxButtons.YesNo) == DialogResult.Yes) { Program.SteamApiKey = ""; Invoke(new MethodInvoker(() => Close())); } } }
public async Task InitializeAsync() { var config = ConfigurationService.Basic; var client = new DiscordClient(TokenType.Bot, config.DiscordToken, new DiscordClientConfiguration { MessageCache = new DefaultMessageCache(100) }); var factory = new SteamWebInterfaceFactory(config.SteamApiKey); // TODO: Factory? var backpackClient = new BackpackClient(config.BackpackApiKey); var commands = new CommandService(new CommandServiceConfiguration { CooldownProvider = new AdminCooldownProvider() }); var provider = new ServiceCollection() .AutoAddServices() .AddSingleton(client) .AddSingleton(factory) .AddSingleton(backpackClient) .AddSingleton(commands) .AddSingleton <CancellationTokenSource>() .AddSingleton <Random>() .AddSingleton <Registry>() .AddSingleton <HttpClient>() .AddEntityFrameworkNpgsql() .BuildServiceProvider(); try { await provider.InitializeServicesAsync(); await client.RunAsync(provider.GetRequiredService <CancellationTokenSource>().Token); } catch (TaskCanceledException) { } catch (Exception ex) { await provider.GetRequiredService <LoggingService>().LogCriticalAsync(ex, "Administrator"); } }