diff --git a/nomen/notifications.py b/nomen/notifications.py index 4057ba7..7c5b69f 100644 --- a/nomen/notifications.py +++ b/nomen/notifications.py @@ -74,30 +74,45 @@ async def handle_notification(db_updates, ctx, message, keyword, user_id, use_em footer = f" | [Show]({message.jump_url}) | <#{ctx.channel.id}>" content = message.content or "(*Keyword in embed*)" + if use_embed: + paginator = Paginator(prefix="", suffix="", max_size=4000) + else: + paginator = Paginator(prefix="", suffix="") + paginator.add_line(header) + paginator.add_line() + + content = indent(content, "> ", lambda line: True) + + for line in content.strip().split("\n"): + if len(line) < 1990: + paginator.add_line(line) + else: + paginator.add_line(line[:1975] + " (... Line too long)") + + paginator.add_line() + paginator.add_line(footer) + if use_embed: log.debug("Sending embed") - embed = Embed(description=content + "\n\n" + footer) + embeds = [] + embed = Embed(description=paginator.pages[0]) embed.set_author( name=f"{message.author.display_name} ({message.author})", icon_url=message.author.display_avatar, ) + embeds.append(embed) + + for page in paginator.pages[1:]: + embeds.append(description=page) + + embeds.extend(message.embeds) try: - await member.send(header, embeds=[embed] + message.embeds[:9]) + await member.send(header, embeds=embeds[:10]) except Forbidden: 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() - for line in indent(content, "> ", lambda line: True).strip().split("\n"): - if len(line) < 1990: - paginator.add_line(line) - else: - paginator.add_line(line[:1975] + " (... Line too long)") - paginator.add_line() - paginator.add_line(footer) try: for page in paginator.pages[:-1]: await member.send(page) diff --git a/nomen/utils.py b/nomen/utils.py index c30f736..4dae10a 100644 --- a/nomen/utils.py +++ b/nomen/utils.py @@ -1,55 +1,15 @@ import logging from asyncio import TimeoutError -from itertools import chain import re2 as re from disnake.ext.commands import BadArgument log = logging.getLogger("nomen.utils") -ALPHABET = list("abcdefghijklmnopqrstuvwxyz ") +ALPHABET = "abcdefghijklmnopqrstuvwxyz" +SYMBOLS = "!@#$%^&*()[]{}-_=+`~;:'\"/\\" -COMMON_WORDS = [ - # common words - "of", - "in", - "is", - "to", - "it", - "as", - "on", - "by", - "or", - "be", - "an", - "at", - "if", - "up", - "so", - "do", - "th", - "no", - "de", - "the", - "and", - "was", - "for", - "that", - "are", - "with", - "from", - "this", - "not", - "also", - "has", - "were", - "which", - "have", - "people", - "one", - "can", - "help", - # pronouns +PRONOUNS = [ "you", "your", "yours", @@ -67,15 +27,92 @@ COMMON_WORDS = [ "theirs", "themself", "themselves", - "a" * 100, + "we", + "me", + "any", + "us", ] -TESTS = list( - chain( - ALPHABET, # single letters - COMMON_WORDS, - ) -) +NUMBERS = [ + *"0123456789", + "10", + "zero", + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine", + "ten", +] + +COMMON_WORDS = [ + "about", + "after", + "also", + "an", + "and", + "are", + "as", + "at", + "be", + "by", + "can", + "do", + "for", + "from", + "has", + "have", + "help", + "if", + "in", + "into", + "is", + "it", + "no", + "not", + "of", + "on", + "or", + "over", + "people", + "so", + "that", + "the", + "this", + "to", + "up", + "was", + "were", + "which", + "with", +] + +COMMON_FRAGMENTS = [ + "de", + "th", + "un", +] + +WILDCARDS = [ + "a" * 100, # letters + "0" * 100, # numbers + " " * 100, # whitespace +] + +TESTS = [ + *ALPHABET, + *NUMBERS, + *PRONOUNS, + *COMMON_WORDS, + *COMMON_FRAGMENTS, + *WILDCARDS, + " ", # single space + "\n", # newline +] regex_cache = {}