|
|
|
@ -4,7 +4,7 @@ from django.db.models.signals import post_save |
|
|
|
from django.dispatch import receiver |
|
|
|
from django.dispatch import receiver |
|
|
|
from django.conf import settings |
|
|
|
from django.conf import settings |
|
|
|
|
|
|
|
|
|
|
|
from .models import Club, FailedApiCall, CustomUser |
|
|
|
from .models import Club, FailedApiCall, CustomUser, Log |
|
|
|
import requests |
|
|
|
import requests |
|
|
|
|
|
|
|
|
|
|
|
def generate_unique_code(): |
|
|
|
def generate_unique_code(): |
|
|
|
@ -20,23 +20,28 @@ def assign_unique_code(sender, instance, created, **kwargs): |
|
|
|
instance.broadcast_code = generate_unique_code() |
|
|
|
instance.broadcast_code = generate_unique_code() |
|
|
|
instance.save() |
|
|
|
instance.save() |
|
|
|
|
|
|
|
|
|
|
|
DISCORD_WEBHOOK_URL = 'https://discord.com/api/webhooks/1248191778134163486/sSoTL6cULCElWr2YFwyllsg7IXxHcCx_YMDJA_cUHtVUU4WOfN-5M7drCJuwNBBfAk9a' |
|
|
|
DISCORD_FAILED_CALLS_WEBHOOK_URL = 'https://discord.com/api/webhooks/1248191778134163486/sSoTL6cULCElWr2YFwyllsg7IXxHcCx_YMDJA_cUHtVUU4WOfN-5M7drCJuwNBBfAk9a' |
|
|
|
|
|
|
|
DISCORD_LOGS_WEBHOOK_URL = 'https://discord.com/api/webhooks/1257987637449588736/TtOUwzYgSlQH2d3Ps7SfIKRcFALQVa3hfkC-j9K4_UAcWtsfiw4v8NUPbnX2_ZPOYzuv' |
|
|
|
|
|
|
|
|
|
|
|
@receiver(post_save, sender=FailedApiCall) |
|
|
|
@receiver(post_save, sender=FailedApiCall) |
|
|
|
def notify_discord_on_create(sender, instance, created, **kwargs): |
|
|
|
def notify_discord_on_create(sender, instance, created, **kwargs): |
|
|
|
notify_object_creation_on_discord(created, instance) |
|
|
|
notify_object_creation_on_discord(created, instance, DISCORD_FAILED_CALLS_WEBHOOK_URL) |
|
|
|
|
|
|
|
|
|
|
|
@receiver(post_save, sender=CustomUser) |
|
|
|
@receiver(post_save, sender=CustomUser) |
|
|
|
def notify_user_creation_on_discord(sender, instance, created, **kwargs): |
|
|
|
def notify_user_creation_on_discord(sender, instance, created, **kwargs): |
|
|
|
notify_object_creation_on_discord(created, instance) |
|
|
|
notify_object_creation_on_discord(created, instance, DISCORD_LOGS_WEBHOOK_URL) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@receiver(post_save, sender=Log) |
|
|
|
|
|
|
|
def notify_log_creation_on_discord(sender, instance, created, **kwargs): |
|
|
|
|
|
|
|
notify_object_creation_on_discord(created, instance, DISCORD_LOGS_WEBHOOK_URL) |
|
|
|
|
|
|
|
|
|
|
|
# WARNING: using this method requires the instance to have a discord_string method |
|
|
|
# WARNING: using this method requires the instance to have a discord_string method |
|
|
|
def notify_object_creation_on_discord(created, instance): |
|
|
|
def notify_object_creation_on_discord(created, instance, webhook_url): |
|
|
|
if created: |
|
|
|
if created: |
|
|
|
default_db_engine = settings.DATABASES['default']['ENGINE'] |
|
|
|
default_db_engine = settings.DATABASES['default']['ENGINE'] |
|
|
|
if default_db_engine != 'django.db.backends.sqlite3': |
|
|
|
if default_db_engine != 'django.db.backends.sqlite3': |
|
|
|
message = f'New {instance.__class__.__name__} created: {instance.discord_string()}' |
|
|
|
message = f'New {instance.__class__.__name__} created: {instance.discord_string()}' |
|
|
|
send_discord_message(DISCORD_WEBHOOK_URL, message) |
|
|
|
send_discord_message(webhook_url, message) |
|
|
|
|
|
|
|
|
|
|
|
def send_discord_message(webhook_url, content): |
|
|
|
def send_discord_message(webhook_url, content): |
|
|
|
data = { |
|
|
|
data = { |
|
|
|
|