Just a few tweaks

This commit is contained in:
Frisk 2021-05-09 23:01:23 +02:00
parent ceefcfb0a1
commit 45030b6731
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
4 changed files with 7 additions and 3 deletions

View file

@ -42,7 +42,7 @@ def clean_link(link: str) -> str:
def sanitize_to_markdown(text: str) -> str: def sanitize_to_markdown(text: str) -> str:
"""Sanitizes given text to escape markdown formatting. It is used in values that will be visible on Discord in messages""" """Sanitizes given text to escape markdown formatting. It is used in values that will be visible on Discord in messages"""
return re.sub(r"([`_*~:<>{}@|\\])", "\\\\\\1", text, 0).replace('//', "/\\/").replace('](', "]\\(") return re.sub(r"([`_*~:<>{}@|\\])", "\\\\\\1", text).replace('//', "/\\/").replace('](', "]\\(")
def sanitize_to_url(text: str) -> str: # TODO ) replaces needed? def sanitize_to_url(text: str) -> str: # TODO ) replaces needed?

View file

@ -62,6 +62,10 @@ def check_tables():
def add_entry(pageid: int, revid: int, logid: int, message, message_id: str): def add_entry(pageid: int, revid: int, logid: int, message, message_id: str):
"""Add an edit or log entry to the DB """Add an edit or log entry to the DB
:param message:
:param logid:
:param revid:
:param pageid:
:param message_id: :param message_id:
""" """
db_cursor.execute("INSERT INTO messages (message_id, content) VALUES (?, ?)", (message_id, message)) db_cursor.execute("INSERT INTO messages (message_id, content) VALUES (?, ?)", (message_id, message))

View file

@ -152,7 +152,7 @@ class ContentParser(HTMLParser):
def handle_data(self, data): def handle_data(self, data):
def escape_formatting(data: str) -> str: def escape_formatting(data: str) -> str:
"""Escape Discord formatting""" """Escape Discord formatting"""
return re.sub(r"([`_*~<>{}@/|\\])", "\\\\\\1", data, 0) return re.sub(r"([`_*~<>{}@/|\\])", "\\\\\\1", data)
data = escape_formatting(data) data = escape_formatting(data)
if self.current_tag == "ins" and self.ins_length <= 1000: if self.current_tag == "ins" and self.ins_length <= 1000:
self.ins_length += len("**" + data + "**") self.ins_length += len("**" + data + "**")

View file

@ -411,7 +411,7 @@ class Wiki(object):
except KeyError: except KeyError:
self.tags[tag["name"]] = None # Tags with no display name are hidden and should not appear on RC as well self.tags[tag["name"]] = None # Tags with no display name are hidden and should not appear on RC as well
for message in startup_info["allmessages"]: for message in startup_info["allmessages"]:
if not "missing" in message: # ignore missing strings if "missing" not in message: # ignore missing strings
self.mw_messages[message["name"]] = message["*"] self.mw_messages[message["name"]] = message["*"]
else: else:
logging.warning("Could not fetch the MW message translation for: {}".format(message["name"])) logging.warning("Could not fetch the MW message translation for: {}".format(message["name"]))