Add ability to block domains

This commit is contained in:
rubenwardy
2023-01-03 12:17:01 +00:00
parent 13dcd373f2
commit 72b4029ed3
7 changed files with 141 additions and 104 deletions

View File

@@ -20,6 +20,7 @@ import secrets
from .flask import *
from .models import *
from .user import *
from flask import current_app
YESES = ["yes", "true", "1", "on"]
@@ -51,3 +52,19 @@ def shouldReturnJson():
def randomString(n):
return secrets.token_hex(int(n / 2))
def has_blocked_domains(text: str, username: str, location: str) -> bool:
if text is None:
return False
blocked_domains = current_app.config["BLOCKED_DOMAINS"]
for domain in blocked_domains:
if domain in text:
from app.tasks.webhooktasks import post_discord_webhook
post_discord_webhook.delay(username,
f"Attempted to post link to blocked domain {domain} in {location}",
True)
return True
return False