Beispiel #1
0
        /// <summary>
        /// Handles a reaction callback
        /// </summary>
        /// <param name="reaction">
        /// The reaction.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task <bool> HandleCallbackAsync(SocketReaction reaction)
        {
            var emote = reaction.Emote;

            if (emote.Equals(options.First))
            {
                page = 1;
            }
            else if (emote.Equals(options.Next))
            {
                if (page >= pages)
                {
                    return(false);
                }
                ++page;
            }
            else if (emote.Equals(options.Back))
            {
                if (page <= 1)
                {
                    return(false);
                }
                --page;
            }
            else if (emote.Equals(options.Last))
            {
                page = pages;
            }
            else if (emote.Equals(options.Stop))
            {
                await Message.DeleteAsync().ConfigureAwait(false);

                return(true);
            }
            else if (emote.Equals(options.Jump))
            {
                _ = Task.Run(async() =>
                {
                    var criteria = new Criteria <SocketMessage>()
                                   .AddCriterion(new EnsureSourceChannelCriterion())
                                   .AddCriterion(new EnsureFromUserCriterion(reaction.UserId))
                                   .AddCriterion(new EnsureIsIntegerCriterion());
                    var response = await Interactive.NextMessageAsync(Context, criteria, TimeSpan.FromSeconds(15));
                    var request  = int.Parse(response.Content);
                    if (request < 1 || request > pages)
                    {
                        _ = response.DeleteAsync().ConfigureAwait(false);
                        await Interactive.ReplyAndDeleteAsync(Context, options.Stop.Name);
                        return;
                    }

                    page = request;
                    _    = response.DeleteAsync().ConfigureAwait(false);
                    await RenderAsync().ConfigureAwait(false);
                });
            }
            else if (emote.Equals(options.Info))
            {
                await Interactive.ReplyAndDeleteAsync(Context, options.InformationText, timeout : options.InfoTimeout);

                return(false);
            }

            _ = Message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);
            await RenderAsync().ConfigureAwait(false);

            return(false);
        }
Beispiel #2
0
        public async Task <bool> HandleCallbackAsync(SocketReaction reaction)
        {
            var emote = reaction.Emote;

            if (emote.Equals(options.First))
            {
                page = 1;
            }
            else if (emote.Equals(options.Next))
            {
                if (page >= pages)
                {
                    return(false);
                }
                ++page;
            }
            else if (emote.Equals(options.Back))
            {
                if (page <= 1)
                {
                    return(false);
                }
                --page;
            }
            else if (emote.Equals(options.Last))
            {
                page = pages;
            }
            else if (emote.Equals(options.Stop))
            {
                await Message.DeleteAsync().ConfigureAwait(false);

                return(true);
            }
            else if (emote.Equals(options.Jump))
            {
                _ = Task.Run(async() =>
                {
                    var msg      = await Context.Channel.SendMessageAsync("Which page do you wish to jump to? <:KannaHype:571690048001671238>");
                    var criteria = new Criteria <SocketMessage>()
                                   .AddCriterion(new EnsureSourceChannelCriterion())
                                   .AddCriterion(new EnsureFromUserCriterion(reaction.UserId))
                                   .AddCriterion(new EnsureIsIntegerCriterion())
                                   .AddCriterion(new EnsureRangeCriterion(pages));
                    var response = await Interactive.NextMessageAsync(Context, criteria, TimeSpan.FromSeconds(60));
                    var request  = int.Parse(response.Content);
                    page         = request;
                    await RenderAsync().ConfigureAwait(false);
                    _ = response.DeleteAsync().ConfigureAwait(false);
                    await msg.DeleteAsync();
                });
                return(false);
            }
            else if (emote.Equals(options.Info))
            {
                await Interactive.ReplyAndDeleteAsync(Context, options.InformationText, timeout : options.InfoTimeout);

                return(false);
            }
            _ = Message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);
            await RenderAsync().ConfigureAwait(false);

            return(false);
        }