mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-04 01:00:00 +00:00
Fix audit log for multiple app command permission updates
This commit is contained in:
parent
66dbed29b7
commit
3b5cd3b92c
@ -67,7 +67,7 @@ if TYPE_CHECKING:
|
|||||||
from .sticker import GuildSticker
|
from .sticker import GuildSticker
|
||||||
from .threads import Thread
|
from .threads import Thread
|
||||||
from .integrations import PartialIntegration
|
from .integrations import PartialIntegration
|
||||||
from .app_commands import AppCommand, AppCommandPermissions
|
from .app_commands import AppCommand
|
||||||
|
|
||||||
TargetType = Union[
|
TargetType = Union[
|
||||||
Guild,
|
Guild,
|
||||||
@ -98,20 +98,6 @@ def _transform_snowflake(entry: AuditLogEntry, data: Snowflake) -> int:
|
|||||||
return int(data)
|
return int(data)
|
||||||
|
|
||||||
|
|
||||||
def _transform_app_command_permissions(
|
|
||||||
entry: AuditLogEntry, data: ApplicationCommandPermissions
|
|
||||||
) -> Optional[AppCommandPermissions]:
|
|
||||||
# avoid circular import
|
|
||||||
from discord.app_commands.models import AppCommandPermissions
|
|
||||||
|
|
||||||
if data is None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
state = entry._state
|
|
||||||
guild = entry.guild
|
|
||||||
return AppCommandPermissions(data=data, guild=guild, state=state)
|
|
||||||
|
|
||||||
|
|
||||||
def _transform_channel(entry: AuditLogEntry, data: Optional[Snowflake]) -> Optional[Union[abc.GuildChannel, Object]]:
|
def _transform_channel(entry: AuditLogEntry, data: Optional[Snowflake]) -> Optional[Union[abc.GuildChannel, Object]]:
|
||||||
if data is None:
|
if data is None:
|
||||||
return None
|
return None
|
||||||
@ -275,7 +261,6 @@ class AuditLogChanges:
|
|||||||
'entity_type': (None, _enum_transformer(enums.EntityType)),
|
'entity_type': (None, _enum_transformer(enums.EntityType)),
|
||||||
'preferred_locale': (None, _enum_transformer(enums.Locale)),
|
'preferred_locale': (None, _enum_transformer(enums.Locale)),
|
||||||
'image_hash': ('cover_image', _transform_cover_image),
|
'image_hash': ('cover_image', _transform_cover_image),
|
||||||
'app_command_permission_update': ('app_command_permissions', _transform_app_command_permissions),
|
|
||||||
'trigger_type': (None, _enum_transformer(enums.AutoModRuleTriggerType)),
|
'trigger_type': (None, _enum_transformer(enums.AutoModRuleTriggerType)),
|
||||||
}
|
}
|
||||||
# fmt: on
|
# fmt: on
|
||||||
@ -283,14 +268,28 @@ class AuditLogChanges:
|
|||||||
def __init__(self, entry: AuditLogEntry, data: List[AuditLogChangePayload]):
|
def __init__(self, entry: AuditLogEntry, data: List[AuditLogChangePayload]):
|
||||||
self.before: AuditLogDiff = AuditLogDiff()
|
self.before: AuditLogDiff = AuditLogDiff()
|
||||||
self.after: AuditLogDiff = AuditLogDiff()
|
self.after: AuditLogDiff = AuditLogDiff()
|
||||||
|
|
||||||
for elem in data:
|
|
||||||
# special case entire process since each
|
# special case entire process since each
|
||||||
# element in data is a different target
|
# element in data is a different target
|
||||||
# key is the target id
|
# key is the target id
|
||||||
if entry.action is enums.AuditLogAction.app_command_permission_update:
|
if entry.action is enums.AuditLogAction.app_command_permission_update:
|
||||||
attr = entry.action.name
|
self.before.app_command_permissions = []
|
||||||
else:
|
self.after.app_command_permissions = []
|
||||||
|
|
||||||
|
for elem in data:
|
||||||
|
self._handle_app_command_permissions(
|
||||||
|
self.before,
|
||||||
|
entry,
|
||||||
|
elem.get('old_value'), # type: ignore # value will be an ApplicationCommandPermissions if present
|
||||||
|
)
|
||||||
|
|
||||||
|
self._handle_app_command_permissions(
|
||||||
|
self.after,
|
||||||
|
entry,
|
||||||
|
elem.get('new_value'), # type: ignore # value will be an ApplicationCommandPermissions if present
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
for elem in data:
|
||||||
attr = elem['key']
|
attr = elem['key']
|
||||||
|
|
||||||
# special cases for role add/remove
|
# special cases for role add/remove
|
||||||
@ -361,6 +360,22 @@ class AuditLogChanges:
|
|||||||
|
|
||||||
setattr(second, 'roles', data)
|
setattr(second, 'roles', data)
|
||||||
|
|
||||||
|
def _handle_app_command_permissions(
|
||||||
|
self,
|
||||||
|
diff: AuditLogDiff,
|
||||||
|
entry: AuditLogEntry,
|
||||||
|
data: Optional[ApplicationCommandPermissions],
|
||||||
|
):
|
||||||
|
if data is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
# avoid circular import
|
||||||
|
from discord.app_commands import AppCommandPermissions
|
||||||
|
|
||||||
|
state = entry._state
|
||||||
|
guild = entry.guild
|
||||||
|
diff.app_command_permissions.append(AppCommandPermissions(data=data, guild=guild, state=state))
|
||||||
|
|
||||||
|
|
||||||
class _AuditLogProxy:
|
class _AuditLogProxy:
|
||||||
def __init__(self, **kwargs: Any) -> None:
|
def __init__(self, **kwargs: Any) -> None:
|
||||||
|
@ -3720,9 +3720,9 @@ AuditLogDiff
|
|||||||
|
|
||||||
.. attribute:: app_command_permissions
|
.. attribute:: app_command_permissions
|
||||||
|
|
||||||
The permissions of the app command.
|
List of permissions for the app command.
|
||||||
|
|
||||||
:type: :class:`~discord.app_commands.AppCommandPermissions`
|
:type: List[:class:`~discord.app_commands.AppCommandPermissions`]
|
||||||
|
|
||||||
.. attribute:: enabled
|
.. attribute:: enabled
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user