Browse Source

Add Onboarding audit log data

pull/9260/head
Josh 2 years ago
parent
commit
e8019f9d4c
  1. 19
      discord/audit_logs.py
  2. 12
      discord/enums.py
  3. 29
      discord/types/audit_log.py
  4. 102
      docs/api.rst

19
discord/audit_logs.py

@ -44,6 +44,7 @@ from .sticker import GuildSticker
from .threads import Thread
from .integrations import PartialIntegration
from .channel import ForumChannel, StageChannel, ForumTag
from .onboarding import OnboardingPrompt, OnboardingPromptOption
__all__ = (
'AuditLogDiff',
@ -72,6 +73,7 @@ if TYPE_CHECKING:
from .types.snowflake import Snowflake
from .types.command import ApplicationCommandPermissions
from .types.automod import AutoModerationTriggerMetadata, AutoModerationAction
from .types.onboarding import Prompt as PromptPayload, PromptOption as PromptOptionPayload
from .user import User
from .app_commands import AppCommand
@ -263,6 +265,16 @@ def _transform_automod_actions(entry: AuditLogEntry, data: List[AutoModerationAc
return [AutoModRuleAction.from_data(action) for action in data]
def _transform_onboarding_prompts(entry: AuditLogEntry, data: List[PromptPayload]) -> List[OnboardingPrompt]:
return [OnboardingPrompt(data=prompt, state=entry._state, guild=entry.guild) for prompt in data]
def _transform_onboarding_prompt_options(
entry: AuditLogEntry, data: List[PromptOptionPayload]
) -> List[OnboardingPromptOption]:
return [OnboardingPromptOption(data=option, state=entry._state, guild=entry.guild) for option in data]
E = TypeVar('E', bound=enums.Enum)
@ -285,13 +297,15 @@ def _flag_transformer(cls: Type[F]) -> Callable[[AuditLogEntry, Union[int, str]]
def _transform_type(
entry: AuditLogEntry, data: Union[int, str]
) -> Union[enums.ChannelType, enums.StickerType, enums.WebhookType, str]:
) -> Union[enums.ChannelType, enums.StickerType, enums.WebhookType, str, enums.OnboardingPromptType]:
if entry.action.name.startswith('sticker_'):
return enums.try_enum(enums.StickerType, data)
elif entry.action.name.startswith('integration_'):
return data # type: ignore # integration type is str
elif entry.action.name.startswith('webhook_'):
return enums.try_enum(enums.WebhookType, data)
elif entry.action.name.startswith('onboarding_question_'):
return enums.try_enum(enums.OnboardingPromptType, data)
else:
return enums.try_enum(enums.ChannelType, data)
@ -370,6 +384,9 @@ class AuditLogChanges:
'available_tags': (None, _transform_forum_tags),
'flags': (None, _transform_overloaded_flags),
'default_reaction_emoji': (None, _transform_default_reaction),
'options': (None, _transform_onboarding_prompt_options),
'prompts': (None, _transform_onboarding_prompts),
'default_channel_ids': ('default_channels', _transform_channels_or_threads),
}
# fmt: on

12
discord/enums.py

@ -368,6 +368,11 @@ class AuditLogAction(Enum):
automod_block_message = 143
automod_flag_message = 144
automod_timeout_member = 145
onboarding_question_create = 163
onboarding_question_update = 164
onboarding_update = 167
server_guide_create = 190
server_guide_update = 191
# fmt: on
@property
@ -428,6 +433,9 @@ class AuditLogAction(Enum):
AuditLogAction.automod_block_message: None,
AuditLogAction.automod_flag_message: None,
AuditLogAction.automod_timeout_member: None,
AuditLogAction.onboarding_question_create: AuditLogActionCategory.create,
AuditLogAction.onboarding_question_update: AuditLogActionCategory.update,
AuditLogAction.onboarding_update: AuditLogActionCategory.update,
}
# fmt: on
return lookup[self]
@ -471,6 +479,10 @@ class AuditLogAction(Enum):
return 'auto_moderation'
elif v < 146:
return 'user'
elif v < 165:
return 'onboarding_question'
elif v < 168:
return 'onboarding'
class UserFlags(Enum):

29
discord/types/audit_log.py

@ -37,6 +37,7 @@ from .role import Role
from .channel import ChannelType, DefaultReaction, PrivacyLevel, VideoQualityMode, PermissionOverwrite, ForumTag
from .threads import Thread
from .command import ApplicationCommand, ApplicationCommandPermissions
from .onboarding import PromptOption, Prompt
AuditLogEvent = Literal[
1,
@ -93,6 +94,9 @@ AuditLogEvent = Literal[
143,
144,
145,
163,
164,
167,
]
@ -109,6 +113,7 @@ class _AuditLogChange_Str(TypedDict):
'permissions',
'tags',
'unicode_emoji',
'title',
]
new_value: str
old_value: str
@ -154,6 +159,10 @@ class _AuditLogChange_Bool(TypedDict):
'available',
'archived',
'locked',
'enabled',
'single_select',
'required',
'in_onboarding',
]
new_value: bool
old_value: bool
@ -258,8 +267,8 @@ class _AuditLogChange_AppCommandPermissions(TypedDict):
old_value: ApplicationCommandPermissions
class _AuditLogChange_AppliedTags(TypedDict):
key: Literal['applied_tags']
class _AuditLogChange_SnowflakeList(TypedDict):
key: Literal['applied_tags', 'default_channel_ids']
new_value: List[Snowflake]
old_value: List[Snowflake]
@ -276,6 +285,18 @@ class _AuditLogChange_DefaultReactionEmoji(TypedDict):
old_value: Optional[DefaultReaction]
class _AuditLogChange_Prompts(TypedDict):
key: Literal['prompts']
new_value: List[Prompt]
old_value: List[Prompt]
class _AuditLogChange_Options(TypedDict):
key: Literal['options']
new_value: List[PromptOption]
old_value: List[PromptOption]
AuditLogChange = Union[
_AuditLogChange_Str,
_AuditLogChange_AssetHash,
@ -295,9 +316,11 @@ AuditLogChange = Union[
_AuditLogChange_Status,
_AuditLogChange_EntityType,
_AuditLogChange_AppCommandPermissions,
_AuditLogChange_AppliedTags,
_AuditLogChange_SnowflakeList,
_AuditLogChange_AvailableTags,
_AuditLogChange_DefaultReactionEmoji,
_AuditLogChange_Prompts,
_AuditLogChange_Options,
]

102
docs/api.rst

@ -2798,6 +2798,46 @@ of :class:`enum.Enum`.
.. versionadded:: 2.1
.. attribute:: onboarding_question_create
A guild onboarding prompt was created.
Possible attributes for :class:`AuditLogDiff`:
- :attr:`~AuditLogDiff.type`
- :attr:`~AuditLogDiff.title`
- :attr:`~AuditLogDiff.options`
- :attr:`~AuditLogDiff.single_select`
- :attr:`~AuditLogDiff.required`
- :attr:`~AuditLogDiff.in_onboarding`
.. versionadded:: 2.3
.. attribute:: onboarding_question_update
A guild onboarding prompt was updated.
Possible attributes for :class:`AuditLogDiff`:
- :attr:`~AuditLogDiff.type`
- :attr:`~AuditLogDiff.title`
- :attr:`~AuditLogDiff.options`
- :attr:`~AuditLogDiff.single_select`
- :attr:`~AuditLogDiff.required`
- :attr:`~AuditLogDiff.in_onboarding`
.. versionadded:: 2.3
.. attribute:: onboarding_update
The guild's onboarding configuration was updated.
Possible attributes for :class:`AuditLogDiff`:
- :attr:`~AuditLogDiff.enabled`
- :attr:`~AuditLogDiff.default_channels`
- :attr:`~AuditLogDiff.prompts`
.. class:: AuditLogActionCategory
Represents the category that the :class:`AuditLogAction` belongs to.
@ -3580,9 +3620,9 @@ AuditLogDiff
.. attribute:: type
The type of channel, sticker, webhook or integration.
The type of channel, sticker, webhook, integration or onboarding prompt.
:type: Union[:class:`ChannelType`, :class:`StickerType`, :class:`WebhookType`, :class:`str`]
:type: Union[:class:`ChannelType`, :class:`StickerType`, :class:`WebhookType`, :class:`str`, :class:`OnboardingPromptType`]
.. attribute:: topic
@ -3935,7 +3975,7 @@ AuditLogDiff
.. attribute:: enabled
Whether the automod rule is active or not.
Whether guild onboarding or the automod rule is active or not.
:type: :class:`bool`
@ -4011,6 +4051,62 @@ AuditLogDiff
:type: :class:`ChannelFlags`
.. attribute:: options
The onboarding prompt options associated with this onboarding prompt.
See also :attr:`OnboardingPrompt.options`
:type: List[:class:`OnboardingPromptOption`]
.. attribute:: default_channels
The default channels associated with the onboarding in this guild.
See also :attr:`Onboarding.default_channels`
:type: List[:class:`abc.GuildChannel`, :class:`Object`]
.. attribute:: prompts
The onboarding prompts associated with the onboarding in this guild.
See also :attr:`Onboarding.prompts`
:type: List[:class:`OnboardingPrompt`]
.. attribute:: title
The title of the onboarding prompt.
See also :attr:`OnboardingPrompt.title`
:type: :class:`str`
.. attribute:: single_select
Whether only one prompt option can be selected.
See also :attr:`OnboardingPrompt.single_select`
:type: :class:`bool`
.. attribute:: required
Whether the onboarding prompt is required to complete the onboarding.
See also :attr:`OnboardingPrompt.required`
:type: :class:`bool`
.. attribute:: in_onboarding
Whether this prompt is currently part of the onboarding flow.
See also :attr:`OnboardingUser.in_onboarding`
:type: :class:`bool`
.. this is currently missing the following keys: reason and application_id
I'm not sure how to port these

Loading…
Cancel
Save