diff --git a/.env.example b/.env.example index 47e3f66..a24a778 100644 --- a/.env.example +++ b/.env.example @@ -2,3 +2,4 @@ DJANGO_SECRET_KEY= DEBUG=True EMAIL_HOST_USER= EMAIL_HOST_PASSWORD= +DISCORD_WEBHOOK_URL= diff --git a/config/settings.py b/config/settings.py index 4883d2c..ce40619 100644 --- a/config/settings.py +++ b/config/settings.py @@ -59,6 +59,7 @@ DEFAULT_FROM_EMAIL: str = os.getenv( default="webmaster@localhost", ) SERVER_EMAIL: str = os.getenv(key="EMAIL_HOST_USER", default="webmaster@localhost") +DISCORD_WEBHOOK_URL: str = os.getenv(key="DISCORD_WEBHOOK_URL", default="") INSTALLED_APPS: list[str] = [ "core.apps.CoreConfig", diff --git a/core/discord.py b/core/discord.py new file mode 100644 index 0000000..59e9529 --- /dev/null +++ b/core/discord.py @@ -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) diff --git a/core/templates/index.html b/core/templates/index.html index 15808b8..59a1bd2 100644 --- a/core/templates/index.html +++ b/core/templates/index.html @@ -131,7 +131,18 @@

{{ game.display_name }}

- +
+ {% csrf_token %} + + +
+
+ {% csrf_token %} + + +