コード例 #1
0
        public static async Task <bool> WaitForBoolReplyAsync(this InteractivityExtension interactivity, CommandContext ctx)
        {
            InteractivityService ins = ctx.Services.GetRequiredService <InteractivityService>();

            ins.AddPendingResponse(ctx.Channel.Id, ctx.User.Id);

            bool response = await WaitForBoolReplyAsync(interactivity, ctx.Channel, ctx.User);

            if (!ins.RemovePendingResponse(ctx.Channel.Id, ctx.User.Id))
            {
                throw new ConcurrentOperationException("Failed to remove user from pending list");
            }

            return(response);
        }
コード例 #2
0
        public static async Task <List <string>?> WaitAndParsePollOptionsAsync(this CommandContext ctx, string separator = ";")
        {
            InteractivityService interactivity = ctx.Services.GetRequiredService <InteractivityService>();

            interactivity.AddPendingResponse(ctx.Channel.Id, ctx.User.Id);

            InteractivityResult <DiscordMessage> mctx = await ctx.Client.GetInteractivity().WaitForMessageAsync(
                xm => xm.Author == ctx.User && xm.Channel == ctx.Channel
                );

            if (!interactivity.RemovePendingResponse(ctx.Channel.Id, ctx.User.Id))
            {
                throw new ConcurrentOperationException("Failed to remove user from pending list");
            }

            return(mctx.TimedOut
                ? null
                : mctx.Result.Content.Split(separator, StringSplitOptions.RemoveEmptyEntries)
                   .Distinct()
                   .ToList());
        }