From 522a2ee2047440a7a203649992d4925ff4af088a Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Wed, 1 Jan 2025 17:53:26 -0500 Subject: [PATCH] paginate long non-embed notifications --- nomen/notifications.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/nomen/notifications.py b/nomen/notifications.py index 9b895d7..dcb5209 100644 --- a/nomen/notifications.py +++ b/nomen/notifications.py @@ -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 | [Show]({message.jump_url}) | <#{ctx.channel.id}>" + footer = f" | [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")