Пример #1
0
        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();
        }
Пример #2
0
        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 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;
                    }
                }
            }
        }
Пример #4
0
 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();
     }
 }
Пример #5
0
        public async Task Steam(CommandContext ctx, [RemainingText] string gameName)
        {
            gameName.RequireRemainingText();
            await ctx.Channel.TriggerTypingAsync();

            var factory = new SteamWebInterfaceFactory(Program.Config.Apis.SteamWebApi);

            using var httpClient = new HttpClient();
            var steamStore = factory.CreateSteamStoreInterface(httpClient);
            var steamApps  = factory.CreateSteamWebInterface <SteamApps>(httpClient);

            var botContext = new BotContext();
            var cacheInfo  = await botContext.CacheInfos.FindAsync(CacheType.Steam);

            if (cacheInfo == null || (DateTime.Now - cacheInfo.RefreshedTime).Hours >= 12)
            {
                var apps = await steamApps.GetAppListAsync();

                botContext.SteamAppsCache.RemoveRange(botContext.SteamAppsCache);
                await botContext.SteamAppsCache.AddRangeAsync(apps.Data);

                cacheInfo = new CacheInfo()
                {
                    Type = CacheType.Steam, RefreshedTime = DateTime.Now
                };
                if (!botContext.CacheInfos.Contains(cacheInfo))
                {
                    await botContext.CacheInfos.AddAsync(cacheInfo);
                }
                await botContext.SaveChangesAsync();

                await ctx.Channel.TriggerTypingAsync();
            }
            var appModel = botContext.SteamAppsCache.ToList().OrderBy(x => Fastenshtein.Levenshtein.Distance(x.Name, gameName)).FirstOrDefault();

            if (appModel == null)
            {
                await ctx.RespondAsync($"Nie znaleziono gry `{gameName}`");

                return;
            }

            var game = await steamStore.GetStoreAppDetailsAsync(appModel.AppId);

            var desc = ClearHtml(game.DetailedDescription);

            if (desc.Length >= 2000)
            {
                desc  = desc.Substring(0, Math.Min(desc.Length, 2000 - 3));
                desc += "...";
            }
            else
            {
                desc = desc.Substring(0, Math.Min(desc.Length, 2000));
            }
            await new ModernEmbedBuilder
            {
                Title       = $"{game.Name}",
                Url         = game.Website,
                Description = desc,
                Fields      =
                {
                    ("F2P",                                                      game.IsFree ? "Tak" : "Nie",                                                   inline: true),
                    ("Data wydania",                                             (game.ReleaseDate.ComingSoon ? "[Coming soon] " : "") + game.ReleaseDate.Date, inline: true),
                    (game.Genres.Length > 1 ? "Gatunki" : "Gatunek",             string.Join(", ",                                                              game.Genres.Select(x => x.Description)),    inline: true),
                    (game.Categories.Length > 1 ? "Kategorie" : "Kategoria",     string.Join(", ",                                                              game.Categories.Select(x => x.Description)),inline: true),
                    (game.Developers.Length > 1 ? "Programiści" : "Programista", string.Join(", ",                                                              game.Developers),                           inline: true),
                    (game.Publishers.Length > 1 ? "Wydawcy" : "Wydawca",         string.Join(", ",                                                              game.Publishers),                           inline: true),
                },
Пример #6
0
        public void Create_SteamStore_Interface_Should_Succeed()
        {
            var steamInterface = factory.CreateSteamStoreInterface();

            Assert.NotNull(steamInterface);
        }