Skip to content

Commit

Permalink
feat: implement new automod features (#1372)
Browse files Browse the repository at this point in the history
* feat: add missing enums

* feat: implement new rules and triggers

* style: remove redundant ellipsis 

Signed-off-by: LordOfPolls <ddavidallen13@gmail.com>

---------

Signed-off-by: LordOfPolls <ddavidallen13@gmail.com>
  • Loading branch information
LordOfPolls authored May 2, 2023
1 parent edab1b4 commit 70f5110
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
24 changes: 22 additions & 2 deletions interactions/models/discord/auto_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ class HarmfulLinkFilter(BaseTrigger):
repr=True,
metadata=docs("The type of trigger"),
)
...


@attrs.define(eq=False, order=False, hash=False, kw_only=True)
Expand Down Expand Up @@ -151,12 +150,24 @@ class MentionSpamTrigger(BaseTrigger):
)


@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class MemberProfileTrigger(BaseTrigger):
regex_patterns: list[str] = attrs.field(
factory=list, repr=True, metadata=docs("The regex patterns to check against")
)
keyword_filter: str | list[str] = attrs.field(
factory=list, repr=True, metadata=docs("The keywords to check against")
)
allow_list: list["Snowflake_Type"] = attrs.field(
factory=list, repr=True, metadata=docs("The roles exempt from this rule")
)


@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class BlockMessage(BaseAction):
"""blocks the content of a message according to the rule"""

type: AutoModAction = attrs.field(repr=False, default=AutoModAction.BLOCK_MESSAGE, converter=AutoModAction)
...


@attrs.define(eq=False, order=False, hash=False, kw_only=True)
Expand All @@ -175,6 +186,13 @@ class TimeoutUser(BaseAction):
type: AutoModAction = attrs.field(repr=False, default=AutoModAction.TIMEOUT_USER, converter=AutoModAction)


@attrs.define(eq=False, order=False, hash=False, kw_only=False)
class BlockMemberInteraction(BaseAction):
"""Block a member from using text, voice, or other interactions"""

# this action has no metadata


@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class AutoModRule(DiscordObject):
"""A representation of an auto mod rule"""
Expand Down Expand Up @@ -345,11 +363,13 @@ def member(self) -> "Optional[Member]":
AutoModAction.BLOCK_MESSAGE: BlockMessage,
AutoModAction.ALERT_MESSAGE: AlertMessage,
AutoModAction.TIMEOUT_USER: TimeoutUser,
AutoModAction.BLOCK_MEMBER_INTERACTION: BlockMemberInteraction,
}

TRIGGER_MAPPING = {
AutoModTriggerType.KEYWORD: KeywordTrigger,
AutoModTriggerType.HARMFUL_LINK: HarmfulLinkFilter,
AutoModTriggerType.KEYWORD_PRESET: KeywordPresetTrigger,
AutoModTriggerType.MENTION_SPAM: MentionSpamTrigger,
AutoModTriggerType.MEMBER_PROFILE: MemberProfileTrigger,
}
3 changes: 3 additions & 0 deletions interactions/models/discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,16 +974,19 @@ class AutoModTriggerType(CursedIntEnum):
SPAM = 3
KEYWORD_PRESET = 4
MENTION_SPAM = 5
MEMBER_PROFILE = 6


class AutoModAction(CursedIntEnum):
BLOCK_MESSAGE = 1
ALERT_MESSAGE = 2
TIMEOUT_USER = 3
BLOCK_MEMBER_INTERACTION = 4


class AutoModEvent(CursedIntEnum):
MESSAGE_SEND = 1
MEMBER_UPDATE = 2


class AutoModLanuguageType(Enum):
Expand Down

0 comments on commit 70f5110

Please sign in to comment.