This commit is contained in:
Frisk 2020-04-08 12:59:41 +02:00
parent 5b7a940a6d
commit 00fa479b13
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
2 changed files with 7 additions and 7 deletions

View file

@ -19,7 +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 misc import datafile, WIKI_SCRIPT_PATH, send_to_discord from misc import datafile, send_to_discord
from session import session from session import session
# Initialize translation # Initialize translation
@ -48,13 +48,13 @@ def embed_formatter(post):
data = {"embeds": []} data = {"embeds": []}
embed["author"]["name"] = post["createdBy"]["name"] embed["author"]["name"] = post["createdBy"]["name"]
embed["author"]["icon_url"] = post["createdBy"]["avatarUrl"] embed["author"]["icon_url"] = post["createdBy"]["avatarUrl"]
embed["author"]["url"] = "{wikiurl}f/u/{creatorId}".format(wikiurl=WIKI_SCRIPT_PATH, creatorId=post["creatorId"]) embed["author"]["url"] = "{wikiurl}f/u/{creatorId}".format(wikiurl=settings["fandom_discussions"]["wiki_url"], creatorId=post["creatorId"])
if post["isReply"]: if post["isReply"]:
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(wikiurl=WIKI_SCRIPT_PATH, threadId=post["threadId"], postId=post["id"]) embed["url"] = "{wikiurl}f/p/{threadId}/r/{postId}".format(wikiurl=settings["fandom_discussions"]["wiki_url"], threadId=post["threadId"], postId=post["id"])
else: else:
embed["title"] = _("Created \"{title}\"").format(title=post["title"]) embed["title"] = _("Created \"{title}\"").format(title=post["title"])
embed["url"] = "{wikiurl}f/p/{threadId}".format(wikiurl=WIKI_SCRIPT_PATH, threadId=post["threadId"]) embed["url"] = "{wikiurl}f/p/{threadId}".format(wikiurl=settings["fandom_discussions"]["wiki_url"], threadId=post["threadId"])
if settings["fandom_discussions"]["appearance"]["embed"]["show_content"]: if settings["fandom_discussions"]["appearance"]["embed"]["show_content"]:
embed["description"] = post["rawContent"] if len(post["rawContent"]) < 2000 else post["rawContent"][0:2000] + "" embed["description"] = post["rawContent"] if len(post["rawContent"]) < 2000 else post["rawContent"][0:2000] + ""
embed["footer"]["text"] = post["forumName"] embed["footer"]["text"] = post["forumName"]
@ -71,10 +71,10 @@ def compact_formatter(post):
message = None message = None
if not post["isReply"]: if not post["isReply"]:
message = _("[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) in {forumName}").format( message = _("[{author}](<{url}f/u/{creatorId}>) created [{title}](<{url}f/p/{threadId}>) in {forumName}").format(
author=post["createdBy"]["name"], url=WIKI_SCRIPT_PATH, creatorId=post["creatorId"], title=post["title"], threadId=post["threadId"], forumName=post["forumName"]) author=post["createdBy"]["name"], url=settings["fandom_discussions"]["wiki_url"], creatorId=post["creatorId"], title=post["title"], threadId=post["threadId"], forumName=post["forumName"])
else: else:
message = _("[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}").format( message = _("[{author}](<{url}f/u/{creatorId}>) created a [reply](<{url}f/p/{threadId}/r/{postId}>) to [{title}](<{url}f/p/{threadId}>) in {forumName}").format(
author=post["createdBy"]["name"], url=WIKI_SCRIPT_PATH, creatorId=post["creatorId"], threadId=post["threadId"], postId=post["id"], title=post["_embedded"]["thread"][0]["title"], forumName=post["forumName"] author=post["createdBy"]["name"], url=settings["fandom_discussions"]["wiki_url"], creatorId=post["creatorId"], threadId=post["threadId"], postId=post["id"], title=post["_embedded"]["thread"][0]["title"], forumName=post["forumName"]
) )
send_to_discord(json.dumps({'content': message, 'allowed_mentions': {'parse': []}})) send_to_discord(json.dumps({'content': message, 'allowed_mentions': {'parse': []}}))
@ -118,7 +118,6 @@ def safe_request(url):
return None return None
return request return request
formatter = embed_formatter if settings["fandom_discussions"]["appearance"]["mode"] == "embed" else compact_formatter formatter = embed_formatter if settings["fandom_discussions"]["appearance"]["mode"] == "embed" else compact_formatter
schedule.every(settings["fandom_discussions"]["cooldown"]).seconds.do(fetch_discussions) schedule.every(settings["fandom_discussions"]["cooldown"]).seconds.do(fetch_discussions)

View file

@ -269,6 +269,7 @@
"fandom_discussions": { "fandom_discussions": {
"enabled": false, "enabled": false,
"wiki_id": 1885853, "wiki_id": 1885853,
"wiki_url": "https://wikibot.fandom.com/",
"cooldown": 60, "cooldown": 60,
"webhookURL": "https://discordapp.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "webhookURL": "https://discordapp.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"limit": 5, "limit": 5,