Support new role colours in audit log

This commit is contained in:
z03h
2025-07-09 13:56:38 -04:00
committed by GitHub
parent b1be7dea74
commit a00510988a
3 changed files with 54 additions and 7 deletions

View File

@ -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_colours(self.before, elem['old_value']) # type: ignore # should be a RoleColours dict
self._handle_colours(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_colours(self, diff: AuditLogDiff, colours: RoleColours):
# handle colours to multiple colour attributes
diff.color = diff.colour = Colour(colours['primary_color'])
secondary_colour = colours['secondary_color']
tertiary_colour = colours['tertiary_color']
diff.secondary_color = diff.secondary_colour = Colour(secondary_colour) if secondary_colour is not None else None
diff.tertiary_color = diff.tertiary_colour = Colour(tertiary_colour) if tertiary_colour 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'):