Added support for wall discussion posts as per #126

This commit is contained in:
Frisk 2020-06-23 15:02:38 +02:00
parent 4c6cfda901
commit 62fd4e0e33
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
7 changed files with 335 additions and 225 deletions

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-04-26 22:05+0200\n" "POT-Creation-Date: 2020-06-23 14:54+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,45 +17,59 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n" "Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: discussions.py:53 #: discussions.py:56
#, python-brace-format #, python-brace-format
msgid "Replied to \"{title}\"" msgid "Replied to \"{title}\""
msgstr "" msgstr ""
#: discussions.py:58 #: discussions.py:63 discussions.py:79
msgid "unknown"
msgstr ""
#: discussions.py:68
#, python-brace-format
msgid "Replied to \"{title}\" on {user}'s Message Wall"
msgstr ""
#: discussions.py:72
#, python-brace-format #, python-brace-format
msgid "Created \"{title}\"" msgid "Created \"{title}\""
msgstr "" msgstr ""
#: discussions.py:70 #: discussions.py:86
#, python-brace-format
msgid "Created \"{title}\" on {user}'s Message Wall"
msgstr ""
#: discussions.py:99
#, python-brace-format #, python-brace-format
msgid "Created a poll titled \"{title}\"" msgid "Created a poll titled \"{title}\""
msgstr "" msgstr ""
#: discussions.py:75 #: discussions.py:104
msgid "Option {}" msgid "Option {}"
msgstr "" msgstr ""
#: discussions.py:76 #: discussions.py:105
#, python-brace-format #, python-brace-format
msgid "__[View image]({image_url})__" msgid "__[View image]({image_url})__"
msgstr "" msgstr ""
#: discussions.py:89 #: discussions.py:118
#, python-brace-format #, python-brace-format
msgid "" msgid ""
"[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) " "[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) "
"in {forumName}" "in {forumName}"
msgstr "" msgstr ""
#: discussions.py:92 #: discussions.py:121
#, python-brace-format #, python-brace-format
msgid "" msgid ""
"[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/" "[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/"
"{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}" "{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}"
msgstr "" msgstr ""
#: discussions.py:97 #: discussions.py:126
#, python-brace-format #, python-brace-format
msgid "" msgid ""
"[{author}](<{url}f/u/{creatorId}>) created a poll [{title}](<{url}f/p/" "[{author}](<{url}f/u/{creatorId}>) created a poll [{title}](<{url}f/p/"

View file

