Revert changes done to FD Discussions from last commit

This commit is contained in:
Frisk 2025-02-13 14:04:35 +01:00
parent 2cacf10ee3
commit 17b82f8782

View file

@ -79,7 +79,7 @@ class DiscussionsFromHellParser:
self.markdown_text = "{old}{img_url}\n".format(old=self.markdown_text, img_url= self.markdown_text = "{old}{img_url}\n".format(old=self.markdown_text, img_url=
self.post["_embedded"]["contentImages"][int(item["attrs"]["id"])]["url"]) self.post["_embedded"]["contentImages"][int(item["attrs"]["id"])]["url"])
self.image_last = self.post["_embedded"]["contentImages"][int(item["attrs"]["id"])]["url"] self.image_last = self.post["_embedded"]["contentImages"][int(item["attrs"]["id"])]["url"]
except (IndexError, ValueError): except (IndexError, ValueError, TypeError):
logger.warning("Image {} not found.".format(item["attrs"]["id"])) logger.warning("Image {} not found.".format(item["attrs"]["id"]))
logger.debug(self.markdown_text) logger.debug(self.markdown_text)
elif item["type"] == "code_block": elif item["type"] == "code_block":
@ -103,7 +103,7 @@ class DiscussionsFromHellParser:
for mark in marks: for mark in marks:
if mark["type"] == "mention": if mark["type"] == "mention":
prefix += "[" prefix += "["
suffix = "]({wiki}f/u/{userid}){suffix}".format(wiki=self.ctx.settings["fandom_discussions"]["wiki_url"], suffix = "]({wiki}f/u/{userid}){suffix}".format(wiki=self.ctx.client.WIKI_SCRIPT_PATH,
userid=mark["attrs"]["userId"], suffix=suffix) userid=mark["attrs"]["userId"], suffix=suffix)
elif mark["type"] == "strong": elif mark["type"] == "strong":
prefix += "**" prefix += "**"
@ -136,16 +136,16 @@ def common_discussions(post: dict, embed: DiscordMessage, ctx: Context):
@formatter.embed(event="discussion/forum") @formatter.embed(event="discussion/forum")
def embed_discussion_forum(ctx: Context, post: dict): def embed_discussion_forum(ctx: Context, post: dict):
embed = DiscordMessage("embed", "discussion", ctx.settings["fandom_discussions"]["webhookURL"]) embed = DiscordMessage("embed", "discussion", ctx.webhook_url)
common_discussions(post, embed, ctx) common_discussions(post, embed, ctx)
author = ctx._("unknown") # Fail safe author = ctx._("unknown") # Fail safe
if post["createdBy"]["name"]: if post["createdBy"]["name"]:
author = post["createdBy"]["name"] author = post["createdBy"]["name"]
embed.set_author(author, "{url}f/u/{creatorId}".format(url=ctx.settings["fandom_discussions"]["wiki_url"], embed.set_author(author, "{url}f/u/{creatorId}".format(url=ctx.client.WIKI_SCRIPT_PATH,
creatorId=post["creatorId"]), creatorId=post["creatorId"]),
icon_url=post["createdBy"]["avatarUrl"]) icon_url=post["createdBy"]["avatarUrl"])
if not post["isReply"]: if not post["isReply"]:
embed["url"] = "{url}f/p/{threadId}".format(url=ctx.settings["fandom_discussions"]["wiki_url"], embed["url"] = "{url}f/p/{threadId}".format(url=ctx.client.WIKI_SCRIPT_PATH,
threadId=post["threadId"]) threadId=post["threadId"])
embed["title"] = ctx._("Created \"{title}\"").format(title=post["title"]) embed["title"] = ctx._("Created \"{title}\"").format(title=post["title"])
thread_funnel = post.get("funnel") thread_funnel = post.get("funnel")
@ -189,7 +189,7 @@ def embed_discussion_forum(ctx: Context, post: dict):
else: else:
embed.event_type = "discussion/forum/reply" embed.event_type = "discussion/forum/reply"
embed["title"] = ctx._("Replied to \"{title}\"").format(title=post["_embedded"]["thread"][0]["title"]) embed["title"] = ctx._("Replied to \"{title}\"").format(title=post["_embedded"]["thread"][0]["title"])
embed["url"] = "{url}f/p/{threadId}/r/{postId}".format(url=ctx.settings["fandom_discussions"]["wiki_url"], embed["url"] = "{url}f/p/{threadId}/r/{postId}".format(url=ctx.client.WIKI_SCRIPT_PATH,
threadId=post["threadId"], postId=post["id"]) threadId=post["threadId"], postId=post["id"])
return embed return embed
@ -200,7 +200,7 @@ def compact_discussion_forum(ctx: Context, post: dict):
author = ctx._("unknown") # Fail safe author = ctx._("unknown") # Fail safe
if post["createdBy"]["name"]: if post["createdBy"]["name"]:
author = post["createdBy"]["name"] author = post["createdBy"]["name"]
author_url = "<{url}f/u/{creatorId}>".format(url=ctx.settings["fandom_discussions"]["wiki_url"], author_url = "<{url}f/u/{creatorId}>".format(url=ctx.client.WIKI_SCRIPT_PATH,
creatorId=post["creatorId"]) creatorId=post["creatorId"])
if not post["isReply"]: if not post["isReply"]:
thread_funnel = post.get("funnel") thread_funnel = post.get("funnel")
@ -219,13 +219,13 @@ def compact_discussion_forum(ctx: Context, post: dict):
thread_funnel)) thread_funnel))
event_type = "unknown" event_type = "unknown"
message = msg_text.format(author=author, author_url=author_url, title=post["title"], message = msg_text.format(author=author, author_url=author_url, title=post["title"],
url=ctx.settings["fandom_discussions"]["wiki_url"], threadId=post["threadId"], url=ctx.client.WIKI_SCRIPT_PATH, threadId=post["threadId"],
forumName=post["forumName"]) forumName=post["forumName"])
else: else:
event_type = "discussion/forum/reply" event_type = "discussion/forum/reply"
message = ctx._( message = ctx._(
"[{author}]({author_url}) created a [reply](<{url}f/p/{threadId}/r/{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}").format( "[{author}]({author_url}) created a [reply](<{url}f/p/{threadId}/r/{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}").format(
author=author, author_url=author_url, url=ctx.settings["fandom_discussions"]["wiki_url"], author=author, author_url=author_url, url=ctx.client.WIKI_SCRIPT_PATH,
threadId=post["threadId"], postId=post["id"], title=post["_embedded"]["thread"][0]["title"], threadId=post["threadId"], postId=post["id"], title=post["_embedded"]["thread"][0]["title"],
forumName=post["forumName"]) forumName=post["forumName"])
return DiscordMessage("compact", event_type, ctx.webhook_url, content=message) return DiscordMessage("compact", event_type, ctx.webhook_url, content=message)
@ -238,14 +238,14 @@ def compact_author_discussions(post: dict, ctx: Context):
author = ctx._("unknown") # Fail safe author = ctx._("unknown") # Fail safe
if post["creatorIp"]: if post["creatorIp"]:
author = post["creatorIp"][1:] if ctx.settings.get("hide_ips", False) is False else ctx._("Unregistered user") author = post["creatorIp"][1:] if ctx.settings.get("hide_ips", False) is False else ctx._("Unregistered user")
author_url = "<{url}wiki/Special:Contributions{creatorIp}>".format(url=ctx.settings["fandom_discussions"]["wiki_url"], author_url = "<{url}wiki/Special:Contributions{creatorIp}>".format(url=ctx.client.WIKI_SCRIPT_PATH,
creatorIp=post["creatorIp"]) creatorIp=post["creatorIp"])
else: else:
if post["createdBy"]["name"]: if post["createdBy"]["name"]:
author = post["createdBy"]["name"] author = post["createdBy"]["name"]
author_url = clean_link(ctx.client.create_article_path("User:{user}".format(user=author))) author_url = clean_link(ctx.client.create_article_path("User:{user}".format(user=author)))
else: else:
author_url = "<{url}f/u/{creatorId}>".format(url=ctx.settings["fandom_discussions"]["wiki_url"], author_url = "<{url}f/u/{creatorId}>".format(url=ctx.client.WIKI_SCRIPT_PATH,
creatorId=post["creatorId"]) creatorId=post["creatorId"])
return author, author_url return author, author_url
@ -256,22 +256,22 @@ def embed_author_discussions(post: dict, embed: DiscordMessage, ctx: Context):
author = post["creatorIp"][1:] author = post["creatorIp"][1:]
embed.set_author(author if ctx.settings.get("hide_ips", False) is False else ctx._("Unregistered user"), embed.set_author(author if ctx.settings.get("hide_ips", False) is False else ctx._("Unregistered user"),
"{url}wiki/Special:Contributions{creatorIp}".format( "{url}wiki/Special:Contributions{creatorIp}".format(
url=ctx.settings["fandom_discussions"]["wiki_url"], creatorIp=post["creatorIp"])) url=ctx.client.WIKI_SCRIPT_PATH, creatorIp=post["creatorIp"]))
else: else:
if post["createdBy"]["name"]: if post["createdBy"]["name"]:
author = post["createdBy"]["name"] author = post["createdBy"]["name"]
embed.set_author(author, "{url}wiki/User:{creator}".format(url=ctx.settings["fandom_discussions"]["wiki_url"], embed.set_author(author, "{url}wiki/User:{creator}".format(url=ctx.client.WIKI_SCRIPT_PATH,
creator=author.replace(" ", "_")), creator=author.replace(" ", "_")),
icon_url=post["createdBy"]["avatarUrl"]) icon_url=post["createdBy"]["avatarUrl"])
else: else:
embed.set_author(author, "{url}f/u/{creatorId}".format(url=ctx.settings["fandom_discussions"]["wiki_url"], embed.set_author(author, "{url}f/u/{creatorId}".format(url=ctx.client.WIKI_SCRIPT_PATH,
creatorId=post["creatorId"]), creatorId=post["creatorId"]),
icon_url=post["createdBy"]["avatarUrl"]) icon_url=post["createdBy"]["avatarUrl"])
@formatter.embed(event="discussion/wall") @formatter.embed(event="discussion/wall")
def embed_discussion_wall(ctx: Context, post: dict): def embed_discussion_wall(ctx: Context, post: dict):
embed = DiscordMessage("embed", "discussion", ctx.settings["fandom_discussions"]["webhookURL"]) embed = DiscordMessage("embed", "discussion", ctx.webhook_url)
common_discussions(post, embed, ctx) common_discussions(post, embed, ctx)
embed_author_discussions(post, embed, ctx) embed_author_discussions(post, embed, ctx)
user_wall = ctx._("unknown") # Fail safe user_wall = ctx._("unknown") # Fail safe
@ -280,13 +280,13 @@ def embed_discussion_wall(ctx: Context, post: dict):
if not post["isReply"]: if not post["isReply"]:
embed.event_type = "discussion/wall/post" embed.event_type = "discussion/wall/post"
embed["url"] = "{url}wiki/Message_Wall:{user_wall}?threadId={threadId}".format( embed["url"] = "{url}wiki/Message_Wall:{user_wall}?threadId={threadId}".format(
url=ctx.settings["fandom_discussions"]["wiki_url"], user_wall=quote_plus(user_wall.replace(" ", "_")), url=ctx.client.WIKI_SCRIPT_PATH, user_wall=quote_plus(user_wall.replace(" ", "_")),
threadId=post["threadId"]) threadId=post["threadId"])
embed["title"] = ctx._("Created \"{title}\" on {user}'s Message Wall").format(title=post["title"], user=user_wall) embed["title"] = ctx._("Created \"{title}\" on {user}'s Message Wall").format(title=post["title"], user=user_wall)
else: else:
embed.event_type = "discussion/wall/reply" embed.event_type = "discussion/wall/reply"
embed["url"] = "{url}wiki/Message_Wall:{user_wall}?threadId={threadId}#{replyId}".format( embed["url"] = "{url}wiki/Message_Wall:{user_wall}?threadId={threadId}#{replyId}".format(
url=ctx.settings["fandom_discussions"]["wiki_url"], user_wall=quote_plus(user_wall.replace(" ", "_")), url=ctx.client.WIKI_SCRIPT_PATH, user_wall=quote_plus(user_wall.replace(" ", "_")),
threadId=post["threadId"], replyId=post["id"]) threadId=post["threadId"], replyId=post["id"])
embed["title"] = ctx._("Replied to \"{title}\" on {user}'s Message Wall").format( embed["title"] = ctx._("Replied to \"{title}\" on {user}'s Message Wall").format(
title=post["_embedded"]["thread"][0]["title"], user=user_wall) title=post["_embedded"]["thread"][0]["title"], user=user_wall)
@ -303,13 +303,13 @@ def compact_discussion_wall(ctx: Context, post: dict):
event_type = "discussion/wall/post" event_type = "discussion/wall/post"
message = ctx._( message = ctx._(
"[{author}]({author_url}) created [{title}](<{url}wiki/Message_Wall:{user_wall}?threadId={threadId}>) on [{user}'s Message Wall](<{url}wiki/Message_Wall:{user_wall}>)").format( "[{author}]({author_url}) created [{title}](<{url}wiki/Message_Wall:{user_wall}?threadId={threadId}>) on [{user}'s Message Wall](<{url}wiki/Message_Wall:{user_wall}>)").format(
author=author, author_url=author_url, title=post["title"], url=ctx.settings["fandom_discussions"]["wiki_url"], author=author, author_url=author_url, title=post["title"], url=ctx.client.WIKI_SCRIPT_PATH,
user=user_wall, user_wall=quote_plus(user_wall.replace(" ", "_")), threadId=post["threadId"]) user=user_wall, user_wall=quote_plus(user_wall.replace(" ", "_")), threadId=post["threadId"])
else: else:
event_type = "discussion/wall/reply" event_type = "discussion/wall/reply"
message = ctx._( message = ctx._(
"[{author}]({author_url}) created a [reply](<{url}wiki/Message_Wall:{user_wall}?threadId={threadId}#{replyId}>) to [{title}](<{url}wiki/Message_Wall:{user_wall}?threadId={threadId}>) on [{user}'s Message Wall](<{url}wiki/Message_Wall:{user_wall}>)").format( "[{author}]({author_url}) created a [reply](<{url}wiki/Message_Wall:{user_wall}?threadId={threadId}#{replyId}>) to [{title}](<{url}wiki/Message_Wall:{user_wall}?threadId={threadId}>) on [{user}'s Message Wall](<{url}wiki/Message_Wall:{user_wall}>)").format(
author=author, author_url=author_url, url=ctx.settings["fandom_discussions"]["wiki_url"], author=author, author_url=author_url, url=ctx.client.WIKI_SCRIPT_PATH,
title=post["_embedded"]["thread"][0]["title"], user=user_wall, title=post["_embedded"]["thread"][0]["title"], user=user_wall,
user_wall=quote_plus(user_wall.replace(" ", "_")), threadId=post["threadId"], replyId=post["id"]) user_wall=quote_plus(user_wall.replace(" ", "_")), threadId=post["threadId"], replyId=post["id"])
return DiscordMessage("compact", event_type, ctx.webhook_url, content=message) return DiscordMessage("compact", event_type, ctx.webhook_url, content=message)
@ -319,12 +319,12 @@ def compact_discussion_wall(ctx: Context, post: dict):
@formatter.embed(event="discussion/article_comment") @formatter.embed(event="discussion/article_comment")
def embed_discussion_article_comment(ctx: Context, post: dict): def embed_discussion_article_comment(ctx: Context, post: dict):
embed = DiscordMessage("embed", "discussion", ctx.settings["fandom_discussions"]["webhookURL"]) embed = DiscordMessage("embed", "discussion", ctx.webhook_url)
common_discussions(post, embed, ctx) common_discussions(post, embed, ctx)
embed_author_discussions(post, embed, ctx) embed_author_discussions(post, embed, ctx)
article_paths = ctx.comment_page article_paths = ctx.comment_page
if article_paths is None: if article_paths is None:
article_paths = {"title": ctx._("unknown"), "fullUrl": ctx.settings["fandom_discussions"]["wiki_url"]} # No page known article_paths = {"title": ctx._("unknown"), "fullUrl": ctx.client.WIKI_SCRIPT_PATH} # No page known
if not post["isReply"]: if not post["isReply"]:
embed.event_type = "discussion/comment/post" embed.event_type = "discussion/comment/post"
embed["url"] = "{url}?commentId={commentId}".format(url=article_paths["fullUrl"], commentId=post["threadId"]) embed["url"] = "{url}?commentId={commentId}".format(url=article_paths["fullUrl"], commentId=post["threadId"])
@ -344,7 +344,7 @@ def compact_discussion_article_comment(ctx: Context, post: dict):
author, author_url = compact_author_discussions(post, ctx) author, author_url = compact_author_discussions(post, ctx)
article_paths = ctx.comment_page article_paths = ctx.comment_page
if article_paths is None: if article_paths is None:
article_paths = {"title": ctx._("unknown"), "fullUrl": ctx.settings["fandom_discussions"]["wiki_url"]} # No page known article_paths = {"title": ctx._("unknown"), "fullUrl": ctx.client.WIKI_SCRIPT_PATH} # No page known
article_paths["fullUrl"] = article_paths["fullUrl"].replace(")", "\\)").replace("()", "\\(") article_paths["fullUrl"] = article_paths["fullUrl"].replace(")", "\\)").replace("()", "\\(")
if not post["isReply"]: if not post["isReply"]:
event_type = "discussion/comment/post" event_type = "discussion/comment/post"