mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-22 16:51:59 +00:00
Use Asset for AuditLogChanges and add more entries
This commit is contained in:
parent
368fda7272
commit
1765cdffb1
@ -31,6 +31,7 @@ from .permissions import PermissionOverwrite, Permissions
|
||||
from .colour import Colour
|
||||
from .invite import Invite
|
||||
from .mixins import Hashable
|
||||
from .asset import Asset
|
||||
|
||||
__all__ = (
|
||||
'AuditLogDiff',
|
||||
@ -50,36 +51,45 @@ if TYPE_CHECKING:
|
||||
def _transform_verification_level(entry, data):
|
||||
return enums.try_enum(enums.VerificationLevel, data)
|
||||
|
||||
|
||||
def _transform_default_notifications(entry, data):
|
||||
return enums.try_enum(enums.NotificationLevel, data)
|
||||
|
||||
|
||||
def _transform_explicit_content_filter(entry, data):
|
||||
return enums.try_enum(enums.ContentFilter, data)
|
||||
|
||||
|
||||
def _transform_permissions(entry, data):
|
||||
return Permissions(int(data))
|
||||
|
||||
|
||||
def _transform_color(entry, data):
|
||||
return Colour(data)
|
||||
|
||||
|
||||
def _transform_snowflake(entry, data):
|
||||
return int(data)
|
||||
|
||||
|
||||
def _transform_channel(entry, data):
|
||||
if data is None:
|
||||
return None
|
||||
return entry.guild.get_channel(int(data)) or Object(id=data)
|
||||
|
||||
|
||||
def _transform_owner_id(entry, data):
|
||||
if data is None:
|
||||
return None
|
||||
return entry._get_member(int(data))
|
||||
|
||||
|
||||
def _transform_inviter_id(entry, data):
|
||||
if data is None:
|
||||
return None
|
||||
return entry._get_member(int(data))
|
||||
|
||||
|
||||
def _transform_overwrites(entry, data):
|
||||
overwrites = []
|
||||
for elem in data:
|
||||
@ -102,12 +112,40 @@ def _transform_overwrites(entry, data):
|
||||
|
||||
return overwrites
|
||||
|
||||
|
||||
def _transform_channeltype(entry, data):
|
||||
return enums.try_enum(enums.ChannelType, data)
|
||||
|
||||
|
||||
def _transform_voiceregion(entry, data):
|
||||
return enums.try_enum(enums.VoiceRegion, data)
|
||||
|
||||
|
||||
def _transform_video_quality_mode(entry, data):
|
||||
return enums.try_enum(enums.VideoQualityMode, data)
|
||||
|
||||
|
||||
def _transform_icon(entry, data):
|
||||
if data is None:
|
||||
return None
|
||||
return Asset._from_guild_icon(entry._state, entry.guild.id, data)
|
||||
|
||||
|
||||
def _transform_avatar(entry, data):
|
||||
if data is None:
|
||||
return None
|
||||
return Asset._from_avatar(entry._state, entry._target_id, data)
|
||||
|
||||
|
||||
def _guild_hash_transformer(path):
|
||||
def _transform(entry, data):
|
||||
if data is None:
|
||||
return None
|
||||
return Asset._from_guild_image(entry._state, entry.guild.id, data, path=path)
|
||||
|
||||
return _transform
|
||||
|
||||
|
||||
class AuditLogDiff:
|
||||
def __len__(self):
|
||||
return len(self.__dict__)
|
||||
@ -119,7 +157,9 @@ class AuditLogDiff:
|
||||
values = ' '.join('%s=%r' % item for item in self.__dict__.items())
|
||||
return f'<AuditLogDiff {values}>'
|
||||
|
||||
|
||||
class AuditLogChanges:
|
||||
# fmt: off
|
||||
TRANSFORMERS = {
|
||||
'verification_level': (None, _transform_verification_level),
|
||||
'explicit_content_filter': (None, _transform_explicit_content_filter),
|
||||
@ -135,15 +175,19 @@ class AuditLogChanges:
|
||||
'system_channel_id': ('system_channel', _transform_channel),
|
||||
'widget_channel_id': ('widget_channel', _transform_channel),
|
||||
'permission_overwrites': ('overwrites', _transform_overwrites),
|
||||
'splash_hash': ('splash', None),
|
||||
'icon_hash': ('icon', None),
|
||||
'avatar_hash': ('avatar', None),
|
||||
'splash_hash': ('splash', _guild_hash_transformer('splashes')),
|
||||
'banner_hash': ('banner', _guild_hash_transformer('banners')),
|
||||
'discovery_splash_hash': ('discovery_splash', _guild_hash_transformer('discovery-splashes')),
|
||||
'icon_hash': ('icon', _transform_icon),
|
||||
'avatar_hash': ('avatar', _transform_avatar),
|
||||
'rate_limit_per_user': ('slowmode_delay', None),
|
||||
'default_message_notifications': ('default_notifications', _transform_default_notifications),
|
||||
'region': (None, _transform_voiceregion),
|
||||
'rtc_region': (None, _transform_voiceregion),
|
||||
'video_quality_mode': (None, _transform_video_quality_mode),
|
||||
'type': (None, _transform_channeltype),
|
||||
}
|
||||
# fmt: on
|
||||
|
||||
def __init__(self, entry, data: List[AuditLogChangePayload]):
|
||||
self.before = AuditLogDiff()
|
||||
@ -190,6 +234,9 @@ class AuditLogChanges:
|
||||
if hasattr(self.after, 'colour'):
|
||||
self.after.color = self.after.colour
|
||||
self.before.color = self.before.colour
|
||||
if hasattr(self.after, 'expire_behavior'):
|
||||
self.after.expire_behaviour = self.after.expire_behavior
|
||||
self.before.expire_behaviour = self.before.expire_behavior
|
||||
|
||||
def __repr__(self):
|
||||
return f'<AuditLogChanges before={self.before!r} after={self.after!r}>'
|
||||
@ -207,12 +254,13 @@ class AuditLogChanges:
|
||||
|
||||
if role is None:
|
||||
role = Object(id=role_id)
|
||||
role.name = e['name'] # type: ignore
|
||||
role.name = e['name'] # type: ignore
|
||||
|
||||
data.append(role)
|
||||
|
||||
setattr(second, 'roles', data)
|
||||
|
||||
|
||||
class AuditLogEntry(Hashable):
|
||||
r"""Represents an Audit Log entry.
|
||||
|
||||
@ -278,7 +326,7 @@ class AuditLogEntry(Hashable):
|
||||
channel_id = int(self.extra['channel_id'])
|
||||
elems = {
|
||||
'count': int(self.extra['count']),
|
||||
'channel': self.guild.get_channel(channel_id) or Object(id=channel_id)
|
||||
'channel': self.guild.get_channel(channel_id) or Object(id=channel_id),
|
||||
}
|
||||
self.extra = type('_AuditLogProxy', (), elems)()
|
||||
elif self.action is enums.AuditLogAction.member_disconnect:
|
||||
@ -291,10 +339,12 @@ class AuditLogEntry(Hashable):
|
||||
# the pin actions have a dict with some information
|
||||
channel_id = int(self.extra['channel_id'])
|
||||
message_id = int(self.extra['message_id'])
|
||||
# fmt: off
|
||||
elems = {
|
||||
'channel': self.guild.get_channel(channel_id) or Object(id=channel_id),
|
||||
'message_id': message_id
|
||||
}
|
||||
# fmt: on
|
||||
self.extra = type('_AuditLogProxy', (), elems)()
|
||||
elif self.action.name.startswith('overwrite_'):
|
||||
# the overwrite_ actions have a dict with some information
|
||||
|
30
docs/api.rst
30
docs/api.rst
@ -1347,7 +1347,7 @@ of :class:`enum.Enum`.
|
||||
- Changing the guild invite splash
|
||||
- Changing the guild AFK channel or timeout
|
||||
- Changing the guild voice server region
|
||||
- Changing the guild icon
|
||||
- Changing the guild icon, banner, or discovery splash
|
||||
- Changing the guild moderation settings
|
||||
- Changing things related to the guild widget
|
||||
|
||||
@ -1365,6 +1365,9 @@ of :class:`enum.Enum`.
|
||||
- :attr:`~AuditLogDiff.name`
|
||||
- :attr:`~AuditLogDiff.owner`
|
||||
- :attr:`~AuditLogDiff.splash`
|
||||
- :attr:`~AuditLogDiff.discovery_splash`
|
||||
- :attr:`~AuditLogDiff.icon`
|
||||
- :attr:`~AuditLogDiff.banner`
|
||||
- :attr:`~AuditLogDiff.vanity_url_code`
|
||||
|
||||
.. attribute:: channel_create
|
||||
@ -1696,6 +1699,7 @@ of :class:`enum.Enum`.
|
||||
|
||||
- :attr:`~AuditLogDiff.channel`
|
||||
- :attr:`~AuditLogDiff.name`
|
||||
- :attr:`~AuditLogDiff.avatar`
|
||||
|
||||
.. attribute:: webhook_delete
|
||||
|
||||
@ -2198,15 +2202,27 @@ AuditLogDiff
|
||||
|
||||
.. attribute:: icon
|
||||
|
||||
A guild's icon hash. See also :attr:`Guild.icon`.
|
||||
A guild's icon. See also :attr:`Guild.icon`.
|
||||
|
||||
:type: :class:`str`
|
||||
:type: :class:`Asset`
|
||||
|
||||
.. attribute:: splash
|
||||
|
||||
The guild's invite splash hash. See also :attr:`Guild.splash`.
|
||||
The guild's invite splash. See also :attr:`Guild.splash`.
|
||||
|
||||
:type: :class:`str`
|
||||
:type: :class:`Asset`
|
||||
|
||||
.. attribute:: discovery_splash
|
||||
|
||||
The guild's discovery splash. See also :attr:`Guild.discovery_splash`.
|
||||
|
||||
:type: :class:`Asset`
|
||||
|
||||
.. attribute:: banner
|
||||
|
||||
The guild's banner. See also :attr:`Guild.banner`.
|
||||
|
||||
:type: :class:`Asset`
|
||||
|
||||
.. attribute:: owner
|
||||
|
||||
@ -2492,11 +2508,11 @@ AuditLogDiff
|
||||
|
||||
.. attribute:: avatar
|
||||
|
||||
The avatar hash of a member.
|
||||
The avatar of a member.
|
||||
|
||||
See also :attr:`User.avatar`.
|
||||
|
||||
:type: :class:`str`
|
||||
:type: :class:`Asset`
|
||||
|
||||
.. attribute:: slowmode_delay
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user