Esempio n. 1
0
        async Task <SocketMessage> WaitForReaponseAsync(IContext Context, ICriteria <SocketMessage> Interactive, TimeSpan?Timeout = null)
        {
            Timeout = Timeout ?? TimeSpan.FromSeconds(15);
            var Trigger = new TaskCompletionSource <SocketMessage>();

            async Task InteractiveHandlerAsync(SocketMessage Message)
            {
                if (Message.Author.IsBot)
                {
                    return;
                }
                var Result = await Interactive.JudgeAsync(Context, Message).ConfigureAwait(false);

                if (Result)
                {
                    Trigger.SetResult(Message);
                }
            }

            (Context.Client as DiscordSocketClient).MessageReceived += InteractiveHandlerAsync;
            var PersonalTask = await Task.WhenAny(Trigger.Task, Task.Delay(Timeout.Value));

            (Context.Client as DiscordSocketClient).MessageReceived -= InteractiveHandlerAsync;
            return(PersonalTask == Trigger.Task ? await Trigger.Task.ConfigureAwait(false) : null);
        }