Skip to content

Commit c3dacb5

Browse files
fix: add title and footer field to embedless paginators
1 parent 5a26443 commit c3dacb5

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

modmail/utils/pagination.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __init__(
6666
prefix: str = "```",
6767
suffix: str = "```",
6868
max_size: int = 2000,
69+
title: str = None,
6970
linesep: str = "\n",
7071
only_users: Optional[List[Union[discord.Object, discord.abc.User]]] = None,
7172
only_roles: Optional[List[Union[discord.Object, discord.Role]]] = None,
@@ -91,6 +92,19 @@ def __init__(
9192

9293
# used if embed is None
9394
self.content = ""
95+
if embed is not None:
96+
if title:
97+
raise TypeError("Cannot set title if embed is None.")
98+
self.title = None
99+
else:
100+
self.title = title
101+
# need to set the max_size down a few to be able to set a "footer"
102+
# page indicator is "page xx of xx"
103+
self.max_size -= 15
104+
if self.title is not None:
105+
self.max_size -= len(title)
106+
if footer_text is not None:
107+
self.max_size -= len(footer_text) + 1
94108

95109
# temporary to support strings as contents. This will be changed when we added wrapping.
96110
if isinstance(contents, str):
@@ -157,6 +171,7 @@ async def paginate(
157171
prefix: str = "",
158172
suffix: str = "",
159173
max_size: int = 4000,
174+
title: str = None,
160175
linesep: str = "\n",
161176
only_users: Optional[List[Union[discord.Object, discord.abc.User]]] = None,
162177
only_roles: Optional[List[Union[discord.Object, discord.abc.Role]]] = None,
@@ -175,6 +190,7 @@ async def paginate(
175190
prefix=prefix,
176191
suffix=suffix,
177192
max_size=max_size,
193+
title=title,
178194
linesep=linesep,
179195
only_users=only_users,
180196
only_roles=only_roles,
@@ -186,10 +202,6 @@ async def paginate(
186202
channel = source_message.channel
187203

188204
paginator.update_states()
189-
if paginator.embed:
190-
paginator.embed.description = paginator.pages[paginator.index]
191-
else:
192-
paginator.content = paginator.pages[paginator.index]
193205
# if there's only one page, don't send the view
194206
if len(paginator.pages) < 2:
195207
if paginator.embed:
@@ -239,18 +251,18 @@ def update_states(self) -> None:
239251
if the paginator is on the last page, the jump last/move forward buttons will be disabled.
240252
"""
241253
# update the footer
254+
page_indicator = f"Page {self.index+1}/{len(self._pages)}"
255+
footer_text = (
256+
f"{self.footer_text} ({page_indicator})" if self.footer_text is not None else page_indicator
257+
)
242258
if self.embed is None:
243-
self.content = self._pages[self.index]
259+
self.content = (self.title or "") + "\n"
260+
self.content += self._pages[self.index]
261+
self.content += "\n" + footer_text
262+
244263
else:
245264
self.embed.description = self._pages[self.index]
246-
page_indicator = f"Page {self.index+1}/{len(self._pages)}"
247-
self.embed.set_footer(
248-
text=(
249-
f"{self.footer_text} ({page_indicator})"
250-
if self.footer_text is not None
251-
else page_indicator
252-
)
253-
)
265+
self.embed.set_footer(text=footer_text)
254266

255267
# determine if the jump buttons should be enabled
256268
more_than_two_pages = len(self._pages) > 2
@@ -287,6 +299,7 @@ async def send_page(self, interaction: Interaction) -> None:
287299
if self.embed:
288300
await interaction.message.edit(embed=self.embed, view=self)
289301
else:
302+
print(len(self.content))
290303
await interaction.message.edit(content=self.content, view=self)
291304

292305
@ui.button(label=JUMP_FIRST_LABEL, custom_id="pag_jump_first", style=ButtonStyle.primary)

0 commit comments

Comments
 (0)