mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-16 02:39:01 +00:00
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 .guild import Guild
|
||||||
from .member import Member
|
from .member import Member
|
||||||
from .role import Role
|
from .role import Role
|
||||||
from .types.audit_log import AuditLogChange as AuditLogChangePayload
|
from .types.audit_log import (
|
||||||
from .types.audit_log import AuditLogEntry as AuditLogEntryPayload
|
AuditLogChange as AuditLogChangePayload,
|
||||||
|
AuditLogEntry as AuditLogEntryPayload,
|
||||||
|
)
|
||||||
from .types.channel import PermissionOverwrite as PermissionOverwritePayload
|
from .types.channel import PermissionOverwrite as PermissionOverwritePayload
|
||||||
from .types.role import Role as RolePayload
|
from .types.role import Role as RolePayload
|
||||||
from .types.snowflake import Snowflake
|
from .types.snowflake import Snowflake
|
||||||
from .user import User
|
from .user import User
|
||||||
|
from .stage_instance import StageInstance
|
||||||
|
from .threads import Thread
|
||||||
|
|
||||||
|
|
||||||
def _transform_permissions(entry: AuditLogEntry, data: str) -> Permissions:
|
def _transform_permissions(entry: AuditLogEntry, data: str) -> Permissions:
|
||||||
@ -69,7 +73,7 @@ def _transform_snowflake(entry: AuditLogEntry, data: Snowflake) -> int:
|
|||||||
return int(data)
|
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:
|
if data is None:
|
||||||
return None
|
return None
|
||||||
return entry.guild.get_channel(int(data)) or Object(id=data)
|
return entry.guild.get_channel(int(data)) or Object(id=data)
|
||||||
@ -434,7 +438,7 @@ class AuditLogEntry(Hashable):
|
|||||||
return utils.snowflake_time(self.id)
|
return utils.snowflake_time(self.id)
|
||||||
|
|
||||||
@utils.cached_property
|
@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:
|
try:
|
||||||
converter = getattr(self, '_convert_target_' + self.action.target_type)
|
converter = getattr(self, '_convert_target_' + self.action.target_type)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@ -501,3 +505,9 @@ class AuditLogEntry(Hashable):
|
|||||||
|
|
||||||
def _convert_target_message(self, target_id: int) -> Union[Member, User, None]:
|
def _convert_target_message(self, target_id: int) -> Union[Member, User, None]:
|
||||||
return self._get_member(target_id)
|
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_create = 83
|
||||||
stage_instance_update = 84
|
stage_instance_update = 84
|
||||||
stage_instance_delete = 85
|
stage_instance_delete = 85
|
||||||
|
thread_create = 110
|
||||||
|
thread_update = 111
|
||||||
|
thread_delete = 112
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -390,6 +393,9 @@ class AuditLogAction(Enum):
|
|||||||
AuditLogAction.stage_instance_create: AuditLogActionCategory.create,
|
AuditLogAction.stage_instance_create: AuditLogActionCategory.create,
|
||||||
AuditLogAction.stage_instance_update: AuditLogActionCategory.update,
|
AuditLogAction.stage_instance_update: AuditLogActionCategory.update,
|
||||||
AuditLogAction.stage_instance_delete: AuditLogActionCategory.delete,
|
AuditLogAction.stage_instance_delete: AuditLogActionCategory.delete,
|
||||||
|
AuditLogAction.thread_create: AuditLogActionCategory.create,
|
||||||
|
AuditLogAction.thread_update: AuditLogActionCategory.update,
|
||||||
|
AuditLogAction.thread_delete: AuditLogActionCategory.delete,
|
||||||
}
|
}
|
||||||
# fmt: on
|
# fmt: on
|
||||||
return lookup[self]
|
return lookup[self]
|
||||||
@ -421,6 +427,8 @@ class AuditLogAction(Enum):
|
|||||||
return 'integration'
|
return 'integration'
|
||||||
elif v < 90:
|
elif v < 90:
|
||||||
return 'stage_instance'
|
return 'stage_instance'
|
||||||
|
elif v < 113:
|
||||||
|
return 'thread'
|
||||||
|
|
||||||
|
|
||||||
class UserFlags(Enum):
|
class UserFlags(Enum):
|
||||||
|
@ -32,6 +32,7 @@ from .user import User
|
|||||||
from .snowflake import Snowflake
|
from .snowflake import Snowflake
|
||||||
from .role import Role
|
from .role import Role
|
||||||
from .channel import ChannelType, VideoQualityMode, PermissionOverwrite
|
from .channel import ChannelType, VideoQualityMode, PermissionOverwrite
|
||||||
|
from .threads import Thread
|
||||||
|
|
||||||
AuditLogEvent = Literal[
|
AuditLogEvent = Literal[
|
||||||
1,
|
1,
|
||||||
@ -69,6 +70,12 @@ AuditLogEvent = Literal[
|
|||||||
80,
|
80,
|
||||||
81,
|
81,
|
||||||
82,
|
82,
|
||||||
|
83,
|
||||||
|
84,
|
||||||
|
85,
|
||||||
|
110,
|
||||||
|
111,
|
||||||
|
112,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -116,6 +123,8 @@ class _AuditLogChange_Bool(TypedDict):
|
|||||||
'enabled_emoticons',
|
'enabled_emoticons',
|
||||||
'region',
|
'region',
|
||||||
'rtc_region',
|
'rtc_region',
|
||||||
|
'archived',
|
||||||
|
'locked',
|
||||||
]
|
]
|
||||||
new_value: bool
|
new_value: bool
|
||||||
old_value: bool
|
old_value: bool
|
||||||
@ -132,6 +141,8 @@ class _AuditLogChange_Int(TypedDict):
|
|||||||
'max_uses',
|
'max_uses',
|
||||||
'max_age',
|
'max_age',
|
||||||
'user_limit',
|
'user_limit',
|
||||||
|
'auto_archive_duration',
|
||||||
|
'default_auto_archive_duration',
|
||||||
]
|
]
|
||||||
new_value: int
|
new_value: int
|
||||||
old_value: int
|
old_value: int
|
||||||
@ -238,3 +249,4 @@ class AuditLog(TypedDict):
|
|||||||
users: List[User]
|
users: List[User]
|
||||||
audit_log_entries: List[AuditLogEntry]
|
audit_log_entries: List[AuditLogEntry]
|
||||||
integrations: List[PartialIntegration]
|
integrations: List[PartialIntegration]
|
||||||
|
threads: List[Thread]
|
||||||
|
@ -115,7 +115,7 @@ class _ThreadChannelOptional(TypedDict, total=False):
|
|||||||
|
|
||||||
|
|
||||||
class ThreadChannel(_BaseChannel, _ThreadChannelOptional):
|
class ThreadChannel(_BaseChannel, _ThreadChannelOptional):
|
||||||
type: Literal[11, 12]
|
type: Literal[10, 11, 12]
|
||||||
guild_id: Snowflake
|
guild_id: Snowflake
|
||||||
parent_id: Snowflake
|
parent_id: Snowflake
|
||||||
owner_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.bitrate`
|
||||||
- :attr:`~AuditLogDiff.rtc_region`
|
- :attr:`~AuditLogDiff.rtc_region`
|
||||||
- :attr:`~AuditLogDiff.video_quality_mode`
|
- :attr:`~AuditLogDiff.video_quality_mode`
|
||||||
|
- :attr:`~AuditLogDiff.default_auto_archive_duration`
|
||||||
|
|
||||||
.. attribute:: channel_delete
|
.. attribute:: channel_delete
|
||||||
|
|
||||||
@ -2173,8 +2174,8 @@ of :class:`enum.Enum`.
|
|||||||
A stage instance was started.
|
A stage instance was started.
|
||||||
|
|
||||||
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||||
either :class:`Object` with the stage instance ID of the stage instance
|
the :class:`StageInstance` or :class:`Object` with the ID of the stage
|
||||||
which was created.
|
instance which was created.
|
||||||
|
|
||||||
Possible attributes for :class:`AuditLogDiff`:
|
Possible attributes for :class:`AuditLogDiff`:
|
||||||
|
|
||||||
@ -2188,8 +2189,8 @@ of :class:`enum.Enum`.
|
|||||||
A stage instance was updated.
|
A stage instance was updated.
|
||||||
|
|
||||||
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
When this is the action, the type of :attr:`~AuditLogEntry.target` is
|
||||||
either :class:`Object` with the stage instance ID of the stage instance
|
the :class:`StageInstance` or :class:`Object` with the ID of the stage
|
||||||
which was updated.
|
instance which was updated.
|
||||||
|
|
||||||
Possible attributes for :class:`AuditLogDiff`:
|
Possible attributes for :class:`AuditLogDiff`:
|
||||||
|
|
||||||
@ -2204,6 +2205,57 @@ of :class:`enum.Enum`.
|
|||||||
|
|
||||||
.. versionadded:: 2.0
|
.. 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
|
.. class:: AuditLogActionCategory
|
||||||
|
|
||||||
Represents the category that the :class:`AuditLogAction` belongs to.
|
Represents the category that the :class:`AuditLogAction` belongs to.
|
||||||
@ -2988,6 +3040,32 @@ AuditLogDiff
|
|||||||
|
|
||||||
:type: :class:`VideoQualityMode`
|
: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
|
.. this is currently missing the following keys: reason and application_id
|
||||||
I'm not sure how to about porting these
|
I'm not sure how to about porting these
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user