Compare commits
2 commits
414f5df5ae
...
9cd672e382
Author | SHA1 | Date | |
---|---|---|---|
9cd672e382 | |||
a0afb916e7 |
2 changed files with 114 additions and 62 deletions
|
@ -75,29 +75,44 @@ async def handle_notification(db_updates, ctx, message, keyword, user_id, use_em
|
|||
content = message.content or "(*Keyword in embed*)"
|
||||
|
||||
if use_embed:
|
||||
log.debug("Sending embed")
|
||||
embed = Embed(description=content + "\n\n" + footer)
|
||||
embed.set_author(
|
||||
name=f"{message.author.display_name} ({message.author})",
|
||||
icon_url=message.author.display_avatar,
|
||||
)
|
||||
|
||||
try:
|
||||
await member.send(header, embeds=[embed] + message.embeds[:9])
|
||||
except Forbidden:
|
||||
log.warning("Cannot send messages to this user")
|
||||
paginator = Paginator(prefix="", suffix="", max_size=4000)
|
||||
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"):
|
||||
|
||||
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.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])
|
||||
except Forbidden:
|
||||
log.warning("Cannot send messages to this user")
|
||||
else:
|
||||
log.debug("Sending plain message")
|
||||
try:
|
||||
for page in paginator.pages[:-1]:
|
||||
await member.send(page)
|
||||
|
|
137
nomen/utils.py
137
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 = {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue