public async Task <ValidationResult> ValidateCommandAsync(Command command)
        {
            var gameBetParseResult = float.TryParse(command.Arguments[1], out float gameBet);

            if (gameBetParseResult)
            {
                if (gameBet <= 0)
                {
                    return(new ValidationResult(false, "Invalid bet amount"));
                }
            }
            else
            {
                return(new ValidationResult(false, "Invalid command structure - rps <user> <points_to_bet>"));
            }

            gameBounty = gameBet;
            var userCurrentBalance = await _userPointsRepository.GetUserBalanceAsync(command.Author.Id);

            var opponentsBalance = await _userPointsRepository.GetUserBalanceAsync(command.Arguments[0]
                                                                                   .Substring(3, command.Arguments[0].Length - 4));

            if (userCurrentBalance is null)
            {
                return(new ValidationResult(false, $"User does not own a wallet, use ?register to create wallet"));
            }

            if (opponentsBalance is null)
            {
                return(new ValidationResult(false, $"Opponent **{command.Arguments[0]}** does not own a wallet"));
            }

            if (opponentsBalance < gameBet)
            {
                return(new ValidationResult(false, $"Opponent **{command.Arguments[0]}** does not have enough money to play"));
            }

            if (userCurrentBalance < gameBet)
            {
                return(new ValidationResult(false, $"User **{command.Author.Username}** does not have enough points"));
            }

            attackerBalance = userCurrentBalance.Value;
            defenderBalance = opponentsBalance.Value;

            return(new ValidationResult(true, string.Empty));
        }
Example #2
0
        public async Task <ValidationResult> ValidateCommandAsync(Command command)
        {
            var userBalance = await _userPointsRepository.GetUserBalanceAsync(command.Author.Id);

            if (userBalance is null)
            {
                return(new ValidationResult(false, "You alread own a wallet"));
            }

            return(new ValidationResult(true));
        }
Example #3
0
        public async Task HandleAsync(Command command)
        {
            var userPoints = await _userPointsRepository.GetUserBalanceAsync(command.Author.Id);

            if (userPoints is null)
            {
                await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                     "Can't find your wallet. Use ?register to create wallet");

                return;
            }

            await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                 $"**{command.Author.Username}** currently has **{string.Format("{0:0.##}", userPoints)}** points");
        }
Example #4
0
        private async Task HandleJoinReaction(Reaction reaction)
        {
            if (reaction.IsAdded)
            {
                var game = _blackjackRepository.GetGame(reaction.MessageId);
                if (!game.IsInProgress)
                {
                    var userBalance = await _usersPointsRepository.GetUserBalanceAsync(reaction.UserId);

                    userBalance = 100000; // DEV
                    if (userBalance.Value >= game.BetAmount)
                    {
                        game.AddMember(reaction.UserId, reaction.Member.User.Username);

                        await _discordRestClient.PostMessage(reaction.ChannelId,
                                                             $"User {MessageUtilities.MentionUser(reaction.UserId)} joined the game");
                    }
                    else
                    {
                        await _discordRestClient.PostMessage(reaction.ChannelId,
                                                             $"User {MessageUtilities.MentionUser(reaction.UserId)} " +
                                                             "does not have enough points to join the game");
                    }
                }
                else
                {
                    await _discordRestClient.PostMessage(reaction.ChannelId,
                                                         $"{MessageUtilities.MentionUser(reaction.UserId)} game already started");
                }
            }
            else
            {
                var game = _blackjackRepository.GetGame(reaction.MessageId);
                if (!game.IsInProgress)
                {
                    game.RemoveMember(reaction.MessageId);

                    await _discordRestClient.PostMessage(reaction.ChannelId,
                                                         $"User {MessageUtilities.MentionUser(reaction.UserId)} leaved the game");
                }
            }
        }