@ -19,6 +19,7 @@
import logging, gettext, schedule, requests, json, datetime import logging, gettext, schedule, requests, json, datetime
from collections import defaultdict from collections import defaultdict
from configloader import settings from configloader import settings
from urllib.parse import quote_plus
from misc import datafile, send_to_discord, DiscordMessage, WIKI_SCRIPT_PATH, escape_formatting, messagequeue from misc import datafile, send_to_discord, DiscordMessage, WIKI_SCRIPT_PATH, escape_formatting, messagequeue
from session import session from session import session
@ -47,17 +48,42 @@ def embed_formatter(post, post_type):
embed = DiscordMessage("embed", "discussion", settings["fandom_discussions"]["webhookURL"]) embed = DiscordMessage("embed", "discussion", settings["fandom_discussions"]["webhookURL"])
embed.set_author(post["createdBy"]["name"], "{wikiurl}f/u/{creatorId}".format( embed.set_author(post["createdBy"]["name"], "{wikiurl}f/u/{creatorId}".format(
wikiurl=settings["fandom_discussions"]["wiki_url"], creatorId=post["creatorId"]), icon_url=post["createdBy"]["avatarUrl"]) wikiurl=settings["fandom_discussions"]["wiki_url"], creatorId=post["creatorId"]), icon_url=post["createdBy"]["avatarUrl"])
discussion_post_type = post["_embedded"]["thread"][0].get("containerType", "FORUM") # Can be FORUM, ARTICLE_COMMENT or WALL on UCP
if post_type == "TEXT": if post_type == "TEXT":
if post["isReply"]: if post["isReply"]:
embed.event_type = "discussion/reply" if discussion_post_type == "FORUM":
embed.event_type = "discussion/forum/reply"
embed["title"] = _("Replied to \"{title}\"").format(title=post["_embedded"]["thread"][0]["title"]) embed["title"] = _("Replied to \"{title}\"").format(title=post["_embedded"]["thread"][0]["title"])
embed["url"] = "{wikiurl}f/p/{threadId}/r/{postId}".format( embed["url"] = "{wikiurl}f/p/{threadId}/r/{postId}".format(
wikiurl=settings["fandom_discussions"]["wiki_url"], threadId=post["threadId"], postId=post["id"]) wikiurl=settings["fandom_discussions"]["wiki_url"], threadId=post["threadId"], postId=post["id"])
elif discussion_post_type == "ARTICLE_COMMENT":
discussion_logger.warning("Article comments are not yet implemented. For reasons see https://gitlab.com/piotrex43/RcGcDw/-/issues/126#note_366480037")
return
elif discussion_post_type == "WALL":
user_wall = _("unknown") # Fail safe
embed.event_type = "discussion/wall/reply"
if post["forumName"].endswith(' Message Wall'):
user_wall = post["forumName"][:-13]
embed["url"] = "{wikiurl}wiki/Message_Wall:{user_wall}?threadId={threadid}#{replyId}".format(wikiurl=settings["fandom_discussions"]["wiki_url"], user_wall=quote_plus(user_wall.replace(" ", "_")), threadid=post["threadId"], replyId=post["id"])
embed["title"] = _("Replied to \"{title}\" on {user}'s Message Wall").format(title=post["_embedded"]["thread"][0]["title"], user=user_wall)
else: else:
embed.event_type = "discussion/post" if discussion_post_type == "FORUM":
embed.event_type = "discussion/forum/post"
embed["title"] = _("Created \"{title}\"").format(title=post["title"]) embed["title"] = _("Created \"{title}\"").format(title=post["title"])
embed["url"] = "{wikiurl}f/p/{threadId}".format(wikiurl=settings["fandom_discussions"]["wiki_url"], embed["url"] = "{wikiurl}f/p/{threadId}".format(wikiurl=settings["fandom_discussions"]["wiki_url"],
threadId=post["threadId"]) threadId=post["threadId"])
elif discussion_post_type == "ARTICLE_COMMENT":
discussion_logger.warning("Article comments are not yet implemented. For reasons see https://gitlab.com/piotrex43/RcGcDw/-/issues/126#note_366480037")
return
elif discussion_post_type == "WALL":
user_wall = _("unknown") # Fail safe
embed.event_type = "discussion/wall/post"
if post["forumName"].endswith(' Message Wall'):
user_wall = post["forumName"][:-13]
embed["url"] = "{wikiurl}wiki/Message_Wall:{user_wall}?threadId={threadid}".format(
wikiurl=settings["fandom_discussions"]["wiki_url"], user_wall=quote_plus(user_wall.replace(" ", "_")),
threadid=post["threadId"])
embed["title"] = _("Created \"{title}\" on {user}'s Message Wall").format(title=post["_embedded"]["thread"][0]["title"], user=user_wall)
if settings["fandom_discussions"]["appearance"]["embed"]["show_content"]: if settings["fandom_discussions"]["appearance"]["embed"]["show_content"]:
if post.get("jsonModel") is not None: if post.get("jsonModel") is not None:
npost = DiscussionsFromHellParser(post) npost = DiscussionsFromHellParser(post)
@ -68,7 +94,7 @@ def embed_formatter(post, post_type):
else: # Fallback when model is not available else: # Fallback when model is not available
embed["description"] = post.get("rawContent", "") embed["description"] = post.get("rawContent", "")
elif post_type == "POLL": elif post_type == "POLL":
embed.event_type = "discussion/poll" embed.event_type = "discussion/forum/poll"
poll = post["poll"] poll = post["poll"]
embed["title"] = _("Created a poll titled \"{title}\"").format(title=poll["question"]) embed["title"] = _("Created a poll titled \"{title}\"").format(title=poll["question"])
image_type = False image_type = False

Binary file not shown.

View file

@ -7,31 +7,84 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-04-05 22:10+0200\n" "POT-Creation-Date: 2020-06-23 14:54+0200\n"
"PO-Revision-Date: 2020-04-06 19:24+0200\n" "PO-Revision-Date: 2020-06-23 14:57+0200\n"
"Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"Language: en\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.3\n" "X-Generator: Poedit 2.3\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: en\n"
#: discussions.py:53
#, python-brace-format
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) "
"in ${forumName}"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) "
"in ${forumName}"
#: discussions.py:56 #: discussions.py:56
#, python-brace-format #, python-brace-format
msgid "Replied to \"{title}\""
msgstr "Replied to \"{title}\""
#: discussions.py:63 discussions.py:79
msgid "unknown"
msgstr "unknown"
#: discussions.py:68
#, python-brace-format
msgid "Replied to \"{title}\" on {user}'s Message Wall"
msgstr "Replied to \"{title}\" on {user}'s Message Wall"
#: discussions.py:72
#, python-brace-format
msgid "Created \"{title}\""
msgstr "Created \"{title}\""
#: discussions.py:86
#, python-brace-format
msgid "Created \"{title}\" on {user}'s Message Wall"
msgstr "Created \"{title}\" on {user}'s Message Wall"
#: discussions.py:99
#, python-brace-format
msgid "Created a poll titled \"{title}\""
msgstr "Created a poll titled \"{title}\""
#: discussions.py:104
msgid "Option {}"
msgstr "Option {}"
#: discussions.py:105
#, python-brace-format
msgid "__[View image]({image_url})__"
msgstr "__[View image]({image_url})__"
#: discussions.py:118
#, python-brace-format
#| msgid ""
#| "[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}"
#| ">) in ${forumName}"
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) "
"in {forumName}"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) "
"in {forumName}"
#: discussions.py:121
#, python-brace-format
msgid "" msgid ""
"[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/" "[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/"
"{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}" "{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}"
msgstr "" msgstr ""
"[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/" "[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/"
"{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}" "{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}"
#: discussions.py:126
#, python-brace-format
#| msgid ""
#| "[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}"
#| ">) in ${forumName}"
msgid ""
"[{author}](<{url}f/u/{creatorId}>) created a poll [{title}](<{url}f/p/"
"{threadId}>) in {forumName}"
msgstr ""
"[{author}](<{url}f/u/{creatorId}>) created a poll [{title}](<{url}f/p/"
"{threadId}>) in {forumName}"

