mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-19 17:37:01 +00:00
Support new role colours in audit log
This commit is contained in:
parent
b1be7dea74
commit
a00510988a
@ -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'):
|
||||
|
@ -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,
|
||||
]
|
||||
|
||||
|
||||
|
34
docs/api.rst
34
docs/api.rst
@ -927,25 +927,25 @@ Members
|
||||
.. function:: on_raw_presence_update(payload)
|
||||
|
||||
Called when a :class:`Member` updates their presence.
|
||||
|
||||
|
||||
This requires :attr:`Intents.presences` to be enabled.
|
||||
|
||||
Unlike :func:`on_presence_update`, when enabled, this is called regardless of the state of internal guild
|
||||
Unlike :func:`on_presence_update`, when enabled, this is called regardless of the state of internal guild
|
||||
and member caches, and **does not** provide a comparison between the previous and updated states of the :class:`Member`.
|
||||
|
||||
.. important::
|
||||
|
||||
By default, this event is only dispatched when :attr:`Intents.presences` is enabled **and** :attr:`Intents.members`
|
||||
By default, this event is only dispatched when :attr:`Intents.presences` is enabled **and** :attr:`Intents.members`
|
||||
is disabled.
|
||||
|
||||
You can manually override this behaviour by setting the **enable_raw_presences** flag in the :class:`Client`,
|
||||
however :attr:`Intents.presences` is always required for this event to work.
|
||||
|
||||
|
||||
.. versionadded:: 2.5
|
||||
|
||||
:param payload: The raw presence update event model.
|
||||
:type payload: :class:`RawPresenceUpdateEvent`
|
||||
|
||||
|
||||
|
||||
Messages
|
||||
~~~~~~~~~
|
||||
@ -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…
x
Reference in New Issue
Block a user