/// <summary> /// The display async. /// </summary> /// <param name="reactionList"> /// The reactions. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task DisplayAsync(ReactionList reactionList) { var embed = BuildEmbed(); var message = await Context.Channel.SendMessageAsync(pager.Content, embed : embed).ConfigureAwait(false); Message = message; Interactive.AddReactionCallback(message, this); // reactionList take a while to add, don't wait for them _ = Task.Run(async() => { if (reactionList.First) { await message.AddReactionAsync(options.First); } if (reactionList.Backward) { await message.AddReactionAsync(options.Back); } if (reactionList.Forward) { await message.AddReactionAsync(options.Next); } if (reactionList.Last) { await message.AddReactionAsync(options.Last); } var manageMessages = Context.Channel is IGuildChannel guildChannel && (Context.User as IGuildUser).GetPermissions(guildChannel).ManageMessages; if (reactionList.Jump) { if (options.JumpDisplayOptions == JumpDisplayOptions.Always || (options.JumpDisplayOptions == JumpDisplayOptions.WithManageMessages && manageMessages)) { await message.AddReactionAsync(options.Jump); } } if (reactionList.Trash) { await message.AddReactionAsync(options.Stop); } if (reactionList.Info) { if (options.DisplayInformationIcon) { await message.AddReactionAsync(options.Info); } } }); if (Timeout.HasValue) { DisplayTimeout(message, Message); } }
/// <summary> /// Sends a paginated message in the current channel /// </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> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <IUserMessage> SendPaginatedMessageAsync(SocketCommandContext context, PaginatedMessage pager, ReactionList reactions, ICriterion <SocketReaction> criterion = null) { var callback = new PaginatedMessageCallback(this, context, pager, criterion); await callback.DisplayAsync(reactions).ConfigureAwait(false); return(callback.Message); }
/// <summary> /// Sends or edits the message, the reactions. /// </summary> /// <param name="reactionList"> /// The reactions. /// </param> /// <param name="oldMessage"> /// The old message to edit. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task DisplayAsync(ReactionList reactionList, IUserMessage oldMessage) { var embed = BuildEmbed(); if (oldMessage == null) { Message = await Context.Channel.SendMessageAsync(pager.Content, embed : embed).ConfigureAwait(false); } else { // TODO: A better way to update the reactions //await OnStopAsync(oldMessage, ActionOnTimeout.DeleteReactions); Interactive.RemoveReactionCallback(oldMessage); await oldMessage.ModifyAsync(x => { x.Content = null; x.Embed = embed; }).ConfigureAwait(false); Message = (IUserMessage)await Context.Channel.GetMessageAsync(oldMessage.Id).ConfigureAwait(false); } //this.Message = Message; 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(Options.First); } if (reactionList.Backward) { await Message.AddReactionAsync(Options.Back); } if (reactionList.Forward) { await Message.AddReactionAsync(Options.Next); } if (reactionList.Last) { await Message.AddReactionAsync(Options.Last); } bool manageMessages = Context.Channel is IGuildChannel guildChannel && (Context.User as IGuildUser).GetPermissions(guildChannel).ManageMessages; if (reactionList.Jump) { if (Options.JumpDisplayOptions == JumpDisplayOptions.Always || (Options.JumpDisplayOptions == JumpDisplayOptions.WithManageMessages && manageMessages)) { await Message.AddReactionAsync(Options.Jump); } } if (reactionList.Stop) { await Message.AddReactionAsync(Options.Stop); } if (reactionList.Info) { await Message.AddReactionAsync(Options.Info); } }); if (Timeout.HasValue) { _ = Task.Delay(Timeout.Value) .ContinueWith(_ => OnStopAsync(Message, Options.ActionOnTimeout).ConfigureAwait(false)) .ConfigureAwait(false); } }
public async Task DisplayAsync(ReactionList reactionList) { var embed = BuildEmbed(); RestUserMessage message; if (embed is string) { message = await Context.Channel.SendMessageAsync(embed as string).ConfigureAwait(false); } else if (embed is Embed) { message = await Context.Channel.SendMessageAsync(_pager.Content, embed : embed as Embed).ConfigureAwait(false); } else { return; } Message = message; Interactive.AddReactionCallback(message, this); _ = Task.Run(async() => { if (reactionList.First) { await message.AddReactionAsync(Options.First); } if (reactionList.Backward) { await message.AddReactionAsync(Options.Back); } if (reactionList.Forward) { await message.AddReactionAsync(Options.Next); } if (reactionList.Last) { await message.AddReactionAsync(Options.Last); } var manageMessages = Context.Channel is IGuildChannel guildChannel && (Context.User as IGuildUser).GetPermissions(guildChannel).ManageMessages; if (reactionList.Jump && Options.JumpDisplayOptions == JumpDisplayOptions.Always || Options.JumpDisplayOptions == JumpDisplayOptions.WithManageMessages && manageMessages) { await message.AddReactionAsync(Options.Jump); } if (reactionList.Trash) { await message.AddReactionAsync(Options.Stop); } if (reactionList.Info && Options.DisplayInformationIcon) { await message.AddReactionAsync(Options.Info); } }); if (Timeout.HasValue) { DisplayTimeout(message, Message); } }