paginate long non-embed notifications

This commit is contained in:
Infinidoge 2025-01-01 17:53:26 -05:00
parent 7f70c2afc8
commit 522a2ee204
Signed by: Infinidoge
SSH key fingerprint: SHA256:GT2StvPQMMfFHyiiFJymQxfTG/z6EWLJ6NWItf5K5sA

View file

@ -6,7 +6,7 @@ from typing import Union
from disnake import Embed, Member, Thread, User
from disnake.abc import GuildChannel
from disnake.errors import Forbidden
from disnake.ext.commands import Cog, group, guild_only
from disnake.ext.commands import Cog, Paginator, group, guild_only
from .utils import can_view, confirm, test_keyword
@ -55,11 +55,11 @@ async def handle_notification(db_updates, ctx, message, keyword, user_id, use_em
db_updates.append((ctx.guild.id, keyword, user_id))
header = f"🔔 `{message.author.display_name}` mentioned `{keyword}` on `{ctx.guild}`:"
footer = f"\n<t:{int(message.created_at.timestamp())}:R> | [Show]({message.jump_url}) | <#{ctx.channel.id}>"
footer = f"<t:{int(message.created_at.timestamp())}:R> | [Show]({message.jump_url}) | <#{ctx.channel.id}>"
if use_embed:
log.debug("Sending embed")
embed = Embed(description=message.content + "\n" + footer)
embed = Embed(description=message.content + "\n\n" + footer)
embed.set_author(
name=f"{message.author.display_name} ({message.author})",
icon_url=message.author.display_avatar,
@ -71,8 +71,16 @@ async def handle_notification(db_updates, ctx, message, keyword, user_id, use_em
log.warning("Cannot send messages to this user")
else:
log.debug("Sending plain message")
paginator = Paginator(prefix="", suffix="")
paginator.add_line(header)
paginator.add_line(empty=True)
for line in indent(message.content, "> ", lambda line: True).strip().split("\n"):
paginator.add_line(line)
paginator.add_line(empty=True)
paginator.add_file(footer)
try:
await member.send("\n".join((header, indent(message.content, "> ", lambda line: True).strip(), footer)))
for page in paginator.pages:
await member.send(page)
except Forbidden:
log.warning("Cannot send messages to this user")