Add support for Discord webhooks

This commit is contained in:
2024-06-28 06:04:30 +02:00
parent c266f32275
commit 3f7bacca2f
8 changed files with 99 additions and 3 deletions

31
core/discord.py Normal file
View File

@ -0,0 +1,31 @@
import logging
from typing import TYPE_CHECKING
from discord_webhook import DiscordWebhook
from django.conf import settings
if TYPE_CHECKING:
from requests import Response
logger: logging.Logger = logging.getLogger(__name__)
def send(message: str) -> None:
"""Send a message to Discord.
Args:
message: The message to send.
"""
webhook_url = str(settings.DISCORD_WEBHOOK_URL)
if not webhook_url:
logger.error("No Discord webhook URL found.")
return
webhook = DiscordWebhook(
url=webhook_url,
content=message,
username="TTVDrops",
rate_limit_retry=True,
)
response: Response = webhook.execute()
logger.debug(response)