Ejemplo n.º 1
0
        /// <summary>
        /// Sends the paginated message with the provided reaction list.
        /// </summary>
        /// <param name="reactionList">
        /// The reactions to add.
        /// </param>
        /// <param name="oldMessage">
        /// An old message to reuse.
        /// </param>
        /// <returns>
        /// A task representing the asynchronous operation.
        /// </returns>
        internal async Task DisplayAsync(ReactionList reactionList, IUserMessage oldMessage)
        {
            var embed = BuildEmbed();

            if (oldMessage == null)
            {
                Message = await Context.Channel.SendMessageAsync(_pager.Text, embed : embed).ConfigureAwait(false);
            }
            else
            {
                // Remove the old message callback
                Interactive.RemoveReactionCallback(oldMessage);
                if (oldMessage.Reactions.Count > 0)
                {
                    // There's still reactions (that means the bot doesn't have ManageMessages perms)
                    await oldMessage.DeleteAsync();

                    Message = await Context.Channel.SendMessageAsync(_pager.Text, embed : embed).ConfigureAwait(false);
                }
                else
                {
                    await oldMessage.ModifyAsync(x =>
                    {
                        x.Content = _pager.Text;
                        x.Embed   = embed;
                    }).ConfigureAwait(false);

                    Message = oldMessage;
                }
            }
            if (_pages <= 1)
            {
                return;
            }
            Interactive.AddReactionCallback(Message, this);

            // reactionList take a while to add, don't wait for them
            _ = Task.Run(async() =>
            {
                if (reactionList.First)
                {
                    await Message.AddReactionAsync(_pager.Options.First).ConfigureAwait(false);
                }
                if (reactionList.Backward)
                {
                    await Message.AddReactionAsync(_pager.Options.Back).ConfigureAwait(false);
                }
                if (reactionList.Forward)
                {
                    await Message.AddReactionAsync(_pager.Options.Next).ConfigureAwait(false);
                }
                if (reactionList.Last)
                {
                    await Message.AddReactionAsync(_pager.Options.Last).ConfigureAwait(false);
                }
                if (reactionList.Jump)
                {
                    await Message.AddReactionAsync(_pager.Options.Jump).ConfigureAwait(false);
                }
                if (reactionList.Stop)
                {
                    await Message.AddReactionAsync(_pager.Options.Stop).ConfigureAwait(false);
                }
                if (reactionList.Info)
                {
                    await Message.AddReactionAsync(_pager.Options.Info).ConfigureAwait(false);
                }
                if (Timeout.HasValue)
                {
                    await Task.Delay(Timeout.Value).ConfigureAwait(false);
                    await OnStopAsync(Message, _pager.Options.ActionOnTimeout).ConfigureAwait(false);
                }
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends a paginated message.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="pager">
        /// The pager.
        /// </param>
        /// <param name="reactions">
        /// The reactions.
        /// </param>
        /// <param name="criterion">
        /// The criterion.
        /// </param>
        /// <param name="oldMessage">
        /// An old message to reuse.
        /// </param>
        /// <returns>
        /// A task representing the asynchronous operation. The result contains the message.
        /// </returns>
        public async Task <IUserMessage> SendPaginatedMessageAsync(SocketCommandContext context, PaginatedMessage pager, ReactionList reactions, ICriterion <SocketReaction> criterion = null,
                                                                   IUserMessage oldMessage = null)
        {
            var callback = new PaginatedMessageCallback(this, context, pager, criterion);
            await callback.DisplayAsync(reactions, oldMessage).ConfigureAwait(false);

            return(callback.Message);
        }