Exemple #1
0
            public async Task ExecuteGroupAsync(CommandContext ctx)
            {
                if (this.Shared.IsEventRunningInChannel(ctx.Channel.Id))
                {
                    throw new CommandFailedException("Another event is already running in the current channel!");
                }

                DiscordDmChannel dm = await ctx.Client.CreateDmChannelAsync(ctx.User.Id);

                if (dm == null)
                {
                    throw new CommandFailedException("Please enable direct messages, so I can ask you about the word to guess.");
                }

                await dm.EmbedAsync("What is the secret word?", StaticDiscordEmoji.Question, this.ModuleColor);

                await this.InformAsync(ctx, StaticDiscordEmoji.Question, $"{ctx.User.Mention}, check your DM. When you give me the word, the game will start.");

                MessageContext mctx = await ctx.Client.GetInteractivity().WaitForMessageAsync(
                    xm => xm.Channel == dm && xm.Author.Id == ctx.User.Id,
                    TimeSpan.FromMinutes(1)
                    );

                if (mctx == null)
                {
                    await this.InformFailureAsync(ctx, "I didn't get the word, so I will abort the game.");

                    return;
                }
                else
                {
                    await dm.EmbedAsync($"Alright! The word is: {Formatter.Bold(mctx.Message.Content)}", StaticDiscordEmoji.Information, this.ModuleColor);
                }

                var hangman = new HangmanGame(ctx.Client.GetInteractivity(), ctx.Channel, mctx.Message.Content, mctx.User);

                this.Shared.RegisterEventInChannel(hangman, ctx.Channel.Id);
                try {
                    await hangman.RunAsync();

                    if (hangman.Winner != null)
                    {
                        await this.Database.UpdateUserStatsAsync(hangman.Winner.Id, GameStatsType.HangmansWon);
                    }
                } finally {
                    this.Shared.UnregisterEventInChannel(ctx.Channel.Id);
                }
            }