async Task PaginateAsync(IPaginationRequest p, DiscordEmoji emoji) { var emojis = await p.GetEmojisAsync(); var msg = await p.GetMessageAsync(); if (emoji == emojis.SkipLeft) { await p.SkipLeftAsync(); } else if (emoji == emojis.Left) { await p.PreviousPageAsync(); } else if (emoji == emojis.Right) { await p.NextPageAsync(); } else if (emoji == emojis.SkipRight) { await p.SkipRightAsync(); } else if (emoji == emojis.Stop) { var tcs = await p.GetTaskCompletionSourceAsync(); tcs.TrySetResult(true); return; } var page = await p.GetPageAsync(); await msg.ModifyAsync(page.Content, page.Embed); }
async Task ResetReactionsAsync(IPaginationRequest p) { var msg = await p.GetMessageAsync(); var emojis = await p.GetEmojisAsync(); await msg.DeleteAllReactionsAsync("Pagination"); if (emojis.SkipLeft != null) { await msg.CreateReactionAsync(emojis.SkipLeft); } if (emojis.Left != null) { await msg.CreateReactionAsync(emojis.Left); } if (emojis.Right != null) { await msg.CreateReactionAsync(emojis.Right); } if (emojis.SkipRight != null) { await msg.CreateReactionAsync(emojis.SkipRight); } if (emojis.Stop != null) { await msg.CreateReactionAsync(emojis.Stop); } }
async Task ResetReactionsAsync(IPaginationRequest p) { var msg = await p.GetMessageAsync(); var emojis = await p.GetEmojisAsync(); // Test permissions to avoid a 403: // https://totally-not.a-sketchy.site/3pXpRLK.png // Yes, this is an issue // No, we should not require people to guarantee MANAGE_MESSAGES // Need to check following: // - In guild? // - If not, only clear if own message // - If yes, check if have permission // - If all above fail (DM && other user's message || guild && no permission), skip this var chn = msg.Channel; var gld = chn?.Guild; var mbr = gld?.CurrentMember; if (gld == null /* == is DM */ && msg.Author == this._client.CurrentUser /* == is own message */ || mbr != null /* == is guild and cache is valid */ && (chn.PermissionsFor(mbr) & Permissions.ManageChannels) != 0) /* == has permissions */ { await msg.DeleteAllReactionsAsync("Pagination"); } // ENDOF: 403 fix if (emojis.SkipLeft != null) { await msg.CreateReactionAsync(emojis.SkipLeft); } if (emojis.Left != null) { await msg.CreateReactionAsync(emojis.Left); } if (emojis.Right != null) { await msg.CreateReactionAsync(emojis.Right); } if (emojis.SkipRight != null) { await msg.CreateReactionAsync(emojis.SkipRight); } if (emojis.Stop != null) { await msg.CreateReactionAsync(emojis.Stop); } }
async Task PaginateAsync(IPaginationRequest p, DiscordEmoji emoji) { var emojis = await p.GetEmojisAsync().ConfigureAwait(false); var msg = await p.GetMessageAsync().ConfigureAwait(false); if (emoji == emojis.SkipLeft) { await p.SkipLeftAsync().ConfigureAwait(false); } else if (emoji == emojis.Left) { await p.PreviousPageAsync().ConfigureAwait(false); } else if (emoji == emojis.Right) { await p.NextPageAsync().ConfigureAwait(false); } else if (emoji == emojis.SkipRight) { await p.SkipRightAsync().ConfigureAwait(false); } else if (emoji == emojis.Stop) { var tcs = await p.GetTaskCompletionSourceAsync().ConfigureAwait(false); tcs.TrySetResult(true); return; } var page = await p.GetPageAsync().ConfigureAwait(false); var builder = new DiscordMessageBuilder() .WithContent(page.Content) .WithEmbed(page.Embed); await builder.ModifyAsync(msg).ConfigureAwait(false); }