/// <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); }
/// <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); }