public Task Betflip(Allin _, BetFlipGuess guess) { long cur; using (var uow = _db.UnitOfWork) { cur = uow.Currency.GetUserCurrency(Context.User.Id); } return(Betflip(cur, guess)); }
public async Task Betflip(ShmartNumber amount, BetFlipGuess guess) { if (!await CheckBetMandatory(amount).ConfigureAwait(false) || amount == 1) { return; } var removed = await _cs.RemoveAsync(Context.User, "Betflip Gamble", amount, false, gamble : true).ConfigureAwait(false); if (!removed) { await ReplyErrorLocalized("not_enough", Bc.BotConfig.CurrencyPluralName).ConfigureAwait(false); return; } BetFlipGuess result; Uri imageToSend; var coins = _images.ImageUrls.Coins; if (rng.Next(0, 1000) <= 499) { imageToSend = coins.Heads[rng.Next(0, coins.Heads.Length)]; result = BetFlipGuess.Heads; } else { imageToSend = coins.Tails[rng.Next(0, coins.Tails.Length)]; result = BetFlipGuess.Tails; } string str, title; if (guess == result) { var toWin = (long)(amount * Bc.BotConfig.BetflipMultiplier); title = GetText("flip_win"); str = Context.User.Mention + ", " + GetText("flip_guess", toWin + Bc.BotConfig.CurrencySign) + "\n" + GetText("flip_dosame"); await _cs.AddAsync(Context.User, "Betflip Gamble", toWin, false, gamble : true).ConfigureAwait(false); } else { title = GetText("flip_lose"); str = Context.User.Mention + ", " + GetText("flip_positive") + "\n" + GetText("better_luck"); } await Context.Channel.EmbedAsync(new EmbedBuilder() .WithTitle(title) .WithDescription(str) .WithOkColor() .WithThumbnailUrl(imageToSend.ToString())).ConfigureAwait(false); }
public async Task Betflip(long amount, BetFlipGuess guess) { if (amount < _bc.BotConfig.MinimumBetAmount) { await ReplyErrorLocalized("min_bet_limit", _bc.BotConfig.MinimumBetAmount + _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } var removed = await _cs.RemoveAsync(Context.User, "Betflip Gamble", amount, false, gamble : true).ConfigureAwait(false); if (!removed) { await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencyPluralName).ConfigureAwait(false); return; } BetFlipGuess result; string imageToSend; var coins = _images.ImageUrls.Coins; if (rng.Next(0, 2) == 1) { imageToSend = coins.Heads[rng.Next(0, coins.Heads.Length)]; result = BetFlipGuess.Heads; } else { imageToSend = coins.Tails[rng.Next(0, coins.Tails.Length)]; result = BetFlipGuess.Tails; } string str; if (guess == result) { var toWin = (int)Math.Round(amount * _bc.BotConfig.BetflipMultiplier); str = Context.User.Mention + " " + GetText("flip_guess", toWin + _bc.BotConfig.CurrencySign); await _cs.AddAsync(Context.User, "Betflip Gamble", toWin, false, gamble : true).ConfigureAwait(false); } else { str = Context.User.Mention + " " + GetText("better_luck"); } await Context.Channel.EmbedAsync(new EmbedBuilder() .WithDescription(str) .WithOkColor() .WithImageUrl(imageToSend)); }
public async Task Betflip(ShmartNumber amount, BetFlipGuess guess) { if (!await CheckBetMandatory(amount).ConfigureAwait(false) || amount == 1) { return; } var removed = await _cs.RemoveAsync(ctx.User, "Betflip Gamble", amount, false, gamble : true).ConfigureAwait(false); if (!removed) { await ReplyErrorLocalizedAsync("not_enough", CurrencySign).ConfigureAwait(false); return; } BetFlipGuess result; Uri imageToSend; var coins = _images.ImageUrls.Coins; if (rng.Next(0, 1000) <= 499) { imageToSend = coins.Heads[rng.Next(0, coins.Heads.Length)]; result = BetFlipGuess.Heads; } else { imageToSend = coins.Tails[rng.Next(0, coins.Tails.Length)]; result = BetFlipGuess.Tails; } string str; if (guess == result) { var toWin = (long)(amount * _config.BetFlip.Multiplier); str = Format.Bold(ctx.User.ToString()) + " " + GetText("flip_guess", toWin + CurrencySign); await _cs.AddAsync(ctx.User, "Betflip Gamble", toWin, false, gamble : true).ConfigureAwait(false); } else { str = ctx.User.ToString() + " " + GetText("better_luck"); } await ctx.Channel.EmbedAsync(new EmbedBuilder() .WithDescription(str) .WithOkColor() .WithImageUrl(imageToSend.ToString())).ConfigureAwait(false); }
public async Task Betflip(int amount, BetFlipGuess guess) { if (amount < _bc.BotConfig.MinimumBetAmount) { await ReplyErrorLocalized("min_bet_limit", _bc.BotConfig.MinimumBetAmount + _bc.BotConfig.CurrencySign).ConfigureAwait(false); return; } var removed = await _cs.RemoveAsync(Context.User, "Betflip Gamble", amount, false).ConfigureAwait(false); if (!removed) { await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencyPluralName).ConfigureAwait(false); return; } BetFlipGuess result; IEnumerable <byte> imageToSend; if (rng.Next(0, 2) == 1) { imageToSend = _images.Heads; result = BetFlipGuess.Heads; } else { imageToSend = _images.Tails; result = BetFlipGuess.Tails; } string str; if (guess == result) { var toWin = (int)Math.Round(amount * _bc.BotConfig.BetflipMultiplier); str = Context.User.Mention + " " + GetText("flip_guess", toWin + _bc.BotConfig.CurrencySign); await _cs.AddAsync(Context.User, "Betflip Gamble", toWin, false).ConfigureAwait(false); } else { str = Context.User.Mention + " " + GetText("better_luck"); } using (var toSend = imageToSend.ToStream()) { await Context.Channel.SendFileAsync(toSend, "result.png", str).ConfigureAwait(false); } }
public async Task BetFlip(long amount, BetFlipGuess guess) { GuildConfig guildConfig = await _config.GetGuildConfigAsync(Context.Guild.Id); if (amount < guildConfig.BetFlipMin) { await Context.Channel.SendErrorAsync($"The minimum bet is `{guildConfig.BetFlipMin}` {guildConfig.CurrencyIcon}") .ConfigureAwait(false); return; } bool removed = await _currency.RemoveCurrencyAsync(Context.User.Id, Context.Guild.Id, Context.Channel.Id, Context.Message.Id, "BetFlip Entry", amount).ConfigureAwait(false); if (!removed) { await Context.Channel.SendErrorAsync($"Not enough {guildConfig.CurrencyIcon}\n" + $"You have `{await _currency.GetCurrencyAsync(Context.User.Id, Context.Guild.Id):N0}`") .ConfigureAwait(false); return; } // TODO get images BetFlipGuess result = _rng.Next(0, 2) == 1 ? BetFlipGuess.Heads : BetFlipGuess.Tails; if (guess == result) { var payout = (long)Math.Ceiling(amount * guildConfig.BetFlipMultiplier); await _currency.AddCurrencyAsync(Context.User.Id, Context.Guild.Id, Context.Channel.Id, Context.Message.Id, "BetFlip Payout", payout).ConfigureAwait(false); await Context.Channel.EmbedAsync(new EmbedBuilder().WithDynamicColor(Context) .WithDescription( $"Result is: {result}\n{Context.User.Mention} Congratulations! You've won `{payout:N0}` {guildConfig.CurrencyIcon}\n" + $"New Balance: `{await _currency.GetCurrencyAsync(Context.User.Id, Context.Guild.Id):N0}` {guildConfig.CurrencyIcon}")) .ConfigureAwait(false); } else { await Context.Channel.EmbedAsync(new EmbedBuilder().WithErrorColor() .WithDescription($"Result is: {result}\n{Context.User.Mention} Better luck next time!\n" + $"New Balance: `{await _currency.GetCurrencyAsync(Context.User.Id, Context.Guild.Id):N0}` {guildConfig.CurrencyIcon}")) .ConfigureAwait(false); } }
public async Task Betflip(int amount, BetFlipGuess guess) { var user = (IGuildUser)Context.User; if (amount < _bc.BotConfig.MinimumBetAmount) { await ReplyErrorLocalized("min_bet_limit", $"{_bc.BotConfig.MinimumBetAmount}{_bc.BotConfig.CurrencySign}").ConfigureAwait(false); return; } var removed = await _cs.RemoveAsync(user, "Betflip Gamble", amount).ConfigureAwait(false); if (!removed) { await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencyPluralName).ConfigureAwait(false); return; } (IEnumerable <byte> imageToSend, var result) = rng.Next(0, 2) == 1 ? (_images.Heads, BetFlipGuess.Heads) : (_images.Tails, BetFlipGuess.Tails); string str; if (guess == result) { var toWin = (int)Math.Round(amount * _bc.BotConfig.BetflipMultiplier); str = $"{user.Mention} {GetText("flip_guess", $"{toWin}{_bc.BotConfig.CurrencySign}")}"; await _cs.AddAsync(user, "Betflip Gamble", toWin).ConfigureAwait(false); } else { str = $"{user.Mention} {GetText("better_luck")}"; } using var toSend = imageToSend.ToStream(); await Context.Channel.SendFileAsync(toSend, "result.png", str).ConfigureAwait(false); }