Пример #1
0
 private async Task EditMessage(IUserMessage message, PaginatedMessage page)
 {
     await message.ModifyAsync(x =>
     {
         x.Content = page.CurrentPageContent;
     });
 }
Пример #2
0
        /// <summary>
        /// Sends a paginated message (with reaction buttons)
        /// </summary>
        /// <param name="channel">The channel this message should be sent to</param>
        /// <param name="paginated">A <see cref="PaginatedMessage">PaginatedMessage</see> containing the pages.</param>
        /// <exception cref="Net.HttpException">Thrown if the bot user cannot send a message or add reactions.</exception>
        /// <returns>The paginated message.</returns>
        public async Task <IUserMessage> SendPaginatedMessageAsync(IMessageChannel channel, PaginatedMessage paginated)
        {
            await WriteLog(Log.Info($"Sending message to {channel}"));

            var message = await channel.SendMessageAsync(paginated.CurrentPageContent);

            await message.AddReactionAsync(FIRST);

            await message.AddReactionAsync(BACK);

            await message.AddReactionAsync(NEXT);

            await message.AddReactionAsync(END);

            await message.AddReactionAsync(STOP);

            _messages.Add(message.Id, paginated);
            await WriteLog(Log.Debug("Listening to message with id {id}"));

            return(message);
        }
Пример #3
0
        /// <summary>
        /// Sends a paginated message (with reaction buttons)
        /// </summary>
        /// <param name="channel">The channel this message should be sent to</param>
        /// <param name="paginated">A <see cref="PaginatedMessage">PaginatedMessage</see> containing the pages.</param>
        /// <exception cref="Net.HttpException">Thrown if the bot user cannot send a message or add reactions.</exception>
        /// <returns>The paginated message.</returns>
        public async Task <IUserMessage> SendPaginatedMessageAsync(IMessageChannel channel, PaginatedMessage paginated)
        {
            await WriteLog(Log.Info($"Sending message to {channel}"));

            var message = await channel.SendMessageAsync("", embed : paginated.GetEmbed());

            await message.AddReactionAsync(new Emoji(FIRST));

            await message.AddReactionAsync(new Emoji(BACK));

            await message.AddReactionAsync(new Emoji(NEXT));

            await message.AddReactionAsync(new Emoji(END));

            await message.AddReactionAsync(new Emoji(STOP));

            _messages.Add(message.Id, paginated);
            await WriteLog(Log.Debug("Listening to message with id {id}"));

            return(message);
        }
Пример #4
0
        /// <summary>
        /// Sends a paginated message (with reaction buttons)
        /// </summary>
        /// <param name="channel">The channel this message should be sent to</param>
        /// <param name="paginated">A <see cref="PaginatedMessage">PaginatedMessage</see> containing the pages.</param>
        /// <exception cref="Net.HttpException">Thrown if the bot user cannot send a message or add reactions.</exception>
        /// <returns>The paginated message.</returns>
        public async Task <IUserMessage> SendPaginatedMessageAsync(IMessageChannel channel, PaginatedMessage paginated)
        {
            await WriteLog(Log.Info($"Sending message to {channel}"));

            var message = await channel.SendMessageAsync("", embed : paginated.GetEmbed());

            await message.AddReactionAsync(paginated.Options.EmoteFirst);

            await message.AddReactionAsync(paginated.Options.EmoteBack);

            await message.AddReactionAsync(paginated.Options.EmoteNext);

            await message.AddReactionAsync(paginated.Options.EmoteLast);

            await message.AddReactionAsync(paginated.Options.EmoteStop);

            _messages.Add(message.Id, paginated);
            await WriteLog(Log.Debug("Listening to message with id {id}"));

            if (paginated.Options.Timeout != TimeSpan.Zero)
            {
                var _ = Task.Delay(paginated.Options.Timeout).ContinueWith(async _t =>
                {
                    if (!_messages.ContainsKey(message.Id))
                    {
                        return;
                    }
                    if (paginated.Options.TimeoutAction == StopAction.DeleteMessage)
                    {
                        await message.DeleteAsync();
                    }
                    else if (paginated.Options.TimeoutAction == StopAction.ClearReactions)
                    {
                        await message.RemoveAllReactionsAsync();
                    }
                    _messages.Remove(message.Id);
                });
            }

            return(message);
        }