From d56430c0f05468f3c832465feb2e6327c04f7c27 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 6 Oct 2024 21:03:13 +0100 Subject: [PATCH] Allow Discord webhook URLs to be an array --- app/tasks/webhooktasks.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/tasks/webhooktasks.py b/app/tasks/webhooktasks.py index 4879c3f5..cda104b4 100644 --- a/app/tasks/webhooktasks.py +++ b/app/tasks/webhooktasks.py @@ -25,10 +25,13 @@ from app.tasks import celery @celery.task() def post_discord_webhook(username: Optional[str], content: str, is_queue: bool, title: Optional[str] = None, description: Optional[str] = None, thumbnail: Optional[str] = None): - discord_url = app.config.get("DISCORD_WEBHOOK_QUEUE" if is_queue else "DISCORD_WEBHOOK_FEED") - if discord_url is None: + discord_urls = app.config.get("DISCORD_WEBHOOK_QUEUE" if is_queue else "DISCORD_WEBHOOK_FEED") + if discord_urls is None: return + if isinstance(discord_urls, str): + discord_urls = [discord_urls] + json = { "content": content[0:2000], } @@ -52,7 +55,8 @@ def post_discord_webhook(username: Optional[str], content: str, is_queue: bool, json["embeds"] = [embed] - res = requests.post(discord_url, json=json, headers={"Accept": "application/json"}) - if not res.ok: - raise Exception(f"Failed to submit Discord webhook {res.json}") - res.raise_for_status() + for url in discord_urls: + res = requests.post(url, json=json, headers={"Accept": "application/json"}) + if not res.ok: + raise Exception(f"Failed to submit Discord webhook {res.json}") + res.raise_for_status()