diff --git a/common/utils.py b/common/utils.py index a3b8a7c6..619871bf 100644 --- a/common/utils.py +++ b/common/utils.py @@ -2,6 +2,7 @@ import uuid from typing import TYPE_CHECKING +import django_rq from discord import SyncWebhook from django.conf import settings from django.conf.locale import LANG_INFO @@ -221,11 +222,17 @@ def get_uuid_or_404(uuid_b62): def discord_send(channel, content, **args) -> bool: - dw = settings.DISCORD_WEBHOOKS.get(channel) + dw = settings.DISCORD_WEBHOOKS.get(channel) or settings.DISCORD_WEBHOOKS.get( + "default" + ) if not dw: return False if "thread_name" in args: args["thread_name"] = args["thread_name"][:99] + django_rq.get_queue("fetch").enqueue(_discord_send, dw, content, **args) + return True + + +def _discord_send(dw, content, **args): webhook = SyncWebhook.from_url(dw) webhook.send(content, **args) - return True diff --git a/docs/configuration.md b/docs/configuration.md index 1ea91f47..43c34d89 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -39,7 +39,7 @@ if you are doing debug or development: - `smtp+tls://:@:` - `smtp+ssl://:@:` - `anymail://?`, to send email via email service providers, see [anymail doc](https://anymail.dev/) - - `DISCORD_WEBHOOKS` - Discord channel to send notification about user submitted suggestion and changes, e.g. `suggest=https://discord.com/api/webhooks/123/abc,audit=https://discord.com/api/webhooks/123/def` + - `DISCORD_WEBHOOKS` - Discord channel to send notification about user submitted suggestion and changes, e.g. `suggest=https://discord.com/api/webhooks/123/abc,audit=https://discord.com/api/webhooks/123/def`. Both suggest and audit channels must be in forum mode. ## Settings for Federation