Browse Source

Support new role colours in audit log

master
z03h 4 days ago
committed by GitHub
parent
commit
a00510988a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      discord/audit_logs.py
  2. 9
      discord/types/audit_log.py
  3. 24
      docs/api.rst

18
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_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'):

9
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_RoleColours(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_RoleColours,
]

24
docs/api.rst

@ -2456,6 +2456,8 @@ of :class:`enum.Enum`.
Possible attributes for :class:`AuditLogDiff`:
- :attr:`~AuditLogDiff.colour`
- :attr:`~AuditLogDiff.secondary_colour`
- :attr:`~AuditLogDiff.tertiary_colour`
- :attr:`~AuditLogDiff.mentionable`
- :attr:`~AuditLogDiff.hoist`
- :attr:`~AuditLogDiff.icon`
@ -2479,6 +2481,8 @@ of :class:`enum.Enum`.
Possible attributes for :class:`AuditLogDiff`:
- :attr:`~AuditLogDiff.colour`
- :attr:`~AuditLogDiff.secondary_colour`
- :attr:`~AuditLogDiff.tertiary_colour`
- :attr:`~AuditLogDiff.mentionable`
- :attr:`~AuditLogDiff.hoist`
- :attr:`~AuditLogDiff.icon`
@ -2496,6 +2500,8 @@ of :class:`enum.Enum`.
Possible attributes for :class:`AuditLogDiff`:
- :attr:`~AuditLogDiff.colour`
- :attr:`~AuditLogDiff.secondary_colour`
- :attr:`~AuditLogDiff.tertiary_colour`
- :attr:`~AuditLogDiff.mentionable`
- :attr:`~AuditLogDiff.hoist`
- :attr:`~AuditLogDiff.name`
@ -4210,6 +4216,24 @@ AuditLogDiff
:type: :class:`Colour`
.. attribute:: secondary_colour
secondary_color
The secondary colour of a role.
See also :attr:`Role.secondary_colour`
:type: Optional[:class:`Colour`]
.. attribute:: tertiary_colour
tertiary_color
The tertiary colour of a role.
See also :attr:`Role.tertiary_colour`
:type: Optional[:class:`Colour`]
.. attribute:: hoist
Whether the role is being hoisted or not.

Loading…
Cancel
Save