Пример #1
0
        private void InitializeCache(KeyValueService kvSvc, VbContext vbContext, IMemoryCache cache)
        {
            var winKv  = kvSvc.GetByKeyAsync(CacheKeys.FitzyWins).GetAwaiter().GetResult();
            var lossKv = kvSvc.GetByKeyAsync(CacheKeys.FitzyLosses).GetAwaiter().GetResult();
            var drawKv = kvSvc.GetByKeyAsync(CacheKeys.FitzyDraws).GetAwaiter().GetResult();

            int.TryParse(winKv?.Value ?? "0", out var winCount);
            int.TryParse(lossKv?.Value ?? "0", out var lossCount);
            int.TryParse(drawKv?.Value ?? "0", out var drawCount);

            cache.Set(CacheKeys.FitzyWins, winCount, CacheHelpers.EntryOptions);
            cache.Set(CacheKeys.FitzyLosses, lossCount, CacheHelpers.EntryOptions);
            cache.Set(CacheKeys.FitzyDraws, drawCount, CacheHelpers.EntryOptions);

            var crendorPointsKv = kvSvc.GetByKeyAsync(CacheKeys.CrendorSubPoints).GetAwaiter().GetResult();

            int.TryParse(crendorPointsKv?.Value ?? "-1", out var crendorPoints);

            cache.Set(CacheKeys.CrendorSubPoints, crendorPoints, CacheHelpers.EntryOptions);

            foreach (var notification in vbContext.TwitchWebhookNotifications.ToListAsync().GetAwaiter().GetResult())
            {
                var expiresAt = notification.ReceivedAt + TimeSpan.FromDays(3);
                if (DateTimeOffset.UtcNow < expiresAt)
                {
                    cache.Set(notification.Id, "", expiresAt);
                }
            }
        }
Пример #2
0
        public async Task InitializeAsync()
        {
            var kv = await KeyValueService.GetByKeyAsync(nameof(SlothyBetStatus));

            SlothyBetStatus status;

            if (kv?.Value == null)
            {
                status = SlothyBetStatus.Closed;
            }
            else
            {
                status = (SlothyBetStatus)Enum.Parse(typeof(SlothyBetStatus), kv.Value, true);
            }

            switch (status)
            {
            case SlothyBetStatus.Open:
                _isBettingOpen  = true;
                _canProcessBets = false;
                break;

            case SlothyBetStatus.InProgress:
                _isBettingOpen  = false;
                _canProcessBets = true;
                break;
            }
        }
Пример #3
0
        public async Task InitializeAsync()
        {
            var raw = await KeyValueService.GetByKeyAsync("SubPointsTokens");

            if (!string.IsNullOrEmpty(raw?.Value))
            {
                var split = raw.Value.Split("|||||");
                _config.SubPointsRefreshToken = split[1];
            }

            await RefreshTokenAsync();

            _pubSub.OnChannelSubscription += OnChannelSubscription;

            if (_config.TrackSubPoints)
            {
                _manualUpdateTimer   = new Timer(async _ => await UpdateSubPointsFromApiAsync(), null, TimeSpan.Zero, TimeSpan.FromMinutes(5));
                _batchSubUpdateTimer = new Timer(async _ => await HandleSubBatchAsync(), null, TimeSpan.Zero, TimeSpan.FromSeconds(5));
            }
        }