diff --git a/NadekoBot/Modules/Administration/AdministrationModule.cs b/NadekoBot/Modules/Administration/AdministrationModule.cs index 4556d441..9b2e6c4e 100644 --- a/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -914,7 +914,7 @@ namespace NadekoBot.Modules.Administration lastmsgId = msgs[msgs.Count - 1].Id; cnt -= 100; } - await e.User.SendFile($"Chatlog-{e.Server.Name}/#{e.Channel.Name}-{DateTime.Now}.txt", JsonConvert.SerializeObject(new { Messages = msgs.Select(s => s.ToString()) }, Formatting.Indented).ToStream()); + await e.User.SendFile($"Chatlog-{e.Server.Name}/#{e.Channel.Name}-{DateTime.Now}.txt", JsonConvert.SerializeObject(new { Messages = msgs.Select(s => s.ToString()) }, Formatting.Indented).ToStream()).ConfigureAwait(false); }); }); diff --git a/NadekoBot/Modules/Gambling/FlipCoinCommand.cs b/NadekoBot/Modules/Gambling/FlipCoinCommand.cs index b28f8346..6d8edf3c 100644 --- a/NadekoBot/Modules/Gambling/FlipCoinCommand.cs +++ b/NadekoBot/Modules/Gambling/FlipCoinCommand.cs @@ -18,11 +18,65 @@ namespace NadekoBot.Modules.Gambling .Description("Flips coin(s) - heads or tails, and shows an image. | `$flip` or `$flip 3`") .Parameter("count", ParameterType.Optional) .Do(FlipCoinFunc()); + + cgb.CreateCommand(Module.Prefix + "betflip") + .Alias(Prefix+"bf") + .Description($"Bet to guess will the result be heads or tails. Guessing award you double flowers you've bet. | `{Prefix}bf 5 heads` or `{Prefix}bf 3 t`") + .Parameter("amount", ParameterType.Required) + .Parameter("guess", ParameterType.Required) + .Do(BetFlipCoinFunc()); } private readonly Random rng = new Random(); + public Func BetFlipCoinFunc() => async e => + { + + var amountstr = e.GetArg("amount").Trim(); + + var guessStr = e.GetArg("guess").Trim().ToUpperInvariant(); + if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS") + return; + + int amount; + if (!int.TryParse(amountstr, out amount) || amount < 1) + return; + + var userFlowers = GamblingModule.GetUserFlowers(e.User.Id); + + if (userFlowers < amount) + { + await e.Channel.SendMessage($"{e.User.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You only have {userFlowers}{NadekoBot.Config.CurrencySign}.").ConfigureAwait(false); + return; + } + + await FlowersHandler.RemoveFlowers(e.User, "Betflip Gamble", (int)amount, true).ConfigureAwait(false); + //heads = true + //tails = false + + var guess = guessStr == "HEADS" || guessStr == "H"; + bool result = false; + if (rng.Next(0, 2) == 1) { + await e.Channel.SendFile("heads.png", Properties.Resources.heads.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false); + result = true; + } + else { + await e.Channel.SendFile("tails.png", Properties.Resources.tails.ToStream(System.Drawing.Imaging.ImageFormat.Png)).ConfigureAwait(false); + } + + string str; + if (guess == result) + { + str = $"{e.User.Mention}`You guessed it!` You won {amount * 2}{NadekoBot.Config.CurrencySign}"; + await FlowersHandler.AddFlowersAsync(e.User, "Betflip Gamble", amount * 2, true).ConfigureAwait(false); + + } + else + str = $"{e.User.Mention}`More luck next time.`"; + + await e.Channel.SendMessage(str).ConfigureAwait(false); + }; public Func FlipCoinFunc() => async e => { diff --git a/NadekoBot/Modules/Gambling/GamblingModule.cs b/NadekoBot/Modules/Gambling/GamblingModule.cs index a9494715..6b97ea09 100644 --- a/NadekoBot/Modules/Gambling/GamblingModule.cs +++ b/NadekoBot/Modules/Gambling/GamblingModule.cs @@ -156,7 +156,7 @@ namespace NadekoBot.Modules.Gambling return; } - await FlowersHandler.RemoveFlowers(e.User, "Betroll Gamble", (int)amount, true); + await FlowersHandler.RemoveFlowers(e.User, "Betroll Gamble", (int)amount, true).ConfigureAwait(false); var rng = new Random().Next(0, 101); var str = $"{e.User.Mention} `You rolled {rng}.` "; @@ -167,19 +167,19 @@ namespace NadekoBot.Modules.Gambling else if (rng < 90) { str += $"Congratulations! You won {amount * 2}{NadekoBot.Config.CurrencySign} for rolling above 66"; - await FlowersHandler.AddFlowersAsync(e.User, "Betroll Gamble", amount * 2, true); + await FlowersHandler.AddFlowersAsync(e.User, "Betroll Gamble", amount * 2, true).ConfigureAwait(false); } else if (rng < 100) { str += $"Congratulations! You won {amount * 3}{NadekoBot.Config.CurrencySign} for rolling above 90."; - await FlowersHandler.AddFlowersAsync(e.User, "Betroll Gamble", amount * 3, true); + await FlowersHandler.AddFlowersAsync(e.User, "Betroll Gamble", amount * 3, true).ConfigureAwait(false); } else { str += $"👑 Congratulations! You won {amount * 10}{NadekoBot.Config.CurrencySign} for rolling **100**. 👑"; - await FlowersHandler.AddFlowersAsync(e.User, "Betroll Gamble", amount * 10, true); + await FlowersHandler.AddFlowersAsync(e.User, "Betroll Gamble", amount * 10, true).ConfigureAwait(false); } - await e.Channel.SendMessage(str); + await e.Channel.SendMessage(str).ConfigureAwait(false); }); @@ -205,7 +205,7 @@ namespace NadekoBot.Modules.Gambling }); } - private static long GetUserFlowers(ulong userId) => + public static long GetUserFlowers(ulong userId) => Classes.DbHandler.Instance.GetStateByUserId((long)userId)?.Value ?? 0; } }