Skip to content

Commit a005109

Browse files
authored
Support new role colours in audit log
1 parent b1be7de commit a005109

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

discord/audit_logs.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
DefaultReaction as DefaultReactionPayload,
7070
)
7171
from .types.invite import Invite as InvitePayload
72-
from .types.role import Role as RolePayload
72+
from .types.role import Role as RolePayload, RoleColours
7373
from .types.snowflake import Snowflake
7474
from .types.command import ApplicationCommandPermissions
7575
from .types.automod import AutoModerationAction
@@ -407,6 +407,12 @@ def __init__(self, entry: AuditLogEntry, data: List[AuditLogChangePayload]):
407407
self._handle_trigger_attr_update(self.after, self.before, entry, trigger_attr, elem['new_value']) # type: ignore
408408
continue
409409

410+
# special case for colors to set secondary and tertiary colos/colour attributes
411+
if attr == 'colors':
412+
self._handle_colours(self.before, elem['old_value']) # type: ignore # should be a RoleColours dict
413+
self._handle_colours(self.after, elem['new_value']) # type: ignore # should be a RoleColours dict
414+
continue
415+
410416
try:
411417
key, transformer = self.TRANSFORMERS[attr]
412418
except (ValueError, KeyError):
@@ -539,6 +545,16 @@ def _handle_trigger_attr_update(
539545
except (AttributeError, TypeError):
540546
pass
541547

548+
def _handle_colours(self, diff: AuditLogDiff, colours: RoleColours):
549+
# handle colours to multiple colour attributes
550+
diff.color = diff.colour = Colour(colours['primary_color'])
551+
552+
secondary_colour = colours['secondary_color']
553+
tertiary_colour = colours['tertiary_color']
554+
555+
diff.secondary_color = diff.secondary_colour = Colour(secondary_colour) if secondary_colour is not None else None
556+
diff.tertiary_color = diff.tertiary_colour = Colour(tertiary_colour) if tertiary_colour is not None else None
557+
542558
def _create_trigger(self, diff: AuditLogDiff, entry: AuditLogEntry) -> AutoModTrigger:
543559
# check if trigger has already been created
544560
if not hasattr(diff, 'trigger'):

discord/types/audit_log.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from .user import User
3434
from .scheduled_event import EntityType, EventStatus, GuildScheduledEvent
3535
from .snowflake import Snowflake
36-
from .role import Role
36+
from .role import Role, RoleColours
3737
from .channel import ChannelType, DefaultReaction, PrivacyLevel, VideoQualityMode, PermissionOverwrite, ForumTag
3838
from .threads import Thread
3939
from .command import ApplicationCommand, ApplicationCommandPermissions
@@ -297,6 +297,12 @@ class _AuditLogChange_TriggerMetadata(TypedDict):
297297
old_value: Optional[AutoModerationTriggerMetadata]
298298

299299

300+
class _AuditLogChange_RoleColours(TypedDict):
301+
key: Literal['colors']
302+
new_value: RoleColours
303+
old_value: RoleColours
304+
305+
300306
AuditLogChange = Union[
301307
_AuditLogChange_Str,
302308
_AuditLogChange_AssetHash,
@@ -321,6 +327,7 @@ class _AuditLogChange_TriggerMetadata(TypedDict):
321327
_AuditLogChange_AvailableTags,
322328
_AuditLogChange_DefaultReactionEmoji,
323329
_AuditLogChange_TriggerMetadata,
330+
_AuditLogChange_RoleColours,
324331
]
325332

326333

docs/api.rst

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,25 +927,25 @@ Members
927927
.. function:: on_raw_presence_update(payload)
928928

929929
Called when a :class:`Member` updates their presence.
930-
930+
931931
This requires :attr:`Intents.presences` to be enabled.
932932

933-
Unlike :func:`on_presence_update`, when enabled, this is called regardless of the state of internal guild
933+
Unlike :func:`on_presence_update`, when enabled, this is called regardless of the state of internal guild
934934
and member caches, and **does not** provide a comparison between the previous and updated states of the :class:`Member`.
935935

936936
.. important::
937937

938-
By default, this event is only dispatched when :attr:`Intents.presences` is enabled **and** :attr:`Intents.members`
938+
By default, this event is only dispatched when :attr:`Intents.presences` is enabled **and** :attr:`Intents.members`
939939
is disabled.
940940

941941
You can manually override this behaviour by setting the **enable_raw_presences** flag in the :class:`Client`,
942942
however :attr:`Intents.presences` is always required for this event to work.
943-
943+
944944
.. versionadded:: 2.5
945945

946946
:param payload: The raw presence update event model.
947947
:type payload: :class:`RawPresenceUpdateEvent`
948-
948+
949949

950950
Messages
951951
~~~~~~~~~
@@ -2456,6 +2456,8 @@ of :class:`enum.Enum`.
24562456
Possible attributes for :class:`AuditLogDiff`:
24572457

24582458
- :attr:`~AuditLogDiff.colour`
2459+
- :attr:`~AuditLogDiff.secondary_colour`
2460+
- :attr:`~AuditLogDiff.tertiary_colour`
24592461
- :attr:`~AuditLogDiff.mentionable`
24602462
- :attr:`~AuditLogDiff.hoist`
24612463
- :attr:`~AuditLogDiff.icon`
@@ -2479,6 +2481,8 @@ of :class:`enum.Enum`.
24792481
Possible attributes for :class:`AuditLogDiff`:
24802482

24812483
- :attr:`~AuditLogDiff.colour`
2484+
- :attr:`~AuditLogDiff.secondary_colour`
2485+
- :attr:`~AuditLogDiff.tertiary_colour`
24822486
- :attr:`~AuditLogDiff.mentionable`
24832487
- :attr:`~AuditLogDiff.hoist`
24842488
- :attr:`~AuditLogDiff.icon`
@@ -2496,6 +2500,8 @@ of :class:`enum.Enum`.
24962500
Possible attributes for :class:`AuditLogDiff`:
24972501

24982502
- :attr:`~AuditLogDiff.colour`
2503+
- :attr:`~AuditLogDiff.secondary_colour`
2504+
- :attr:`~AuditLogDiff.tertiary_colour`
24992505
- :attr:`~AuditLogDiff.mentionable`
25002506
- :attr:`~AuditLogDiff.hoist`
25012507
- :attr:`~AuditLogDiff.name`
@@ -4210,6 +4216,24 @@ AuditLogDiff
42104216

42114217
:type: :class:`Colour`
42124218

4219+
.. attribute:: secondary_colour
4220+
secondary_color
4221+
4222+
The secondary colour of a role.
4223+
4224+
See also :attr:`Role.secondary_colour`
4225+
4226+
:type: Optional[:class:`Colour`]
4227+
4228+
.. attribute:: tertiary_colour
4229+
tertiary_color
4230+
4231+
The tertiary colour of a role.
4232+
4233+
See also :attr:`Role.tertiary_colour`
4234+
4235+
:type: Optional[:class:`Colour`]
4236+
42134237
.. attribute:: hoist
42144238

42154239
Whether the role is being hoisted or not.

0 commit comments

Comments
 (0)