send discord messages async
This commit is contained in:
parent
b2d4b97d33
commit
a95eb3eb50
2 changed files with 10 additions and 3 deletions
|
@ -2,6 +2,7 @@ import functools
|
|||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue