Skip to content

Commit

Permalink
send discord messages async
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name authored and alphatownsman committed Jan 5, 2025
1 parent b2d4b97 commit a95eb3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if you are doing debug or development:
- `smtp+tls://<username>:<password>@<host>:<port>`
- `smtp+ssl://<username>:<password>@<host>:<port>`
- `anymail://<anymail_backend_name>?<anymail_args>`, 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
Expand Down

0 comments on commit a95eb3e

Please sign in to comment.