paginate long non-embed notifications
This commit is contained in:
parent
7f70c2afc8
commit
522a2ee204
1 changed files with 12 additions and 4 deletions
|
@ -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")
|
||||
|
||||
|
|
Loading…
Reference in a new issue