Пример #1
0
        public static async Task <bool> WaitForBoolReplyAsync(this InteractivityExtension interactivity, ulong cid, ulong uid, SharedData shared = null)
        {
            if (!(shared is null))
            {
                shared.AddPendingResponse(cid, uid);
            }

            bool           response = false;
            MessageContext mctx     = await interactivity.WaitForMessageAsync(
                m => {
                if (m.ChannelId != cid || m.Author.Id != uid)
                {
                    return(false);
                }
                bool?b   = CustomBoolConverter.TryConvert(m.Content);
                response = b ?? false;
                return(b.HasValue);
            }
                );

            if (!(shared is null) && !shared.TryRemovePendingResponse(cid, uid))
            {
                throw new ConcurrentOperationException("Failed to remove user from waiting list. This is bad!");
            }

            return(response);
        }
Пример #2
0
        public static async Task <MessageContext> WaitForDmReplyAsync(this InteractivityExtension interactivity, DiscordDmChannel dm, ulong cid, ulong uid, SharedData shared = null)
        {
            if (!(shared is null))
            {
                shared.AddPendingResponse(cid, uid);
            }

            MessageContext mctx = await interactivity.WaitForMessageAsync(xm => xm.Channel == dm && xm.Author.Id == uid, TimeSpan.FromMinutes(1));

            if (!(shared is null) && !shared.TryRemovePendingResponse(cid, uid))
            {
                throw new ConcurrentOperationException("Failed to remove user from waiting list. This is bad!");
            }

            return(mctx);
        }
Пример #3
0
        internal static async Task <List <string> > WaitAndParsePollOptionsAsync(this CommandContext ctx)
        {
            SharedData shared = ctx.Services.GetService <SharedData>();

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

            var mctx = await ctx.Client.GetInteractivity().WaitForMessageAsync(xm => xm.Author.Id == ctx.User.Id && xm.Channel.Id == ctx.Channel.Id);

            if (!shared.TryRemovePendingResponse(ctx.Channel.Id, ctx.User.Id))
            {
                throw new ConcurrentOperationException("Failed to remove user from waiting list. This isn't good...");
            }

            if (mctx.TimedOut)
            {
                return(null);
            }

            return(mctx.Result.Content.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList());
        }
Пример #4
0
        internal static async Task <DiscordUser> WaitForGameOpponentAsync(this CommandContext ctx)
        {
            SharedData shared = ctx.Services.GetService <SharedData>();

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

            var mctx = await ctx.Client.GetInteractivity().WaitForMessageAsync(xm =>
            {
                if (xm.Author.IsBot || xm.Author.Id == ctx.User.Id || xm.Channel.Id != ctx.Channel.Id)
                {
                    return(false);
                }
                string[] split = xm.Content.ToLowerInvariant().Split(' ');

                return(split.Length == 1 && (split[0] == "me" || split[0] == "i"));
            });

            if (!shared.TryRemovePendingResponse(ctx.Channel.Id, ctx.User.Id))
            {
                throw new ConcurrentOperationException("Failed to remove user from waiting list. This isn't good...");
            }

            return(mctx.TimedOut ? null : mctx.Result.Author);
        }