Implement AutoMod

This commit is contained in:
Alex Nørgaard
2022-06-27 05:47:52 +01:00
committed by GitHub
parent 7ad00750c6
commit 5426d19dc7
12 changed files with 1279 additions and 2 deletions

View File

@ -276,6 +276,7 @@ class AuditLogChanges:
'preferred_locale': (None, _enum_transformer(enums.Locale)),
'image_hash': ('cover_image', _transform_cover_image),
'app_command_permission_update': ('app_command_permissions', _transform_app_command_permissions),
'trigger_type': (None, _enum_transformer(enums.AutoModRuleTriggerType)),
}
# fmt: on
@ -394,6 +395,12 @@ class _AuditLogProxyMessageBulkDelete(_AuditLogProxy):
count: int
class _AuditLogProxyAutoModAction(_AuditLogProxy):
automod_rule_name: str
automod_rule_trigger_type: str
channel: Union[abc.GuildChannel, Thread]
class AuditLogEntry(Hashable):
r"""Represents an Audit Log entry.
@ -469,6 +476,7 @@ class AuditLogEntry(Hashable):
_AuditLogProxyPinAction,
_AuditLogProxyStageInstanceAction,
_AuditLogProxyMessageBulkDelete,
_AuditLogProxyAutoModAction,
Member, User, None, PartialIntegration,
Role, Object
] = None
@ -500,6 +508,16 @@ class AuditLogEntry(Hashable):
channel=self.guild.get_channel_or_thread(channel_id) or Object(id=channel_id),
message_id=int(extra['message_id']),
)
elif self.action is enums.AuditLogAction.automod_block_message:
channel_id = int(extra['channel_id'])
self.extra = _AuditLogProxyAutoModAction(
automod_rule_name=extra['auto_moderation_rule_name'],
automod_rule_trigger_type=enums.try_enum(
enums.AutoModRuleTriggerType, extra['auto_moderation_rule_trigger_type']
),
channel=self.guild.get_channel_or_thread(channel_id) or Object(id=channel_id),
)
elif self.action.name.startswith('overwrite_'):
# the overwrite_ actions have a dict with some information
instance_id = int(extra['id'])
@ -660,3 +678,6 @@ class AuditLogEntry(Hashable):
def _convert_target_integration_or_app_command(self, target_id: int) -> Union[PartialIntegration, AppCommand, Object]:
return self._get_integration_by_app_id(target_id) or self._get_app_command(target_id) or Object(target_id)
def _convert_target_auto_moderation(self, target_id: int) -> Union[Member, Object]:
return self.guild.get_member(target_id) or Object(target_id)