Binary file not shown.

View file

@ -7,8 +7,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-04-26 22:05+0200\n" "POT-Creation-Date: 2020-06-23 14:54+0200\n"
"PO-Revision-Date: 2020-04-26 22:15+0200\n" "PO-Revision-Date: 2020-06-23 14:56+0200\n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"Language: pl\n" "Language: pl\n"
@ -19,31 +19,48 @@ msgstr ""
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 " "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 "
"|| n%100>14) ? 1 : 2);\n" "|| n%100>14) ? 1 : 2);\n"
#: discussions.py:53 #: discussions.py:56
#, python-brace-format #, python-brace-format
msgid "Replied to \"{title}\"" msgid "Replied to \"{title}\""
msgstr "Odpowiedział(a) w „{title}”" msgstr "Odpowiedział(a) w „{title}”"
#: discussions.py:58 #: discussions.py:63 discussions.py:79
msgid "unknown"
msgstr "nieznany"
#: discussions.py:68
#, python-brace-format
msgid "Replied to \"{title}\" on {user}'s Message Wall"
msgstr ""
"Odpowiedział(a) na „{title}” z tablicy wiadomości użytkownika/użytkowniczki "
"{user}"
#: discussions.py:72
#, python-brace-format #, python-brace-format
msgid "Created \"{title}\"" msgid "Created \"{title}\""
msgstr "Utworzył(a) „{title}”" msgstr "Utworzył(a) „{title}”"
#: discussions.py:70 #: discussions.py:86
#, python-brace-format
msgid "Created \"{title}\" on {user}'s Message Wall"
msgstr ""
"Utworzył(a) „{title}” na tablicy wiadomości użytkownika/użytkowniczki {user}"
#: discussions.py:99
#, python-brace-format #, python-brace-format
msgid "Created a poll titled \"{title}\"" msgid "Created a poll titled \"{title}\""
msgstr "Utworzył(a) ankietę zatytułowaną „{title}”" msgstr "Utworzył(a) ankietę zatytułowaną „{title}”"
#: discussions.py:75 #: discussions.py:104
msgid "Option {}" msgid "Option {}"
msgstr "Opcja {}" msgstr "Opcja {}"
#: discussions.py:76 #: discussions.py:105
#, python-brace-format #, python-brace-format
msgid "__[View image]({image_url})__" msgid "__[View image]({image_url})__"
msgstr "__[Zobacz zdjęcie]({image_url})__" msgstr "__[Zobacz zdjęcie]({image_url})__"
#: discussions.py:89 #: discussions.py:118
#, python-brace-format #, python-brace-format
msgid "" msgid ""
"[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) " "[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) "
@ -52,7 +69,7 @@ msgstr ""
"[{author}](<{url}f/u/{creatorId}>) utworzył(a) [{title}](<{url}f/p/{threadId}" "[{author}](<{url}f/u/{creatorId}>) utworzył(a) [{title}](<{url}f/p/{threadId}"
">) w {forumName}" ">) w {forumName}"
#: discussions.py:92 #: discussions.py:121
#, python-brace-format #, python-brace-format
msgid "" msgid ""
"[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/" "[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/"
@ -62,7 +79,7 @@ msgstr ""
"{threadId}/r/{postId}>) pod tematem [{title}](<{url}f/p/{threadId}>) w " "{threadId}/r/{postId}>) pod tematem [{title}](<{url}f/p/{threadId}>) w "
"{forumName}" "{forumName}"
#: discussions.py:97 #: discussions.py:126
#, python-brace-format #, python-brace-format
msgid "" msgid ""
"[{author}](<{url}f/u/{creatorId}>) created a poll [{title}](<{url}f/p/" "[{author}](<{url}f/u/{creatorId}>) created a poll [{title}](<{url}f/p/"

File diff suppressed because it is too large Load diff