implement plaintext notifications
This commit is contained in:
parent
ec54e31b5c
commit
0df744c946
1 changed files with 14 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
from asyncio import TaskGroup
|
||||
from textwrap import indent
|
||||
|
||||
from disnake import Embed
|
||||
from disnake.ext.commands import Cog, group, guild_only
|
||||
|
@ -10,7 +11,7 @@ log = logging.getLogger("nomen.notifications")
|
|||
log.setLevel(logging.INFO)
|
||||
|
||||
|
||||
async def handle_notification(db_updates, ctx, message, keyword, user_id):
|
||||
async def handle_notification(db_updates, ctx, message, keyword, user_id, use_embed):
|
||||
"""
|
||||
Async task to dispatch a notification
|
||||
"""
|
||||
|
@ -26,17 +27,19 @@ async def handle_notification(db_updates, ctx, message, keyword, user_id):
|
|||
log.debug(f"- - Notifying {user_id}")
|
||||
db_updates.append((ctx.guild.id, keyword, user_id))
|
||||
|
||||
footer = f"\n\n<t:{int(message.created_at.timestamp())}:R> | [Show]({message.jump_url}) | <#{ctx.channel.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}>"
|
||||
|
||||
embed = Embed(
|
||||
description=message.content + footer,
|
||||
)
|
||||
embed.set_author(name=message.author, icon_url=message.author.display_avatar)
|
||||
if use_embed:
|
||||
embed = Embed(description=message.content + "\n" + footer)
|
||||
embed.set_author(
|
||||
name=f"{message.author.display_name} ({message.author})",
|
||||
icon_url=message.author.display_avatar,
|
||||
)
|
||||
|
||||
await member.send(
|
||||
f":bell: `{message.author}` mentioned `{keyword}` on `{ctx.guild}`:",
|
||||
embed=embed,
|
||||
)
|
||||
await member.send(header, embed=embed)
|
||||
else:
|
||||
await member.send("\n".join((header, indent(message.content, "> ", lambda line: True).strip(), footer)))
|
||||
|
||||
|
||||
async def handle_triggers(ctx, message):
|
||||
|
@ -88,7 +91,7 @@ async def handle_triggers(ctx, message):
|
|||
async for keyword, user_id, use_embed in cur:
|
||||
log.debug(f"- Creating notification task: '{keyword}' for {user_id}")
|
||||
|
||||
tg.create_task(handle_notification(db_updates, ctx, message, keyword, user_id))
|
||||
tg.create_task(handle_notification(db_updates, ctx, message, keyword, user_id, use_embed))
|
||||
|
||||
await ctx.bot.db.executemany(
|
||||
"UPDATE keywords SET count = count + 1 WHERE guild_id=? AND keyword=? AND user_id=?",
|
||||
|
|
Loading…
Reference in a new issue