check contents of embeds

This commit is contained in:
Infinidoge 2025-01-01 23:19:49 -05:00
parent 0187890dc1
commit 5642033442
Signed by: Infinidoge
SSH key fingerprint: SHA256:GT2StvPQMMfFHyiiFJymQxfTG/z6EWLJ6NWItf5K5sA

View file

@ -56,17 +56,18 @@ async def handle_notification(db_updates, ctx, message, keyword, user_id, use_em
header = f"🔔 `{message.author.display_name}` mentioned `{keyword}` on `{ctx.guild}`:" header = f"🔔 `{message.author.display_name}` mentioned `{keyword}` on `{ctx.guild}`:"
footer = f"<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}>"
content = message.content or "(*Keyword in embed*)"
if use_embed: if use_embed:
log.debug("Sending embed") log.debug("Sending embed")
embed = Embed(description=message.content + "\n\n" + footer) embed = Embed(description=content + "\n\n" + footer)
embed.set_author( embed.set_author(
name=f"{message.author.display_name} ({message.author})", name=f"{message.author.display_name} ({message.author})",
icon_url=message.author.display_avatar, icon_url=message.author.display_avatar,
) )
try: try:
await member.send(header, embed=embed) await member.send(header, embeds=[embed] + message.embeds[:9])
except Forbidden: except Forbidden:
log.warning("Cannot send messages to this user") log.warning("Cannot send messages to this user")
else: else:
@ -74,7 +75,7 @@ async def handle_notification(db_updates, ctx, message, keyword, user_id, use_em
paginator = Paginator(prefix="", suffix="") paginator = Paginator(prefix="", suffix="")
paginator.add_line(header) paginator.add_line(header)
paginator.add_line() paginator.add_line()
for line in indent(message.content, "> ", lambda line: True).strip().split("\n"): for line in indent(content, "> ", lambda line: True).strip().split("\n"):
if len(line) < 1990: if len(line) < 1990:
paginator.add_line(line) paginator.add_line(line)
else: else:
@ -82,8 +83,9 @@ async def handle_notification(db_updates, ctx, message, keyword, user_id, use_em
paginator.add_line() paginator.add_line()
paginator.add_line(footer) paginator.add_line(footer)
try: try:
for page in paginator.pages: for page in paginator.pages[:-1]:
await member.send(page) await member.send(page)
await member.send(paginator.pages[-1], embeds=message.embeds[:10])
except Forbidden: except Forbidden:
log.warning("Cannot send messages to this user") log.warning("Cannot send messages to this user")
@ -97,12 +99,21 @@ async def handle_triggers(ctx, message):
log.debug(f"Handling triggers for '{message.content}' from {ctx.author}") log.debug(f"Handling triggers for '{message.content}' from {ctx.author}")
contents = [message.content]
for embed in message.embeds:
contents.append(embed.title or "")
contents.append(embed.description or "")
for field in embed.fields:
contents.append(field.name or "")
contents.append(field.value or "")
contents.append(embed.footer.text or "")
params = { params = {
"author": ctx.author.id, "author": ctx.author.id,
"channel": ctx.channel.id, "channel": ctx.channel.id,
"category": ctx.channel.category_id, "category": ctx.channel.category_id,
"guild": ctx.guild.id, "guild": ctx.guild.id,
"content": message.content, "content": " ".join(contents),
"is_bot": ctx.author.bot, "is_bot": ctx.author.bot,
"parent": 0, "parent": 0,
} }