mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-05 17:41:53 +00:00
Add custom_message to automod block_message aciton
This commit is contained in:
parent
517d7ae4fe
commit
90d50bef1f
@ -27,7 +27,6 @@ import datetime
|
|||||||
|
|
||||||
from typing import TYPE_CHECKING, Any, Dict, Optional, List, Sequence, Set, Union, Sequence
|
from typing import TYPE_CHECKING, Any, Dict, Optional, List, Sequence, Set, Union, Sequence
|
||||||
|
|
||||||
|
|
||||||
from .enums import AutoModRuleTriggerType, AutoModRuleActionType, AutoModRuleEventType, try_enum
|
from .enums import AutoModRuleTriggerType, AutoModRuleActionType, AutoModRuleEventType, try_enum
|
||||||
from .flags import AutoModPresets
|
from .flags import AutoModPresets
|
||||||
from . import utils
|
from . import utils
|
||||||
@ -73,15 +72,28 @@ class AutoModRuleAction:
|
|||||||
The duration of the timeout to apply, if any.
|
The duration of the timeout to apply, if any.
|
||||||
Has a maximum of 28 days.
|
Has a maximum of 28 days.
|
||||||
Passing this sets :attr:`type` to :attr:`~AutoModRuleActionType.timeout`.
|
Passing this sets :attr:`type` to :attr:`~AutoModRuleActionType.timeout`.
|
||||||
|
custom_message: Optional[:class:`str`]
|
||||||
|
A custom message which will be shown to a user when their message is blocked.
|
||||||
|
Passing this sets :attr:`type` to :attr:`~AutoModRuleActionType.block_message`.
|
||||||
|
|
||||||
|
.. versionadded:: 2.2
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ('type', 'channel_id', 'duration')
|
__slots__ = ('type', 'channel_id', 'duration', 'custom_message')
|
||||||
|
|
||||||
def __init__(self, *, channel_id: Optional[int] = None, duration: Optional[datetime.timedelta] = None) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
channel_id: Optional[int] = None,
|
||||||
|
duration: Optional[datetime.timedelta] = None,
|
||||||
|
custom_message: Optional[str] = None,
|
||||||
|
) -> None:
|
||||||
self.channel_id: Optional[int] = channel_id
|
self.channel_id: Optional[int] = channel_id
|
||||||
self.duration: Optional[datetime.timedelta] = duration
|
self.duration: Optional[datetime.timedelta] = duration
|
||||||
if channel_id and duration:
|
self.custom_message: Optional[str] = custom_message
|
||||||
raise ValueError('Please provide only one of ``channel`` or ``duration``')
|
|
||||||
|
if sum(v is None for v in (channel_id, duration, custom_message)) < 2:
|
||||||
|
raise ValueError('Only one of channel_id, duration, or custom_message can be passed.')
|
||||||
|
|
||||||
if channel_id:
|
if channel_id:
|
||||||
self.type = AutoModRuleActionType.send_alert_message
|
self.type = AutoModRuleActionType.send_alert_message
|
||||||
@ -102,11 +114,13 @@ class AutoModRuleAction:
|
|||||||
elif data['type'] == AutoModRuleActionType.send_alert_message.value:
|
elif data['type'] == AutoModRuleActionType.send_alert_message.value:
|
||||||
channel_id = int(data['metadata']['channel_id'])
|
channel_id = int(data['metadata']['channel_id'])
|
||||||
return cls(channel_id=channel_id)
|
return cls(channel_id=channel_id)
|
||||||
return cls()
|
return cls(custom_message=data.get('metadata', {}).get('custom_message'))
|
||||||
|
|
||||||
def to_dict(self) -> Dict[str, Any]:
|
def to_dict(self) -> Dict[str, Any]:
|
||||||
ret = {'type': self.type.value, 'metadata': {}}
|
ret = {'type': self.type.value, 'metadata': {}}
|
||||||
if self.type is AutoModRuleActionType.timeout:
|
if self.type is AutoModRuleActionType.block_message and self.custom_message is not None:
|
||||||
|
ret['metadata'] = {'custom_message': self.custom_message}
|
||||||
|
elif self.type is AutoModRuleActionType.timeout:
|
||||||
ret['metadata'] = {'duration_seconds': int(self.duration.total_seconds())} # type: ignore # duration cannot be None here
|
ret['metadata'] = {'duration_seconds': int(self.duration.total_seconds())} # type: ignore # duration cannot be None here
|
||||||
elif self.type is AutoModRuleActionType.send_alert_message:
|
elif self.type is AutoModRuleActionType.send_alert_message:
|
||||||
ret['metadata'] = {'channel_id': str(self.channel_id)}
|
ret['metadata'] = {'channel_id': str(self.channel_id)}
|
||||||
|
@ -45,9 +45,13 @@ class _AutoModerationActionMetadataTimeout(TypedDict):
|
|||||||
duration_seconds: int
|
duration_seconds: int
|
||||||
|
|
||||||
|
|
||||||
|
class _AutoModerationActionMetadataCustomMessage(TypedDict):
|
||||||
|
custom_message: str
|
||||||
|
|
||||||
|
|
||||||
class _AutoModerationActionBlockMessage(TypedDict):
|
class _AutoModerationActionBlockMessage(TypedDict):
|
||||||
type: Literal[1]
|
type: Literal[1]
|
||||||
metadata: NotRequired[Empty]
|
metadata: NotRequired[_AutoModerationActionMetadataCustomMessage]
|
||||||
|
|
||||||
|
|
||||||
class _AutoModerationActionAlert(TypedDict):
|
class _AutoModerationActionAlert(TypedDict):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user