Пример #1
0
        public async Task RollDice(int bet, int side)
        {
            if (side < 1 || side > 6)
            {
                await ReplyFailureEmbed("Please choose a side between 1-6");

                return;
            }

            if (bet <= 0)
            {
                await ReplyFailureEmbed("Please specify a bet larger than 0.");

                return;
            }

            var availableCoins = _coinRepository.GetCoins(Context.User.Id);

            if (bet > availableCoins)
            {
                await ReplyFailureEmbed(
                    $"Please specify a bet smaller or equal to your total Sora coin amount ({availableCoins.ToString()} SC).");

                return;
            }

            int  roll = _rand.GetRandomNext(1, 7);
            bool won  = roll == side;

            if (won)
            {
                await _coinRepository.GiveAmount(Context.User.Id, (uint)(bet * 5));  // *5 since we never take away the initial bet
            }
            else if (!await _coinRepository.TryTakeAmount(Context.User.Id, (uint)bet))
            {
                await ReplyFailureEmbed("You didn't have enough Sora coins for the transfer. Try again");

                return;
            }

            if (won)
            {
                await ReplyMoneyEmbed($"Congratulations! You won {(bet * 6).ToString()} Sora Coins!");
            }
            else
            {
                await ReplyMoneyLostEmbed($"You lost :( The dice was {roll.ToString()}. Better luck next time!");
            }
        }
Пример #2
0
        public async Task <IActionResult> ApproveRequest(uint requestId)
        {
            // Check if request exists
            var req = await _waifuRequestRepo.GetWaifuRequest(requestId);

            if (!req)
            {
                return(NotFound("Request doesn't exist"));
            }

            var wr = ~req;

            // Check if waifu already exists!
            if (await _waifuRequestRepo.WaifuExists(wr.Name.Trim()))
            {
                return(BadRequest("Waifu already exists!"));
            }

            // Change the state
            await _waifuRequestRepo.ChangeRequestStatus(requestId, RequestState.Accepted);

            // Give user reward
            await _coinRepository.GiveAmount(wr.UserId, _REQUEST_REWARD);

            // add waifu
            await _waifuRequestRepo.AddWaifu(wr);

            // check if user wants to be notified
            bool notify = await _waifuRequestRepo.UserHasNotificationOn(wr.UserId);

            // notify
            if (notify)
            {
                await this.NotifyUser(wr, true);
            }

            return(Ok());
        }