public async Task <IActionResult> AddPoints(int num)
        {
            if (!_cache.TryGetValue(CacheKeys.CrendorSubPoints, out int curPoints))
            {
                curPoints = 0;
            }

            num += curPoints;
            var numString = num.ToString();

            _cache.Set(CacheKeys.CrendorSubPoints, num, CacheHelpers.EntryOptions);
            await _wsMgr.SendAllAsync(numString);

            await _kvSvc.CreateOrUpdateAsync(CacheKeys.CrendorSubPoints, numString);

            return(NoContent());
        }
Beispiel #2
0
        private async Task OpenBettingAsync(OnChatCommandReceivedArgs e)
        {
            if (_isBettingOpen)
            {
                _client.SendMessage(e, "Betting was already open.");
                return;
            }

            _isBettingOpen  = true;
            _canProcessBets = false;
            await KeyValueService.CreateOrUpdateAsync(nameof(SlothyBetStatus), nameof(SlothyBetStatus.Open));

            _client.SendMessage(e, "Betting is now open.");
        }
        private async Task RefreshTokenAsync()
        {
            _api.Settings.AccessToken = null;
            _api.Settings.ClientId    = _config.SubPointsClientId;

            var resp = await _api.Auth.RefreshAuthTokenAsync(_config.SubPointsRefreshToken, _config.SubPointsClientSecret);

            _config.SubPointsAccessToken  = resp.AccessToken;
            _config.SubPointsRefreshToken = resp.RefreshToken;

            _api.Settings.AccessToken = _config.SubPointsAccessToken;

            _tokenRefreshTimer?.Dispose();
            _tokenRefreshTimer = new Timer(async _ => await RefreshTokenAsync(), null, TimeSpan.FromSeconds(resp.ExpiresIn - 600), TimeSpan.FromMilliseconds(-1));

            await KeyValueService.CreateOrUpdateAsync("SubPointsTokens", $"{resp.AccessToken}|||||{resp.RefreshToken}");
        }
Beispiel #4
0
        private async Task CloseBettingAsync(OnChatCommandReceivedArgs e)
        {
            if (!_isBettingOpen)
            {
                _client.SendMessage(e, "Betting was already closed.");
                return;
            }

            _isBettingOpen  = false;
            _canProcessBets = true;

            await KeyValueService.CreateOrUpdateAsync(nameof(SlothyBetStatus), nameof(SlothyBetStatus.InProgress));

            var stats = CalculateStats();

            _client.SendMessage(e, $"Betting is now closed. | {stats}");
        }
Beispiel #5
0
        private async Task ProcessBetsAsync(OnChatCommandReceivedArgs e, SlothyBetType type)
        {
            if (!_canProcessBets)
            {
                _client.SendMessage(e, $"@{e.Command.ChatMessage.DisplayName}: Bets cannot be processed right now. " +
                                    "If betting is open, close it first.");
                return;
            }

            _canProcessBets       = false;
            _canProcessCorrection = false;

            _client.SendMessage(e, "Processing bets...");

            var currentBets = _betSvc.GetAllCurrentBets();

            foreach (var bet in currentBets)
            {
                if (bet.BetType == type)
                {
                    await _slothySvc.AddSlothiesAsync(bet.UserId, bet.Amount);
                }
                else
                {
                    await _slothySvc.AddSlothiesAsync(bet.UserId, 0 - bet.Amount);
                }
            }

            var stats = CalculateStats();

            _previousSlothyBetRecords = currentBets;
            _previousBetWinType       = type;

            await _betSvc.ClearBetsAsync();

            await KeyValueService.CreateOrUpdateAsync(nameof(SlothyBetStatus), nameof(SlothyBetStatus.Closed));

            _canProcessCorrection = true;

            _client.SendMessage(e, $"Bets processed. | {stats}");
        }
Beispiel #6
0
        private async Task ProcessForfeitAsync(OnChatCommandReceivedArgs e)
        {
            if (!_canProcessBets)
            {
                _client.SendMessage(e, $"@{e.Command.ChatMessage.DisplayName}: Bets cannot be processed right now.");
                return;
            }

            _canProcessBets       = false;
            _canProcessCorrection = false;

            _previousSlothyBetRecords = _betSvc.GetAllCurrentBets();
            _previousBetWinType       = SlothyBetType.Void;

            await _betSvc.ClearBetsAsync();

            await KeyValueService.CreateOrUpdateAsync(nameof(SlothyBetStatus), nameof(SlothyBetStatus.Closed));

            _canProcessCorrection = true;

            _client.SendMessage(e, "All bets have been canceled.");
        }
Beispiel #7
0
        public async Task <IActionResult> Wins(int num)
        {
            if (num > 99)
            {
                num = 99;
            }

            if (_cache.TryGetValue(CacheKeys.FitzyWins, out int wins))
            {
                num = num > -1 ? num : Math.Min(wins + 1, 99);
                _cache.Set(CacheKeys.FitzyWins, num);
            }
            else
            {
                num = num > -1 ? num : 1;
                _cache.Set(CacheKeys.FitzyWins, num);
            }

            await _wsMgr.SendAllCurrentRecordAsync();

            await _kvSvc.CreateOrUpdateAsync(CacheKeys.FitzyWins, num.ToString());

            return(NoContent());
        }