aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/models/bot
diff options
context:
space:
mode:
authorGravatar D0rs4n <[email protected]>2022-03-12 16:48:54 +0100
committerGravatar D0rs4n <[email protected]>2022-03-12 16:48:54 +0100
commitc7300a92c885b01a5663913fa73679fc680bfb74 (patch)
treeb4a93b362188d79b6a4c52e3591ccc69ca87b752 /pydis_site/apps/api/models/bot
parentRemove role validation (diff)
Sync Filter models with relating migrations, adjust code consistency
Diffstat (limited to 'pydis_site/apps/api/models/bot')
-rw-r--r--pydis_site/apps/api/models/bot/filters.py57
1 files changed, 38 insertions, 19 deletions
diff --git a/pydis_site/apps/api/models/bot/filters.py b/pydis_site/apps/api/models/bot/filters.py
index 13b332d2..f8bbfd14 100644
--- a/pydis_site/apps/api/models/bot/filters.py
+++ b/pydis_site/apps/api/models/bot/filters.py
@@ -1,7 +1,4 @@
-from typing import List
-
from django.contrib.postgres.fields import ArrayField, JSONField
-from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import UniqueConstraint
@@ -37,7 +34,8 @@ class FilterSettingsMixin(models.Model):
)
infraction_reason = models.CharField(
max_length=1000,
- help_text="The reason to give for the infraction."
+ help_text="The reason to give for the infraction.",
+ null=True
)
infraction_duration = models.DurationField(
null=True,
@@ -59,13 +57,13 @@ class FilterList(FilterSettingsMixin):
help_text="Whether this list is an allowlist or denylist"
)
guild_pings = ArrayField(
- models.CharField(max_length=20),
+ models.CharField(max_length=100),
help_text="Who to ping when this filter triggers.",
null=False
)
filter_dm = models.BooleanField(help_text="Whether DMs should be filtered.", null=False)
dm_pings = ArrayField(
- models.CharField(max_length=20),
+ models.CharField(max_length=100),
help_text="Who to ping when this filter triggers on a DM.",
null=False
)
@@ -83,9 +81,7 @@ class FilterList(FilterSettingsMixin):
null=False
)
send_alert = models.BooleanField(
- help_text="Whether alert should be sent.",
- null=False,
- default=True
+ help_text="Whether an alert should be sent.",
)
# Where a filter should apply.
#
@@ -93,9 +89,18 @@ class FilterList(FilterSettingsMixin):
# - enabled_channels
# - disabled_categories
# - disabled_channels
- enabled_channels = ArrayField(models.IntegerField())
- disabled_channels = ArrayField(models.IntegerField())
- disabled_categories = ArrayField(models.IntegerField())
+ enabled_channels = ArrayField(
+ models.CharField(max_length=100),
+ help_text="Channels in which to run the filter even if it's disabled in the category."
+ )
+ disabled_channels = ArrayField(
+ models.CharField(max_length=100),
+ help_text="Channels in which to not run the filter."
+ )
+ disabled_categories = ArrayField(
+ models.CharField(max_length=100),
+ help_text="Categories in which to not run the filter."
+ )
class Meta:
"""Constrain name and list_type unique."""
@@ -112,20 +117,23 @@ class Filter(FilterSettingsMixin):
"""One specific trigger of a list."""
content = models.CharField(max_length=100, help_text="The definition of this filter.")
- description = models.CharField(max_length=200, help_text="Why this filter has been added.")
+ description = models.CharField(
+ max_length=200,
+ help_text="Why this filter has been added.", null=True
+ )
additional_field = JSONField(null=True, help_text="Implementation specific field.")
filter_list = models.ForeignKey(
FilterList, models.CASCADE, related_name="filters",
help_text="The filter list containing this filter."
)
guild_pings = ArrayField(
- models.CharField(max_length=20),
+ models.CharField(max_length=100),
help_text="Who to ping when this filter triggers.",
null=True
)
filter_dm = models.BooleanField(help_text="Whether DMs should be filtered.", null=True)
dm_pings = ArrayField(
- models.CharField(max_length=20),
+ models.CharField(max_length=100),
help_text="Who to ping when this filter triggers on a DM.",
null=True
)
@@ -143,14 +151,25 @@ class Filter(FilterSettingsMixin):
null=True
)
send_alert = models.BooleanField(
- help_text="Whether alert should be sent.",
+ help_text="Whether an alert should be sent.",
null=True
)
# Check FilterList model for information about these properties.
- enabled_channels = ArrayField(models.IntegerField(), null=True)
- disabled_channels = ArrayField(models.IntegerField(), null=True)
- disabled_categories = ArrayField(models.IntegerField(), null=True)
+ enabled_channels = ArrayField(
+ models.CharField(max_length=100),
+ help_text="Channels in which to run the filter even if it's disabled in the category.",
+ null=True
+ )
+ disabled_channels = ArrayField(
+ models.CharField(max_length=100),
+ help_text="Channels in which to not run the filter.", null=True
+ )
+ disabled_categories = ArrayField(
+ models.CharField(max_length=100),
+ help_text="Categories in which to not run the filter.",
+ null=True
+ )
def __str__(self) -> str:
return f"Filter {self.content!r}"