mirror of
https://github.com/minetest/contentdb.git
synced 2024-10-18 07:43:10 +02:00
Allow Discord webhook URLs to be an array
This commit is contained in:
parent
f69bc8fc1e
commit
d56430c0f0
@ -25,10 +25,13 @@ from app.tasks import celery
|
|||||||
|
|
||||||
@celery.task()
|
@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):
|
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")
|
discord_urls = app.config.get("DISCORD_WEBHOOK_QUEUE" if is_queue else "DISCORD_WEBHOOK_FEED")
|
||||||
if discord_url is None:
|
if discord_urls is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if isinstance(discord_urls, str):
|
||||||
|
discord_urls = [discord_urls]
|
||||||
|
|
||||||
json = {
|
json = {
|
||||||
"content": content[0:2000],
|
"content": content[0:2000],
|
||||||
}
|
}
|
||||||
@ -52,7 +55,8 @@ def post_discord_webhook(username: Optional[str], content: str, is_queue: bool,
|
|||||||
|
|
||||||
json["embeds"] = [embed]
|
json["embeds"] = [embed]
|
||||||
|
|
||||||
res = requests.post(discord_url, json=json, headers={"Accept": "application/json"})
|
for url in discord_urls:
|
||||||
if not res.ok:
|
res = requests.post(url, json=json, headers={"Accept": "application/json"})
|
||||||
raise Exception(f"Failed to submit Discord webhook {res.json}")
|
if not res.ok:
|
||||||
res.raise_for_status()
|
raise Exception(f"Failed to submit Discord webhook {res.json}")
|
||||||
|
res.raise_for_status()
|
||||||
|
Loading…
Reference in New Issue
Block a user