-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[back][infra] refactor: add
write_on_discord
command (#979)
Co-authored-by: Adrien Matissart <a@matissart.net> Co-authored-by: Gresille&Siffle <39056254+GresilleSiffle@users.noreply.github.com>
- Loading branch information
1 parent
b17d558
commit 9f88d2f
Showing
31 changed files
with
123 additions
and
122 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import logging | ||
|
||
import requests | ||
from django.conf import settings | ||
|
||
|
||
def write_in_channel(discord_channel, message) -> bool: | ||
"""Write a message in a Discord channel.""" | ||
webhook_url = settings.DISCORD_CHANNEL_WEBHOOKS.get(discord_channel, "") | ||
|
||
if not webhook_url: | ||
logging.warning("Cannot write in discord channel %s", discord_channel) | ||
logging.warning("Cause: empty webhook URL.") | ||
return False | ||
|
||
resp = requests.post(webhook_url, json={"content": message}) | ||
resp.raise_for_status() | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
Send a message to a configured Discord channel. | ||
The web hook of the target channel must be configured in the settings. | ||
""" | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from core.lib.discord.api import write_in_channel | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Send a message to a configured Discord channel." | ||
|
||
def add_arguments(self, parser): | ||
|
||
parser.add_argument( | ||
"-c", | ||
"--channel", | ||
type=str, | ||
help="Name of the target channel.", | ||
) | ||
|
||
parser.add_argument( | ||
"-m", | ||
"--message", | ||
type=str, | ||
help="Message to send.", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
self.stdout.write(f"start command: {__name__}") | ||
discord_channel = options["channel"] | ||
|
||
# display the configuration if more verbosity is asked | ||
if options.get("verbosity", 1) > 1: | ||
self.stdout.write(f"Discord channel: {discord_channel}") | ||
|
||
write_in_channel(discord_channel, options["message"]) | ||
|
||
self.stdout.write(self.style.SUCCESS(f"Message posted on {discord_channel}")) | ||
self.stdout.write("end") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
infra/ansible/roles/backups/templates/discord-export-backups-fail-alert.sh.j2
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
infra/ansible/roles/django/templates/discord-ml-fail-alert.sh.j2
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
infra/ansible/roles/django/templates/discord-tournesolapi-cleartokens-fail-alert.sh.j2
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
.../ansible/roles/django/templates/discord-tournesolapi-deleteinactiveusers-fail-alert.sh.j2
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
infra/ansible/roles/django/templates/discord-twitterbot-fail-alert.sh.j2
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
cd /srv/tournesol-backend && SETTINGS_FILE=/etc/tournesol/settings.yaml ./venv/bin/python manage.py send_on_discord "$@" | ||
echo "alert sent" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
infra/ansible/roles/monitoring/templates/discord_alerting_webhook.j2
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.