Compare commits

..

No commits in common. "9cd672e38232b2edd484a6e74cf902f0173fbdfd" and "414f5df5ae1c91cde07bfc3e16460ea06e25a553" have entirely different histories.

2 changed files with 62 additions and 114 deletions

View file

@ -74,45 +74,30 @@ async def handle_notification(db_updates, ctx, message, keyword, user_id, use_em
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:
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")
embeds = []
embed = Embed(description=paginator.pages[0])
embed = Embed(description=content + "\n\n" + footer)
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=embeds[:10])
await member.send(header, embeds=[embed] + message.embeds[:9])
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)

View file

@ -1,15 +1,55 @@
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 = "abcdefghijklmnopqrstuvwxyz"
SYMBOLS = "!@#$%^&*()[]{}-_=+`~;:'\"/\\"
ALPHABET = list("abcdefghijklmnopqrstuvwxyz ")
PRONOUNS = [
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
"you",
"your",
"yours",
@ -27,92 +67,15 @@ PRONOUNS = [
"theirs",
"themself",
"themselves",
"we",
"me",
"any",
"us",
"a" * 100,
]
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
]
TESTS = list(
chain(
ALPHABET, # single letters
COMMON_WORDS,
)
)
regex_cache = {}