From c7dfba01eaf8320fc6a8a66069c88c59364c6250 Mon Sep 17 00:00:00 2001 From: Markus-Rost Date: Sun, 2 Aug 2020 13:44:57 +0200 Subject: [PATCH] make webhookURL an array --- scripts/configbuilder.py | 2 +- settings.json.example | 8 ++++++-- src/discussion_formatters.py | 4 ++-- src/misc.py | 2 +- src/rc_formatters.py | 4 ++-- src/rcgcdw.py | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/configbuilder.py b/scripts/configbuilder.py index f6ec3ff..8ed3efb 100644 --- a/scripts/configbuilder.py +++ b/scripts/configbuilder.py @@ -169,7 +169,7 @@ def set_webhook(): print("The webhook URL does not seem right. Reason: {}".format(test_webhook.json()["message"])) return False else: - settings["webhookURL"] = option + settings["webhookURL"] = [option] return True else: print("A Discord webhook URL should start with https://discord.com/api/webhooks/, are you sure it's the right URL?") diff --git a/settings.json.example b/settings.json.example index ba2fd4c..b38f324 100644 --- a/settings.json.example +++ b/settings.json.example @@ -7,7 +7,9 @@ "user-agent": "RcGcDw/{version}" }, "limit": 10, - "webhookURL": "https://discordapp.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "webhookURL": [ + "https://discordapp.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ], "limitrefetch": 28, "wikiname": "Wreck It Woodhouse", "avatars": { @@ -293,7 +295,9 @@ "wiki_id": 1885853, "wiki_url": "https://wikibot.fandom.com/", "cooldown": 60, - "webhookURL": "https://discordapp.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "webhookURL": [ + "https://discordapp.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ], "limit": 5, "appearance": { "mode": "embed", diff --git a/src/discussion_formatters.py b/src/discussion_formatters.py index ace0cf2..7d6c2f8 100644 --- a/src/discussion_formatters.py +++ b/src/discussion_formatters.py @@ -14,7 +14,7 @@ discussion_logger = logging.getLogger("rcgcdw.discussion_formatter") def embed_formatter(post, post_type): """Embed formatter for Fandom discussions.""" - embed = DiscordMessage("embed", "discussion", settings["fandom_discussions"]["webhookURL"]) + embed = DiscordMessage("embed", "discussion", settings["fandom_discussions"]["webhookURL"][int(post["id"]) % len(settings["fandom_discussions"]["webhookURL"])]) 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"]) discussion_post_type = post["_embedded"]["thread"][0].get("containerType", "FORUM") # Can be FORUM, ARTICLE_COMMENT or WALL on UCP @@ -122,7 +122,7 @@ def compact_formatter(post, post_type): "[{author}](<{url}f/u/{creatorId}>) created a poll [{title}](<{url}f/p/{threadId}>) in {forumName}").format( author=post["createdBy"]["name"], url=settings["fandom_discussions"]["wiki_url"], creatorId=post["creatorId"], title=post["title"], threadId=post["threadId"], forumName=post["forumName"]) - send_to_discord(DiscordMessage("compact", "discussion", settings["fandom_discussions"]["webhookURL"], content=message)) + send_to_discord(DiscordMessage("compact", "discussion", settings["fandom_discussions"]["webhookURL"][int(post["id"]) % len(settings["fandom_discussions"]["webhookURL"])], content=message)) class DiscussionsFromHellParser: diff --git a/src/misc.py b/src/misc.py index ab87213..65bfded 100644 --- a/src/misc.py +++ b/src/misc.py @@ -305,7 +305,7 @@ def create_article_path(article: str) -> str: def send_simple(msgtype, message, name, avatar): - discord_msg = DiscordMessage("compact", msgtype, settings["webhookURL"], content=message) + discord_msg = DiscordMessage("compact", msgtype, settings["webhookURL"][0], content=message) discord_msg.set_avatar(avatar) discord_msg.set_name(name) messagequeue.resend_msgs() diff --git a/src/rc_formatters.py b/src/rc_formatters.py index e272427..a12b578 100644 --- a/src/rc_formatters.py +++ b/src/rc_formatters.py @@ -321,11 +321,11 @@ def compact_formatter(action, change, parsed_comment, categories, recent_changes else: logger.warning("No entry for {event} with params: {params}".format(event=action, params=change)) return - send_to_discord(DiscordMessage("compact", action, settings["webhookURL"], content=content)) + send_to_discord(DiscordMessage("compact", action, settings["webhookURL"][change["rcid"] % len(settings["webhookURL"])], content=content)) def embed_formatter(action, change, parsed_comment, categories, recent_changes): - embed = DiscordMessage("embed", action, settings["webhookURL"]) + embed = DiscordMessage("embed", action, settings["webhookURL"][change["rcid"] % len(settings["webhookURL"])]) if parsed_comment is None: parsed_comment = _("No description provided") if action != "suppressed": diff --git a/src/rcgcdw.py b/src/rcgcdw.py index 78eaf27..275855d 100644 --- a/src/rcgcdw.py +++ b/src/rcgcdw.py @@ -140,7 +140,7 @@ def day_overview(): changed_bytes = 0 new_articles = 0 active_articles = [] - embed = DiscordMessage("embed", "daily_overview", settings["webhookURL"]) + embed = DiscordMessage("embed", "daily_overview", settings["webhookURL"][0]) embed["title"] = _("Daily overview") embed["url"] = create_article_path("Special:Statistics") embed.set_author(settings["wikiname"], create_article_path(""),