private async Task MakeBet(BetCommand b) { if (Context.Message.MentionedUserIds.Count == 1) { ulong mentionedId = Context.Message.MentionedUserIds.First(); var dealer = await Context.Guild.GetUserAsync(mentionedId).ConfigureAwait(false); try { var round = await _db.Rounds .AsNoTracking() .Where(x => x.RoundStatus == RoundStatus.Open) .Include(x => x.Bets) .FirstOrDefaultAsync() .ConfigureAwait(false); if (round != null && round.DealerId == mentionedId) { int min = 0; int max = 0; string roundTypeStr = Utils.GetRoundTypeName(round.RoundType); switch (round.RoundType) { case RoundType.Pick1: min = _config.Min1; max = _config.Max1; break; case RoundType.Pick2: min = (b.PlayType == PlayType.Straight) ? _config.Min2Str : _config.Min2Any; max = (b.PlayType == PlayType.Straight) ? _config.Max2Str : _config.Max2Any; break; case RoundType.Pick3: min = (b.PlayType == PlayType.Straight) ? _config.Min3Str : _config.Min3Any; max = (b.PlayType == PlayType.Straight) ? _config.Max3Str : _config.Max3Any; break; } // parse bet itself if (b.Amount >= min && b.Amount <= max) { // can only bet max int total = round.Bets .Where(x => x.UserId == Context.User.Id && (round.RoundType == RoundType.Pick1 || x.PlayType == b.PlayType)) .Sum(x => x.Amount); int userTotal = total + b.Amount.Value; if (userTotal > max) { await SendBetError(round, roundTypeStr, $"Bet amount **{b.Amount.Value.AddCommas()}** is too high.\nFor this round, the max bet is **{max.AddCommas()}** for {b.PlayType} and you've bet a total of **{total.AddCommas()}**.\n" + string.Format(REFUND, dealer)).ConfigureAwait(false); } // parse picks else if (round.RoundType == RoundType.Pick1) { if (b.Pick1 >= 0 && b.Pick1 <= 9 && (b.Quick || (!b.Pick2.HasValue && !b.Pick3.HasValue))) { await MakeBetDb(b, round).ConfigureAwait(false); } else { await SendBetError(round, roundTypeStr, $"Picks not parsed (out of range, **0** - **9**)\n" + string.Format(REFUND, dealer)).ConfigureAwait(false); } } else if (round.RoundType == RoundType.Pick2) { if (b.Pick1 >= 0 && b.Pick2 >= 0 && b.Pick1 <= 9 && b.Pick2 <= 9 && (b.Quick || !b.Pick3.HasValue)) { await MakeBetDb(b, round).ConfigureAwait(false); } else { await SendBetError(round, roundTypeStr, $"Picks not parsed (out of range, **00** - **99**)\n" + string.Format(REFUND, dealer)).ConfigureAwait(false); } } else if (round.RoundType == RoundType.Pick3) { if (b.Pick1 >= 0 && b.Pick2 >= 0 && b.Pick3 >= 0 && b.Pick1 <= 9 && b.Pick2 <= 9 && b.Pick3 <= 9) { await MakeBetDb(b, round).ConfigureAwait(false); } else { await SendBetError(round, roundTypeStr, $"Picks not parsed (out of range, **000** - **999**)\n" + string.Format(REFUND, dealer)).ConfigureAwait(false); } } } else { string playType = (round.RoundType == RoundType.Pick1) ? PlayType.Single.ToString() : b.PlayType.Value.ToString(); await SendBetError(round, roundTypeStr, $"Bet amount not parsed (out of range, **{min}** - **{max}** for **{playType}** play)\n" + string.Format(REFUND, dealer)).ConfigureAwait(false); } } } catch (Exception ex) { await Context.Message.Channel.SendMessageAsync(ex.Message).ConfigureAwait(false); } } }
private async Task BetConfirmation(Bet item, SocketMessage betMsg, string user) { string play = item.PlayType.ToString(); string quick = (item.IsQuick) ? " (quick)" : string.Empty; int win = 0; int secs = 0; switch (item.Round.RoundType) { case RoundType.Pick1: win = AdminModule.PICK1_MULTI_SINGLE * item.Amount; secs = _config.Secs1; break; case RoundType.Pick2: if (item.PlayType == PlayType.Straight) { win = AdminModule.PICK2_MULTI_STRAIGHT * item.Amount; } else if (item.PlayType == PlayType.Any) { win = AdminModule.PICK2_MULTI_ANY * item.Amount; } secs = _config.Secs2; break; case RoundType.Pick3: if (item.PlayType == PlayType.Straight) { win = AdminModule.PICK3_MULTI_STRAIGHT * item.Amount; } else if (item.PlayType == PlayType.Any) { win = AdminModule.PICK3_MULTI_ANY * item.Amount; } secs = _config.Secs3; break; } bool first = false; if (!item.Round.Ends.HasValue) { item.Round.Ends = DateTime.Now.AddSeconds(secs); first = true; } int secsLeft = (int)(item.Round.Ends.Value - DateTime.Now).TotalSeconds + 1; string roundTypeStr = Utils.GetRoundTypeName(item.Round.RoundType); var builder = new EmbedBuilder() .WithColor(Color.SUCCESS) .WithFooter(footer => { footer.WithText($"Round #{item.RoundId} ({roundTypeStr}) ends in {Utils.ConvertToCompoundDuration(secsLeft)}") .WithIconUrl(Asset.CLOCK); }) .WithAuthor(author => { author.WithName($"{play} play '{item.Pick1}{item.Pick2}{item.Pick3}'{quick}, placed by @{user} for {item.Amount.AddCommas()}") .WithIconUrl(Asset.SUCCESS); }) .WithDescription($"They could win a total of **{win.AddCommas()}**!"); var embed = builder.Build(); await betMsg.Channel.SendMessageAsync(string.Empty, embed : embed).ConfigureAwait(false); item.Confirmed = true; _db.Update(item); await _db.SaveChangesAsync().ConfigureAwait(false); if (first) { var context = new CommandContext(_client, (IUserMessage)betMsg); _ = Task.Delay(secsLeft * 1000) .ContinueWith(_ => _commands.ExecuteAsync(context, "close", _services).ConfigureAwait(false)) .ConfigureAwait(false); } }