示例#1
0
        public static bool TryParseSlothyBetType(string str, bool includeVoid, out SlothyBetType type)
        {
            str = str.ToLowerInvariant();

            type = SlothyBetType.Win;

            if (str == "win" || str == "won")
            {
                return(true);
            }

            if (str == "lose" || str == "loss" || str == "lost")
            {
                type = SlothyBetType.Lose;
                return(true);
            }

            if (includeVoid && (str == "draw" || str == "forfeit" || str == "forfeited" || str == "forfeitted" ||
                                str == "null" || str == "void"))
            {
                type = SlothyBetType.Void;
                return(true);
            }

            return(false);
        }
示例#2
0
        private async Task TakeBetAsync(OnChatCommandReceivedArgs e, decimal amount, SlothyBetType type)
        {
            var msgBegin = $"@{e.Command.ChatMessage.DisplayName}:";

            if (!_isBettingOpen)
            {
                _client.SendMessage(e, $"{msgBegin} Betting is currently closed.");
                return;
            }

            if (amount <= 0)
            {
                _client.SendMessage(e, $"{msgBegin} You must bet a positive number of slothies.");
                return;
            }

            if (amount > 100)
            {
                _client.SendMessage(e, $"{msgBegin} You cannot bet more than 100 slothies at a time.");
                return;
            }

            var curCount = _slothySvc.GetSlothyCount(e.Command.ChatMessage.UserId);

            if (curCount <= -1000)
            {
                _client.SendMessage(e, $"{msgBegin} You must have more than -1,000 slothies to place bets.");
                return;
            }

            var hadExistingBet = _betSvc.GetCurrentBet(e.Command.ChatMessage.UserId) != null;

            await _betSvc.AddOrUpdateBetAsync(new SlothyBetRecord
            {
                UserId  = e.Command.ChatMessage.UserId,
                Amount  = amount,
                BetType = type
            });

            if (!hadExistingBet)
            {
                _client.SendMessage(e, $"{msgBegin} Bet placed.");
            }
            else
            {
                _client.SendMessage(e, $"{msgBegin} Bet updated.");
            }
        }
示例#3
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}");
        }