Esempio n. 1
0
        public async Task Flip(string sAmount, string side = "t", [Remainder] string str = "")
        {
            var user = (SocketGuildUser)Context.User;
            var rnd  = new Random();

            side = side.ToLower();

            if (!(side.Equals("t") || side.Equals("h") || side.Equals("tails") || side.Equals("heads")))
            {
                await Context.Channel.SendMessageAsync("Pick heads or tails!");

                return;
            }

            int amount = ToastieUtil.ParseAmount(sAmount, user);

            if (amount < 0)
            {
                await Context.Channel.SendMessageAsync("Pick an amount! number, all, half, or x/y.");

                return;
            }
            if (amount == 0)
            {
                await Context.Channel.SendMessageAsync("You have no toasties...");

                return;
            }

            try
            {
                await BalanceDb.AddToasties(user.Id, -amount, Context.Guild.Id);
            }
            catch (Exception ex)
            {
                await Context.Channel.SendMessageAsync(ex.Message);

                return;
            }

            if (BalanceDb.GetToasties(Context.Client.CurrentUser.Id, Context.Guild.Id) < amount)
            {
                string prefix = Program.GetPrefix(Context);
                await Context.Channel.SendMessageAsync("Tch, I don't have enough toasties... I will recover eventually by stealing toasties from all of you. :fox:" +
                                                       $"But if you want to speed up the process you can give me some using the `{prefix}give` or `{prefix}at` commands.");

                await BalanceDb.AddToasties(user.Id, amount, Context.Guild.Id);

                return;
            }

            if (ToastieUtil.FiftyFifty())
            {
                await BalanceDb.AddToasties(user.Id, amount * 2, Context.Guild.Id);

                await BalanceDb.AddToasties(Context.Client.CurrentUser.Id, -amount, Context.Guild.Id);

                string resp = "";
                if (amount >= 50000 && rnd.Next(5) == 1)
                {
                    resp = "Tch... I'll get you next time.";
                }
                await Context.Channel.SendMessageAsync(resp, false, ToastieUtil.FlipWinEmbed(user, amount).Build());
            }
            else
            {
                await BalanceDb.AddToasties(Context.Client.CurrentUser.Id, amount, Context.Guild.Id);

                string resp = "";
                if (amount >= 50000 && rnd.Next(5) == 1)
                {
                    resp = "I'll take those.";
                }
                await Context.Channel.SendMessageAsync(resp, false, ToastieUtil.FlipLoseEmbed(user, amount).Build());
            }
        }