Compare commits

..

3 commits

3 changed files with 26 additions and 5 deletions

View file

@ -5,6 +5,7 @@ from typing import Union
from disnake import Embed, Member, Thread, User from disnake import Embed, Member, Thread, User
from disnake.abc import GuildChannel 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, group, guild_only
from .utils import can_view, confirm, test_keyword from .utils import can_view, confirm, test_keyword
@ -64,10 +65,16 @@ async def handle_notification(db_updates, ctx, message, keyword, user_id, use_em
icon_url=message.author.display_avatar, icon_url=message.author.display_avatar,
) )
try:
await member.send(header, embed=embed) await member.send(header, embed=embed)
except Forbidden:
log.warning("Cannot send messages to this user")
else: else:
log.debug("Sending plain message") log.debug("Sending plain message")
try:
await member.send("\n".join((header, indent(message.content, "> ", lambda line: True).strip(), footer))) await member.send("\n".join((header, indent(message.content, "> ", lambda line: True).strip(), footer)))
except Forbidden:
log.warning("Cannot send messages to this user")
log.debug("Sent") log.debug("Sent")

View file

@ -148,6 +148,10 @@ You may want to `{ctx.clean_prefix}nomen export` first"""
You will not trigger anyone else's notifications, and you will not receive any notifications You will not trigger anyone else's notifications, and you will not receive any notifications
""" """
if await ctx.bot.get_setting(ctx.author.id, "disabled"):
await ctx.send("You are already opted-out")
return
log.debug(f"Opting-out: {ctx.author} ({ctx.author.id})") log.debug(f"Opting-out: {ctx.author} ({ctx.author.id})")
await ctx.send( await ctx.send(
@ -163,6 +167,10 @@ You may want to `{ctx.clean_prefix}nomen export` first"""
Opt-in to Nomen processing your messages Opt-in to Nomen processing your messages
""" """
if not await ctx.bot.get_setting(ctx.author.id, "disabled"):
await ctx.send("You are already opted-in")
return
log.debug(f"Opting-in: {ctx.author} ({ctx.author.id})") log.debug(f"Opting-in: {ctx.author} ({ctx.author.id})")
await ctx.send( await ctx.send(

View file

@ -4,6 +4,7 @@ from itertools import chain
import re2 as re import re2 as re
from disnake import ChannelType from disnake import ChannelType
from disnake.ext.commands import BadArgument
log = logging.getLogger("nomen.utils") log = logging.getLogger("nomen.utils")
@ -87,9 +88,14 @@ def compile_keyword(keyword, regex):
if not regex: if not regex:
keyword = re.escape(keyword) keyword = re.escape(keyword)
try:
reg = re.compile(rf"(?i)\b{keyword}\b") reg = re.compile(rf"(?i)\b{keyword}\b")
regex_cache[(keyword, regex)] = reg regex_cache[(keyword, regex)] = reg
return reg return reg
except re._re2.Error:
raise BadArgument(
"Invalid regex. Nomen only supports regexes that [re2](<https://github.com/google/re2>) can parse."
)
def contains(string, keyword, regex): def contains(string, keyword, regex):