From 2a411a00a6ca9279909d0a070fd91021a1e054ae Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 15 Nov 2017 18:21:36 +0100 Subject: [PATCH] You can now specify 'allin' instead of the amount when playing .wheel, .br and .bf --- .../Modules/Gambling/FlipCoinCommands.cs | 19 +++++++++++--- NadekoBot.Core/Modules/Gambling/Gambling.cs | 25 +++++++++++++++---- .../Gambling/WheelOfFortuneCommands.cs | 21 +++++++++++++--- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/NadekoBot.Core/Modules/Gambling/FlipCoinCommands.cs b/NadekoBot.Core/Modules/Gambling/FlipCoinCommands.cs index 1658022e..3bb6c01b 100644 --- a/NadekoBot.Core/Modules/Gambling/FlipCoinCommands.cs +++ b/NadekoBot.Core/Modules/Gambling/FlipCoinCommands.cs @@ -20,14 +20,16 @@ namespace NadekoBot.Modules.Gambling private readonly IImageCache _images; private readonly IBotConfigProvider _bc; private readonly CurrencyService _cs; - + private readonly DbService _db; private static readonly NadekoRandom rng = new NadekoRandom(); - public FlipCoinCommands(IDataCache data, CurrencyService cs, IBotConfigProvider bc) + public FlipCoinCommands(IDataCache data, CurrencyService cs, + IBotConfigProvider bc, DbService db) { _images = data.LocalImages; _bc = bc; _cs = cs; + _db = db; } [NadekoCommand, Usage, Description, Aliases] @@ -86,7 +88,18 @@ namespace NadekoBot.Modules.Gambling } [NadekoCommand, Usage, Description, Aliases] - public async Task Betflip(int amount, BetFlipGuess guess) + public Task Betflip(Allin _, BetFlipGuess guess) + { + long cur; + using (var uow = _db.UnitOfWork) + { + cur = uow.Currency.GetUserCurrency(Context.User.Id); + } + return Betflip(cur, guess); + } + + [NadekoCommand, Usage, Description, Aliases] + public async Task Betflip(long amount, BetFlipGuess guess) { if (amount < _bc.BotConfig.MinimumBetAmount) { diff --git a/NadekoBot.Core/Modules/Gambling/Gambling.cs b/NadekoBot.Core/Modules/Gambling/Gambling.cs index 9defa74f..c6a05aa0 100644 --- a/NadekoBot.Core/Modules/Gambling/Gambling.cs +++ b/NadekoBot.Core/Modules/Gambling/Gambling.cs @@ -278,9 +278,9 @@ namespace NadekoBot.Modules.Gambling // }); // return Task.CompletedTask; //} + public enum Allin { Allin, All } - [NadekoCommand, Usage, Description, Aliases] - public async Task BetRoll(long amount) + private async Task InternallBetroll(long amount) { if (amount < 1) return; @@ -303,24 +303,39 @@ namespace NadekoBot.Modules.Gambling { str += GetText("br_win", (amount * _bc.BotConfig.Betroll67Multiplier) + CurrencySign, 66); await _cs.AddAsync(Context.User, "Betroll Gamble", - (int) (amount * _bc.BotConfig.Betroll67Multiplier), false).ConfigureAwait(false); + (int)(amount * _bc.BotConfig.Betroll67Multiplier), false).ConfigureAwait(false); } else if (rnd < 100) { str += GetText("br_win", (amount * _bc.BotConfig.Betroll91Multiplier) + CurrencySign, 90); await _cs.AddAsync(Context.User, "Betroll Gamble", - (int) (amount * _bc.BotConfig.Betroll91Multiplier), false).ConfigureAwait(false); + (int)(amount * _bc.BotConfig.Betroll91Multiplier), false).ConfigureAwait(false); } else { str += GetText("br_win", (amount * _bc.BotConfig.Betroll100Multiplier) + CurrencySign, 99) + " 👑"; await _cs.AddAsync(Context.User, "Betroll Gamble", - (int) (amount * _bc.BotConfig.Betroll100Multiplier), false).ConfigureAwait(false); + (int)(amount * _bc.BotConfig.Betroll100Multiplier), false).ConfigureAwait(false); } } await Context.Channel.SendConfirmAsync(str).ConfigureAwait(false); } + [NadekoCommand, Usage, Description, Aliases] + public Task BetRoll(long amount) + => InternallBetroll(amount); + + [NadekoCommand, Usage, Description, Aliases] + public Task BetRoll(Allin _) + { + long cur; + using (var uow = _db.UnitOfWork) + { + cur = uow.Currency.GetUserCurrency(Context.User.Id); + } + return InternallBetroll(cur); + } + [NadekoCommand, Usage, Description, Aliases] public async Task Leaderboard(int page = 1) { diff --git a/NadekoBot.Core/Modules/Gambling/WheelOfFortuneCommands.cs b/NadekoBot.Core/Modules/Gambling/WheelOfFortuneCommands.cs index ecbf4489..e8047008 100644 --- a/NadekoBot.Core/Modules/Gambling/WheelOfFortuneCommands.cs +++ b/NadekoBot.Core/Modules/Gambling/WheelOfFortuneCommands.cs @@ -15,16 +15,31 @@ namespace NadekoBot.Modules.Gambling { private readonly CurrencyService _cs; private readonly IBotConfigProvider _bc; + private readonly DbService _db; - public WheelOfFortuneCommands(CurrencyService cs, IBotConfigProvider bc) + public WheelOfFortuneCommands(CurrencyService cs, IBotConfigProvider bc, + DbService db) { _cs = cs; _bc = bc; + _db = db; + } + + public enum Allin { Allin, All } + + [NadekoCommand, Usage, Description, Aliases] + public Task WheelOfFortune(Allin _) + { + long cur; + using (var uow = _db.UnitOfWork) + { + cur = uow.Currency.GetUserCurrency(Context.User.Id); + } + return WheelOfFortune(cur); } [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - public async Task WheelOfFortune(int bet) + public async Task WheelOfFortune(long bet) { const int minBet = 10; if (bet < minBet)