public async Task DisplayAsync()
        {
            Embed embed = BuildEmbed();

            Rest.RestUserMessage message = await Context.Channel.SendMessageAsync(embed : embed).ConfigureAwait(false);

            Message = message;
            Interactive.AddReactionCallback(message, this);
            // Reactions take a while to add, don't wait for them
            _ = Task.Run(async() =>
            {
                await message.AddReactionAsync(Options.First);
                await message.AddReactionAsync(Options.Back);
                await message.AddReactionAsync(Options.Stop);
                await message.AddReactionAsync(Options.Next);
                await message.AddReactionAsync(Options.Last);
            });
            if (Timeout != null)
            {
                _ = Task.Delay(Timeout.Value).ContinueWith(_ =>
                {
                    Interactive.RemoveReactionCallback(message);
                    Message.DeleteAsync();
                });
            }
        }
Ejemplo n.º 2
0
        public async Task <IUserMessage> ReplyAndDeleteAsync(SocketCommandContext context,
                                                             string content, bool isTTS = false,
                                                             Embed embed            = null,
                                                             TimeSpan?timeout       = null,
                                                             RequestOptions options = null)
        {
            timeout = timeout ?? _defaultTimeout;
            Rest.RestUserMessage message = await context.Channel.SendMessageAsync(content, isTTS, embed, options).ConfigureAwait(false);

            _ = Task.Delay(timeout.Value)
                .ContinueWith(_ => message.DeleteAsync().ConfigureAwait(false))
                .ConfigureAwait(false);
            return(message);
        }
Ejemplo n.º 3
0
        public async Task DisplayAsync()
        {
            Embed embed = BuildEmbed();

            Rest.RestUserMessage message = await Context.Channel.SendMessageAsync(_pager.Content, embed : embed).ConfigureAwait(false);

            Message = message;
            Interactive.AddReactionCallback(message, this);
            // Reactions take a while to add, don't wait for them
            _ = Task.Run(async() =>
            {
                await message.AddReactionAsync(options.First);
                await message.AddReactionAsync(options.Back);
                await message.AddReactionAsync(options.Next);
                await message.AddReactionAsync(options.Last);

                bool manageMessages = (Context.Channel is IGuildChannel guildChannel) &&
                                      (Context.User as IGuildUser).GetPermissions(guildChannel).ManageMessages;

                if (options.JumpDisplayOptions == JumpDisplayOptions.Always ||
                    (options.JumpDisplayOptions == JumpDisplayOptions.WithManageMessages && manageMessages))
                {
                    await message.AddReactionAsync(options.Jump);
                }

                await message.AddReactionAsync(options.Stop);

                if (options.DisplayInformationIcon)
                {
                    await message.AddReactionAsync(options.Info);
                }
            });
            // TODO: (Next major version) timeouts need to be handled at the service-level!
            if (Timeout.HasValue && Timeout.Value != null)
            {
                _ = Task.Delay(Timeout.Value).ContinueWith(_ =>
                {
                    Interactive.RemoveReactionCallback(message);
                    _ = Message.DeleteAsync();
                });
            }
        }