diff --git a/nomen/notifications.py b/nomen/notifications.py index da9c406..f5818a0 100644 --- a/nomen/notifications.py +++ b/nomen/notifications.py @@ -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 | [Show]({message.jump_url}) | <#{ctx.channel.id}>" + header = f"🔔 `{message.author.display_name}` mentioned `{keyword}` on `{ctx.guild}`:" + footer = f"\n | [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=?",