Skip to content

Commit 2bc5fc4

Browse files
authored
Merge pull request #348 from Joshi234/add-custom-buttons-to-pagination
Add custom buttons & ability to remove buttons to pagination
2 parents b883dea + b1cbf70 commit 2bc5fc4

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

Remora.Discord.Pagination/Interactions/PaginationInteractions.cs

+5
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ public async Task<Result> HelpAsync()
175175
{
176176
return Result.FromSuccess();
177177
}
178+
if (lease.Data.Appearance.HelpEmbed == null)
179+
{
180+
return new InvalidOperationError("Help embed is not available.");
181+
}
182+
178183
return (Result)await _feedback.SendContextualEmbedAsync
179184
(
180185
lease.Data.Appearance.HelpEmbed,

Remora.Discord.Pagination/PaginatedAppearanceOptions.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ public sealed record PaginatedAppearanceOptions
3737
ButtonComponent Previous,
3838
ButtonComponent Next,
3939
ButtonComponent Last,
40-
ButtonComponent Close,
41-
ButtonComponent Help,
42-
Embed HelpEmbed,
43-
string FooterFormat = "Page {0}/{1}"
40+
ButtonComponent? Close,
41+
ButtonComponent? Help,
42+
Embed? HelpEmbed,
43+
string FooterFormat = "Page {0}/{1}",
44+
ButtonComponent[]? CustomButtons = null
4445
)
4546
{
4647
/// <summary>
@@ -94,7 +95,7 @@ public sealed record PaginatedAppearanceOptions
9495
/// <summary>
9596
/// Gets the appearance options' configured buttons as an array.
9697
/// </summary>
97-
public IReadOnlyList<ButtonComponent> Buttons { get; } = new[]
98+
public IReadOnlyList<ButtonComponent?> Buttons { get; } = new[]
9899
{
99100
First,
100101
Previous,

Remora.Discord.Pagination/PaginatedMessageData.cs

+14-5
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ public Embed GetCurrentPage()
156156
/// <returns>The buttons.</returns>
157157
public IReadOnlyList<IMessageComponent> GetCurrentComponents()
158158
{
159+
List<ButtonComponent> customComponents = new List<ButtonComponent>();
160+
if (this.Appearance.Help != null)
161+
{
162+
customComponents.Add(this.Appearance.Help with { CustomID = CustomIDHelpers.CreateButtonID("help") });
163+
}
164+
if (this.Appearance.Close != null)
165+
{
166+
customComponents.Add(this.Appearance.Close with { CustomID = CustomIDHelpers.CreateButtonID("close") });
167+
}
168+
if (this.Appearance.CustomButtons != null)
169+
{
170+
customComponents.AddRange(this.Appearance.CustomButtons);
171+
}
159172
return new[]
160173
{
161174
new ActionRowComponent
@@ -186,11 +199,7 @@ this.Appearance.Last with
186199
),
187200
new ActionRowComponent
188201
(
189-
new[]
190-
{
191-
this.Appearance.Close with { CustomID = CustomIDHelpers.CreateButtonID("close") },
192-
this.Appearance.Help with { CustomID = CustomIDHelpers.CreateButtonID("help") }
193-
}
202+
customComponents
194203
)
195204
};
196205
}

0 commit comments

Comments
 (0)