コード例 #1
0
        public async Task StartBlackjack(EventContext e, int bet)
        {
            using (var context = new MikiContext())
            {
                User user = await context.Users.FindAsync(e.Author.Id.ToDbLong());

                await user.AddCurrencyAsync(-bet, e.Channel);

                await context.SaveChangesAsync();
            }

            BlackjackManager bm = new BlackjackManager();

            IDiscordMessage message = await bm.CreateEmbed(e)
                                      .ToEmbed()
                                      .SendToChannel(e.Channel);

            Framework.Events.CommandMap map = new Framework.Events.CommandMap();
            SimpleCommandHandler        c   = new SimpleCommandHandler(map);

            c.AddPrefix("");
            c.AddCommand(new CommandEvent("hit")
                         .Default(async(ec) => await OnBlackjackHit(ec, bm, message, bet)));
            c.AddCommand(new CommandEvent("stand")
                         .SetAliases("knock", "stay", "stop")
                         .Default(async(ec) => await OnBlackjackHold(ec, bm, message, bet)));

            e.EventSystem.GetCommandHandler <SessionBasedCommandHandler>().AddSession(
                new CommandSession()
            {
                UserId = e.Author.Id, ChannelId = e.Channel.Id
            }, c, new TimeSpan(1, 0, 0));
        }
コード例 #2
0
ファイル: MarriageModule.cs プロジェクト: wowweemip-fan/Miki
        public async Task BuyMarriageSlotAsync(EventContext e)
        {
            using (var context = new MikiContext())
            {
                User user = await User.GetAsync(context, e.Author);

                int  limit     = 10;
                bool isDonator = await user.IsDonatorAsync(context);

                if (isDonator)
                {
                    limit += 5;
                }

                EmbedBuilder embed = new EmbedBuilder();

                if (user.MarriageSlots >= limit)
                {
                    embed.Description = $"For now, **{limit} slots** is the max. sorry :(";

                    if (limit == 10 && !isDonator)
                    {
                        embed.AddField("Pro tip!", "Donators get 5 more slots!")
                        .SetFooter("Check `>donate` for more information!", "");
                    }

                    embed.Color = new Color(1f, 0.6f, 0.4f);
                    embed.ToEmbed().QueueToChannel(e.Channel);
                    return;
                }

                int costForUpgrade = (user.MarriageSlots - 4) * 2500;

                embed.Description = $"Do you want to buy a Marriage slot for **{costForUpgrade}**?\n\nType `yes` to confirm.";
                embed.Color       = new Color(0.4f, 0.6f, 1f);

                SimpleCommandHandler commandHandler = new SimpleCommandHandler(new CommandMap());
                commandHandler.AddPrefix("");
                commandHandler.AddCommand(new CommandEvent("yes")
                                          .Default(async(cx) => await ConfirmBuyMarriageSlot(cx, costForUpgrade)));

                e.EventSystem.GetCommandHandler <SessionBasedCommandHandler>().AddSession(e.CreateSession(), commandHandler, new TimeSpan(0, 0, 20));

                embed.ToEmbed().QueueToChannel(e.Channel);
            }
        }