Started work towards #61

This commit is contained in:
Frisk 2019-04-15 21:35:02 +02:00
parent 1692256aef
commit f89ab0e598
No known key found for this signature in database
GPG key ID: 0E9A7D3C0A01586C

View file

@ -154,7 +154,7 @@ def send_to_discord(data):
pass pass
def webhook_formatter(action, STATIC, **params): def webhook_formatter(change, parseddomment, **params):
logging.debug("Received things: {thing}".format(thing=params)) logging.debug("Received things: {thing}".format(thing=params))
colornumber = None if isinstance(STATIC["color"], str) else STATIC["color"] colornumber = None if isinstance(STATIC["color"], str) else STATIC["color"]
data = {"embeds": []} data = {"embeds": []}
@ -571,22 +571,20 @@ def handle_discord_http(code, formatted_embed, result):
return 3 return 3
def first_pass( def essential_info(change, changed_categories):
change, changed_categories): # I've decided to split the embed formatter and change handler, maybe it's more messy this way, I don't know """Prepares essential information for both embed and compact message format."""
if ("actionhidden" in change or "suppressed" in change) and "suppressed" not in settings["ignored"]: logging.debug(change)
webhook_formatter("suppressed", if ("actionhidden" in change or "suppressed" in change) and "suppressed" not in settings["ignored"]: # if event is hidden using supression
{"timestamp": change["timestamp"], "color": settings["appearance"]["suppressed"]["color"], # webhook_formatter("suppressed",
"icon": settings["appearance"]["suppressed"]["icon"]}, user=change["user"]) # {"timestamp": change["timestamp"], "color": settings["appearance"]["suppressed"]["color"],
# "icon": settings["appearance"]["suppressed"]["icon"]}, user=change["user"])
return return
if "commenthidden" not in change: if "commenthidden" not in change:
LinkParser.feed(change["parsedcomment"]) LinkParser.feed(change["parsedcomment"])
# parsedcomment = (BeautifulSoup(change["parsedcomment"], "lxml")).get_text()
parsedcomment = LinkParser.new_string parsedcomment = LinkParser.new_string
LinkParser.new_string = "" LinkParser.new_string = ""
else: else:
parsedcomment = _("~~hidden~~") parsedcomment = _("~~hidden~~")
logging.debug(change)
STATIC_VARS = {"timestamp": change["timestamp"], "tags": change["tags"], "redirect": (True if "redirect" in change else False), "ipaction": (True if "anon" in change else False), "changed_categories": changed_categories}
if not parsedcomment: if not parsedcomment:
parsedcomment = _("No description provided") parsedcomment = _("No description provided")
parsedcomment = re.sub(r"(`|_|\*|~|<|>|{|}|\|\|)", "\\\\\\1", parsedcomment, 0) parsedcomment = re.sub(r"(`|_|\*|~|<|>|{|}|\|\|)", "\\\\\\1", parsedcomment, 0)
@ -594,6 +592,24 @@ def first_pass(
logging.debug("List of categories in first_pass: {}".format(changed_categories)) logging.debug("List of categories in first_pass: {}".format(changed_categories))
if "userhidden" in change: if "userhidden" in change:
change["user"] = _("hidden") change["user"] = _("hidden")
elif change["type"] == "categorize":
return
if settings["appearance"]["mode"] == "webhook":
webhook_formatter(change, parsedcomment, changed_categories)
elif settings["appearance"]["mode"] == "compact":
compact_formatter(change, parsedcomment, changed_categories)
else:
logging.critical("Unknown formatter!")
sys.exit(1)
def first_pass(
change, changed_categories): # I've decided to split the embed formatter and change handler, maybe it's more messy this way, I don't know
STATIC_VARS = {"timestamp": change["timestamp"], "tags": change["tags"], "redirect": (True if "redirect" in change else False), "ipaction": (True if "anon" in change else False), "changed_categories": changed_categories}
STATIC_VARS = {**STATIC_VARS, **{"color": settings["appearance"]["edit"]["color"], STATIC_VARS = {**STATIC_VARS, **{"color": settings["appearance"]["edit"]["color"],
"icon": settings["appearance"]["edit"]["icon"]}} "icon": settings["appearance"]["edit"]["icon"]}}
webhook_formatter("edit", STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment, webhook_formatter("edit", STATIC_VARS, user=change["user"], title=change["title"], desc=parsedcomment,