Browse Source

Support new colors in audit log

pull/10225/head
ec 7 days ago
parent
commit
33487eef11
  1. 18
      discord/audit_logs.py
  2. 9
      discord/types/audit_log.py

18
discord/audit_logs.py

@ -69,7 +69,7 @@ if TYPE_CHECKING:
DefaultReaction as DefaultReactionPayload, DefaultReaction as DefaultReactionPayload,
) )
from .types.invite import Invite as InvitePayload 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.snowflake import Snowflake
from .types.command import ApplicationCommandPermissions from .types.command import ApplicationCommandPermissions
from .types.automod import AutoModerationAction 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 self._handle_trigger_attr_update(self.after, self.before, entry, trigger_attr, elem['new_value']) # type: ignore
continue 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: try:
key, transformer = self.TRANSFORMERS[attr] key, transformer = self.TRANSFORMERS[attr]
except (ValueError, KeyError): except (ValueError, KeyError):
@ -539,6 +545,16 @@ class AuditLogChanges:
except (AttributeError, TypeError): except (AttributeError, TypeError):
pass 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: def _create_trigger(self, diff: AuditLogDiff, entry: AuditLogEntry) -> AutoModTrigger:
# check if trigger has already been created # check if trigger has already been created
if not hasattr(diff, 'trigger'): if not hasattr(diff, 'trigger'):

9
discord/types/audit_log.py

@ -33,7 +33,7 @@ from .integration import IntegrationExpireBehavior, PartialIntegration
from .user import User from .user import User
from .scheduled_event import EntityType, EventStatus, GuildScheduledEvent from .scheduled_event import EntityType, EventStatus, GuildScheduledEvent
from .snowflake import Snowflake from .snowflake import Snowflake
from .role import Role from .role import Role, RoleColours
from .channel import ChannelType, DefaultReaction, PrivacyLevel, VideoQualityMode, PermissionOverwrite, ForumTag from .channel import ChannelType, DefaultReaction, PrivacyLevel, VideoQualityMode, PermissionOverwrite, ForumTag
from .threads import Thread from .threads import Thread
from .command import ApplicationCommand, ApplicationCommandPermissions from .command import ApplicationCommand, ApplicationCommandPermissions
@ -297,6 +297,12 @@ class _AuditLogChange_TriggerMetadata(TypedDict):
old_value: Optional[AutoModerationTriggerMetadata] old_value: Optional[AutoModerationTriggerMetadata]
class _AuditLogChange_RoleColors(TypedDict):
key: Literal['colors']
new_value: RoleColours
old_value: RoleColours
AuditLogChange = Union[ AuditLogChange = Union[
_AuditLogChange_Str, _AuditLogChange_Str,
_AuditLogChange_AssetHash, _AuditLogChange_AssetHash,
@ -321,6 +327,7 @@ AuditLogChange = Union[
_AuditLogChange_AvailableTags, _AuditLogChange_AvailableTags,
_AuditLogChange_DefaultReactionEmoji, _AuditLogChange_DefaultReactionEmoji,
_AuditLogChange_TriggerMetadata, _AuditLogChange_TriggerMetadata,
_AuditLogChange_RoleColors,
] ]

Loading…
Cancel
Save