From 33487eef1104fa8c2fb5bd64d2df1e47809432de Mon Sep 17 00:00:00 2001 From: ec Date: Tue, 8 Jul 2025 18:56:19 -0700 Subject: [PATCH] Support new colors in audit log --- discord/audit_logs.py | 18 +++++++++++++++++- discord/types/audit_log.py | 9 ++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/discord/audit_logs.py b/discord/audit_logs.py index 89577769f..f162845b8 100644 --- a/discord/audit_logs.py +++ b/discord/audit_logs.py @@ -69,7 +69,7 @@ if TYPE_CHECKING: DefaultReaction as DefaultReactionPayload, ) from .types.invite import Invite as InvitePayload - from .types.role import Role as RolePayload + from .types.role import Role as RolePayload, RoleColours from .types.snowflake import Snowflake from .types.command import ApplicationCommandPermissions from .types.automod import AutoModerationAction @@ -407,6 +407,12 @@ class AuditLogChanges: self._handle_trigger_attr_update(self.after, self.before, entry, trigger_attr, elem['new_value']) # type: ignore continue + # special case for colors to set secondary and tertiary colos/colour attributes + if attr == 'colors': + self._handle_colors(self.before, elem['old_value']) #type: ignore # should be a RoleColours dict + self._handle_colors(self.after, elem['new_value']) #type: ignore # should be a RoleColours dict + continue + try: key, transformer = self.TRANSFORMERS[attr] except (ValueError, KeyError): @@ -539,6 +545,16 @@ class AuditLogChanges: except (AttributeError, TypeError): pass + def _handle_colors(self, diff: AuditLogDiff, colors: RoleColours): + # handle colors to multiple color attributes + diff.color = diff.colour = Colour(colors['primary_color']) + + secondary_color = colors['secondary_color'] + tertiary_color = colors['tertiary_color'] + + diff.secondary_color = diff.secondary_colour = Colour(secondary_color) if secondary_color is not None else None + diff.tertiary_color = diff.tertiary_colour = Colour(tertiary_color) if tertiary_color is not None else None + def _create_trigger(self, diff: AuditLogDiff, entry: AuditLogEntry) -> AutoModTrigger: # check if trigger has already been created if not hasattr(diff, 'trigger'): diff --git a/discord/types/audit_log.py b/discord/types/audit_log.py index 2c37542fd..905ad4c7e 100644 --- a/discord/types/audit_log.py +++ b/discord/types/audit_log.py @@ -33,7 +33,7 @@ from .integration import IntegrationExpireBehavior, PartialIntegration from .user import User from .scheduled_event import EntityType, EventStatus, GuildScheduledEvent from .snowflake import Snowflake -from .role import Role +from .role import Role, RoleColours from .channel import ChannelType, DefaultReaction, PrivacyLevel, VideoQualityMode, PermissionOverwrite, ForumTag from .threads import Thread from .command import ApplicationCommand, ApplicationCommandPermissions @@ -297,6 +297,12 @@ class _AuditLogChange_TriggerMetadata(TypedDict): old_value: Optional[AutoModerationTriggerMetadata] +class _AuditLogChange_RoleColors(TypedDict): + key: Literal['colors'] + new_value: RoleColours + old_value: RoleColours + + AuditLogChange = Union[ _AuditLogChange_Str, _AuditLogChange_AssetHash, @@ -321,6 +327,7 @@ AuditLogChange = Union[ _AuditLogChange_AvailableTags, _AuditLogChange_DefaultReactionEmoji, _AuditLogChange_TriggerMetadata, + _AuditLogChange_RoleColors, ]