mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-11 00:09:47 +00:00
Fix member_profile triggers not having attributes filled
This commit is contained in:
parent
7d159920e7
commit
933460c3d4
@ -33,7 +33,7 @@ from .invite import Invite
|
|||||||
from .mixins import Hashable
|
from .mixins import Hashable
|
||||||
from .object import Object
|
from .object import Object
|
||||||
from .permissions import PermissionOverwrite, Permissions
|
from .permissions import PermissionOverwrite, Permissions
|
||||||
from .automod import AutoModTrigger, AutoModRuleAction, AutoModPresets, AutoModRule
|
from .automod import AutoModTrigger, AutoModRuleAction, AutoModRule
|
||||||
from .role import Role
|
from .role import Role
|
||||||
from .emoji import Emoji
|
from .emoji import Emoji
|
||||||
from .partial_emoji import PartialEmoji
|
from .partial_emoji import PartialEmoji
|
||||||
@ -234,33 +234,24 @@ def _transform_automod_trigger_metadata(
|
|||||||
entry: AuditLogEntry, data: AutoModerationTriggerMetadata
|
entry: AuditLogEntry, data: AutoModerationTriggerMetadata
|
||||||
) -> Optional[AutoModTrigger]:
|
) -> Optional[AutoModTrigger]:
|
||||||
|
|
||||||
|
# Try to get trigger type from target.trigger or infer from keys in data
|
||||||
if isinstance(entry.target, AutoModRule):
|
if isinstance(entry.target, AutoModRule):
|
||||||
# Trigger type cannot be changed, so type should be the same before and after updates.
|
# Trigger type cannot be changed, so type should be the same before and after updates.
|
||||||
# Avoids checking which keys are in data to guess trigger type
|
# Avoids checking which keys are in data to guess trigger type
|
||||||
# or returning None if data is empty.
|
_type = entry.target.trigger.type.value
|
||||||
try:
|
elif not data:
|
||||||
return AutoModTrigger.from_data(type=entry.target.trigger.type.value, data=data)
|
_type = enums.AutoModRuleTriggerType.spam.value
|
||||||
except Exception:
|
elif 'presets' in data:
|
||||||
pass
|
_type = enums.AutoModRuleTriggerType.keyword_preset.value
|
||||||
|
elif 'keyword_filter' in data or 'regex_patterns' in data:
|
||||||
# Try to infer trigger type from available keys in data
|
_type = enums.AutoModRuleTriggerType.keyword.value
|
||||||
if 'presets' in data:
|
elif 'mention_total_limit' in data or 'mention_raid_protection_enabled' in data:
|
||||||
return AutoModTrigger(
|
_type = enums.AutoModRuleTriggerType.mention_spam.value
|
||||||
type=enums.AutoModRuleTriggerType.keyword_preset,
|
|
||||||
presets=AutoModPresets._from_value(data['presets']), # type: ignore
|
|
||||||
allow_list=data.get('allow_list'),
|
|
||||||
)
|
|
||||||
elif 'keyword_filter' in data:
|
|
||||||
return AutoModTrigger(
|
|
||||||
type=enums.AutoModRuleTriggerType.keyword,
|
|
||||||
keyword_filter=data['keyword_filter'], # type: ignore
|
|
||||||
allow_list=data.get('allow_list'),
|
|
||||||
regex_patterns=data.get('regex_patterns'),
|
|
||||||
)
|
|
||||||
elif 'mention_total_limit' in data:
|
|
||||||
return AutoModTrigger(type=enums.AutoModRuleTriggerType.mention_spam, mention_limit=data['mention_total_limit']) # type: ignore
|
|
||||||
else:
|
else:
|
||||||
return AutoModTrigger(type=enums.AutoModRuleTriggerType.spam)
|
# some unknown type
|
||||||
|
_type = -1
|
||||||
|
|
||||||
|
return AutoModTrigger.from_data(type=_type, data=data)
|
||||||
|
|
||||||
|
|
||||||
def _transform_automod_actions(entry: AuditLogEntry, data: List[AutoModerationAction]) -> List[AutoModRuleAction]:
|
def _transform_automod_actions(entry: AuditLogEntry, data: List[AutoModerationAction]) -> List[AutoModRuleAction]:
|
||||||
|
@ -213,8 +213,8 @@ class AutoModTrigger:
|
|||||||
type: :class:`AutoModRuleTriggerType`
|
type: :class:`AutoModRuleTriggerType`
|
||||||
The type of trigger.
|
The type of trigger.
|
||||||
keyword_filter: List[:class:`str`]
|
keyword_filter: List[:class:`str`]
|
||||||
The list of strings that will trigger the keyword filter. Maximum of 1000.
|
The list of strings that will trigger the filter.
|
||||||
Keywords can only be up to 60 characters in length.
|
Maximum of 1000. Keywords can only be up to 60 characters in length.
|
||||||
|
|
||||||
This could be combined with :attr:`regex_patterns`.
|
This could be combined with :attr:`regex_patterns`.
|
||||||
regex_patterns: List[:class:`str`]
|
regex_patterns: List[:class:`str`]
|
||||||
@ -260,8 +260,11 @@ class AutoModTrigger:
|
|||||||
regex_patterns: Optional[List[str]] = None,
|
regex_patterns: Optional[List[str]] = None,
|
||||||
mention_raid_protection: Optional[bool] = None,
|
mention_raid_protection: Optional[bool] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
if type is None and sum(arg is not None for arg in (keyword_filter or regex_patterns, presets, mention_limit)) > 1:
|
unique_args = (keyword_filter or regex_patterns, presets, mention_limit or mention_raid_protection)
|
||||||
raise ValueError('Please pass only one of keyword_filter, regex_patterns, presets, or mention_limit.')
|
if type is None and sum(arg is not None for arg in unique_args) > 1:
|
||||||
|
raise ValueError(
|
||||||
|
'Please pass only one of keyword_filter/regex_patterns, presets, or mention_limit/mention_raid_protection.'
|
||||||
|
)
|
||||||
|
|
||||||
if type is not None:
|
if type is not None:
|
||||||
self.type = type
|
self.type = type
|
||||||
@ -273,7 +276,7 @@ class AutoModTrigger:
|
|||||||
self.type = AutoModRuleTriggerType.mention_spam
|
self.type = AutoModRuleTriggerType.mention_spam
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Please pass the trigger type explicitly if not using keyword_filter, presets, or mention_limit.'
|
'Please pass the trigger type explicitly if not using keyword_filter, regex_patterns, presets, mention_limit, or mention_raid_protection.'
|
||||||
)
|
)
|
||||||
|
|
||||||
self.keyword_filter: List[str] = keyword_filter if keyword_filter is not None else []
|
self.keyword_filter: List[str] = keyword_filter if keyword_filter is not None else []
|
||||||
@ -296,7 +299,7 @@ class AutoModTrigger:
|
|||||||
type_ = try_enum(AutoModRuleTriggerType, type)
|
type_ = try_enum(AutoModRuleTriggerType, type)
|
||||||
if data is None:
|
if data is None:
|
||||||
return cls(type=type_)
|
return cls(type=type_)
|
||||||
elif type_ is AutoModRuleTriggerType.keyword:
|
elif type_ in (AutoModRuleTriggerType.keyword, AutoModRuleTriggerType.member_profile):
|
||||||
return cls(
|
return cls(
|
||||||
type=type_,
|
type=type_,
|
||||||
keyword_filter=data.get('keyword_filter'),
|
keyword_filter=data.get('keyword_filter'),
|
||||||
@ -317,7 +320,7 @@ class AutoModTrigger:
|
|||||||
return cls(type=type_)
|
return cls(type=type_)
|
||||||
|
|
||||||
def to_metadata_dict(self) -> Optional[Dict[str, Any]]:
|
def to_metadata_dict(self) -> Optional[Dict[str, Any]]:
|
||||||
if self.type is AutoModRuleTriggerType.keyword:
|
if self.type in (AutoModRuleTriggerType.keyword, AutoModRuleTriggerType.member_profile):
|
||||||
return {
|
return {
|
||||||
'keyword_filter': self.keyword_filter,
|
'keyword_filter': self.keyword_filter,
|
||||||
'regex_patterns': self.regex_patterns,
|
'regex_patterns': self.regex_patterns,
|
||||||
@ -355,6 +358,8 @@ class AutoModRule:
|
|||||||
The IDs of the roles that are exempt from the rule.
|
The IDs of the roles that are exempt from the rule.
|
||||||
exempt_channel_ids: Set[:class:`int`]
|
exempt_channel_ids: Set[:class:`int`]
|
||||||
The IDs of the channels that are exempt from the rule.
|
The IDs of the channels that are exempt from the rule.
|
||||||
|
event_type: :class:`AutoModRuleEventType`
|
||||||
|
The type of event that will trigger the the rule.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user