Fix Discord webhooks failing due to avatar URL being relative

This commit is contained in:
rubenwardy 2023-05-14 17:21:23 +01:00
parent 1a173153c8
commit 8178232911

@ -37,6 +37,8 @@ def post_discord_webhook(username: Optional[str], content: str, is_queue: bool,
user = User.query.filter_by(username=username).first() user = User.query.filter_by(username=username).first()
if user: if user:
json["avatar_url"] = user.getProfilePicURL().replace("/./", "/") json["avatar_url"] = user.getProfilePicURL().replace("/./", "/")
if json["avatar_url"].startswith("/"):
json["avatar_url"] = app.config["BASE_URL"] + json["avatar_url"]
if title: if title:
embed = { embed = {
@ -51,5 +53,5 @@ def post_discord_webhook(username: Optional[str], content: str, is_queue: bool,
res = requests.post(discord_url, json=json, headers={"Accept": "application/json"}) res = requests.post(discord_url, json=json, headers={"Accept": "application/json"})
if res.status_code != 200: if res.status_code != 200:
print("Failed to submit Discord webhook", res.json(), file=sys.stderr) raise f"Failed to submit Discord webhook {res.json}"
res.raise_for_status() res.raise_for_status()