Add audit log events for threads
This commit is contained in:
parent
1472e9ed7c
commit
154c90ef59
@ -49,12 +49,16 @@ if TYPE_CHECKING:
|
||||
from .guild import Guild
|
||||
from .member import Member
|
||||
from .role import Role
|
||||
from .types.audit_log import AuditLogChange as AuditLogChangePayload
|
||||
from .types.audit_log import AuditLogEntry as AuditLogEntryPayload
|
||||
from .types.audit_log import (
|
||||
AuditLogChange as AuditLogChangePayload,
|
||||
AuditLogEntry as AuditLogEntryPayload,
|
||||
)
|
||||
from .types.channel import PermissionOverwrite as PermissionOverwritePayload
|
||||
from .types.role import Role as RolePayload
|
||||
from .types.snowflake import Snowflake
|
||||
from .user import User
|
||||
from .stage_instance import StageInstance
|
||||
from .threads import Thread
|
||||
|
||||
|
||||
def _transform_permissions(entry: AuditLogEntry, data: str) -> Permissions:
|
||||
@ -69,7 +73,7 @@ def _transform_snowflake(entry: AuditLogEntry, data: Snowflake) -> int:
|
||||
return int(data)
|
||||
|
||||
|
||||
def _transform_channel(entry: AuditLogEntry, data: Optional[Snowflake]) -> Optional[Object]:
|
||||
def _transform_channel(entry: AuditLogEntry, data: Optional[Snowflake]) -> Optional[Union[abc.GuildChannel, Object]]:
|
||||
if data is None:
|
||||
return None
|
||||
return entry.guild.get_channel(int(data)) or Object(id=data)
|
||||
@ -434,7 +438,7 @@ class AuditLogEntry(Hashable):
|
||||
return utils.snowflake_time(self.id)
|
||||
|
||||
@utils.cached_property
|
||||
def target(self) -> Union[Guild, abc.GuildChannel, Member, User, Role, Invite, Emoji, Object, None]:
|
||||
def target(self) -> Union[Guild, abc.GuildChannel, Member, User, Role, Invite, Emoji, Object, Thread, None]:
|
||||
try:
|
||||
converter = getattr(self, '_convert_target_' + self.action.target_type)
|
||||
except AttributeError:
|
||||
@ -501,3 +505,9 @@ class AuditLogEntry(Hashable):
|
||||
|
||||
def _convert_target_message(self, target_id: int) -> Union[Member, User, None]:
|
||||
return self._get_member(target_id)
|
||||
|
||||
def _convert_target_stage_instance(self, target_id: int) -> Union[StageInstance, Object]:
|
||||
return self.guild.get_stage_instance(target_id) or Object(id=target_id)
|
||||
|
||||
def _convert_target_thread(self, target_id: int) -> Union[Thread, Object]:
|
||||
return self.guild.get_thread(target_id) or Object(id=target_id)
|
||||
|
@ -346,6 +346,9 @@ class AuditLogAction(Enum):
|
||||
stage_instance_create = 83
|
||||
stage_instance_update = 84
|
||||
stage_instance_delete = 85
|
||||
thread_create = 110
|
||||
thread_update = 111
|
||||
thread_delete = 112
|
||||
# fmt: on
|
||||
|
||||
@property
|
||||
@ -390,6 +393,9 @@ class AuditLogAction(Enum):
|
||||
AuditLogAction.stage_instance_create: AuditLogActionCategory.create,
|
||||
AuditLogAction.stage_instance_update: AuditLogActionCategory.update,
|
||||
AuditLogAction.stage_instance_delete: AuditLogActionCategory.delete,
|
||||
AuditLogAction.thread_create: AuditLogActionCategory.create,
|
||||
AuditLogAction.thread_update: AuditLogActionCategory.update,
|
||||
AuditLogAction.thread_delete: AuditLogActionCategory.delete,
|
||||
}
|
||||
# fmt: on
|
||||
return lookup[self]
|
||||
@ -421,6 +427,8 @@ class AuditLogAction(Enum):
|
||||
return 'integration'
|
||||
elif v < 90:
|
||||
return 'stage_instance'
|
||||
elif v < 113:
|
||||
return 'thread'
|
||||
|
||||
|
||||
class UserFlags(Enum):
|
||||
|
@ -32,6 +32,7 @@ from .user import User
|
||||
from .snowflake import Snowflake
|
||||
from .role import Role
|
||||
from .channel import ChannelType, VideoQualityMode, PermissionOverwrite
|
||||
from .threads import Thread
|
||||
|
||||
AuditLogEvent = Literal[
|
||||
1,
|
||||
@ -69,6 +70,12 @@ AuditLogEvent = Literal[
|
||||
80,
|
||||
81,
|
||||
82,
|
||||
83,
|
||||
84,
|
||||
85,
|
||||
110,
|
||||
111,
|
||||
112,
|
||||
]
|
||||
|
||||
|
||||
@ -116,6 +123,8 @@ class _AuditLogChange_Bool(TypedDict):
|
||||
'enabled_emoticons',
|
||||
'region',
|
||||
'rtc_region',
|
||||
'archived',
|
||||
'locked',
|
||||
]
|
||||
new_value: bool
|
||||
old_value: bool
|
||||
@ -132,6 +141,8 @@ class _AuditLogChange_Int(TypedDict):
|
||||
'max_uses',
|
||||
'max_age',
|
||||
'user_limit',
|
||||
'auto_archive_duration',
|
||||
'default_auto_archive_duration',
|
||||
]
|
||||
new_value: int
|
||||
old_value: int
|
||||
@ -238,3 +249,4 @@ class AuditLog(TypedDict):
|
||||
users: List[User]
|
||||
audit_log_entries: List[AuditLogEntry]
|
||||
integrations: List[PartialIntegration]
|
||||
threads: List[Thread]
|
||||
|
@ -115,7 +115,7 @@ class _ThreadChannelOptional(TypedDict, total=False):
|
||||
|
||||
|
||||
class ThreadChannel(_BaseChannel, _ThreadChannelOptional):
|
||||
type: Literal[11, 12]
|
||||
type: Literal[10, 11, 12]
|
||||
guild_id: Snowflake
|
||||
parent_id: Snowflake
|
||||
owner_id: Snowflake
|
||||
|
86
docs/api.rst
86
docs/api.rst
@ -1745,6 +1745,7 @@ of :class:`enum.Enum`.
|
||||
- :attr:`~AuditLogDiff.bitrate`
|
||||
- :attr:`~AuditLogDiff.rtc_region`
|
||||
- :attr:`~AuditLogDiff.video_quality_mode`
|
||||
- :attr:`~AuditLogDiff.default_auto_archive_duration`
|
||||
|
||||
.. attribute:: channel_delete
|
||||
|
||||
@ -2173,8 +2174,8 @@ of :class:`enum.Enum`.
|
||||
A stage instance was started.
|
||||
|
||||
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||
either :class:`Object` with the stage instance ID of the stage instance
|
||||
which was created.
|
||||
the :class:`StageInstance` or :class:`Object` with the ID of the stage
|
||||
instance which was created.
|
||||
|
||||
Possible attributes for :class:`AuditLogDiff`:
|
||||
|
||||
@ -2188,8 +2189,8 @@ of :class:`enum.Enum`.
|
||||
A stage instance was updated.
|
||||
|
||||
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||
either :class:`Object` with the stage instance ID of the stage instance
|
||||
which was updated.
|
||||
the :class:`StageInstance` or :class:`Object` with the ID of the stage
|
||||
instance which was updated.
|
||||
|
||||
Possible attributes for :class:`AuditLogDiff`:
|
||||
|
||||
@ -2204,6 +2205,57 @@ of :class:`enum.Enum`.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
.. attribute:: thread_create
|
||||
|
||||
A thread was created.
|
||||
|
||||
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||
the :class:`Thread` or :class:`Object` with the ID of the thread which
|
||||
was created.
|
||||
|
||||
Possible attributes for :class:`AuditLogDiff`:
|
||||
|
||||
- :attr:`~AuditLogDiff.name`
|
||||
- :attr:`~AuditLogDiff.archived`
|
||||
- :attr:`~AuditLogDiff.locked`
|
||||
- :attr:`~AuditLogDiff.auto_archive_duration`
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
.. attribute:: thread_update
|
||||
|
||||
A thread was updated.
|
||||
|
||||
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||
the :class:`Thread` or :class:`Object` with the ID of the thread which
|
||||
was updated.
|
||||
|
||||
Possible attributes for :class:`AuditLogDiff`:
|
||||
|
||||
- :attr:`~AuditLogDiff.name`
|
||||
- :attr:`~AuditLogDiff.archived`
|
||||
- :attr:`~AuditLogDiff.locked`
|
||||
- :attr:`~AuditLogDiff.auto_archive_duration`
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
.. attribute:: thread_delete
|
||||
|
||||
A thread was deleted.
|
||||
|
||||
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||
the :class:`Thread` or :class:`Object` with the ID of the thread which
|
||||
was deleted.
|
||||
|
||||
Possible attributes for :class:`AuditLogDiff`:
|
||||
|
||||
- :attr:`~AuditLogDiff.name`
|
||||
- :attr:`~AuditLogDiff.archived`
|
||||
- :attr:`~AuditLogDiff.locked`
|
||||
- :attr:`~AuditLogDiff.auto_archive_duration`
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
.. class:: AuditLogActionCategory
|
||||
|
||||
Represents the category that the :class:`AuditLogAction` belongs to.
|
||||
@ -2988,6 +3040,32 @@ AuditLogDiff
|
||||
|
||||
:type: :class:`VideoQualityMode`
|
||||
|
||||
.. attribute:: archived
|
||||
|
||||
The thread is now archived.
|
||||
|
||||
:type: :class:`bool`
|
||||
|
||||
.. attribute:: locked
|
||||
|
||||
The thread is being locked or unlocked.
|
||||
|
||||
:type: :class:`bool`
|
||||
|
||||
.. attribute:: auto_archive_duration
|
||||
|
||||
The thread's auto archive duration being changed.
|
||||
|
||||
See also :attr:`Thread.auto_archive_duration`
|
||||
|
||||
:type: :class:`int`
|
||||
|
||||
.. attribute:: default_auto_archive_duration
|
||||
|
||||
The default auto archive duration for newly created threads being changed.
|
||||
|
||||
:type: :class:`int`
|
||||
|
||||
.. this is currently missing the following keys: reason and application_id
|
||||
I'm not sure how to about porting these
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user