|
|
@ -76,6 +76,7 @@ if TYPE_CHECKING: |
|
|
|
from .types.onboarding import Prompt as PromptPayload, PromptOption as PromptOptionPayload |
|
|
|
from .user import User |
|
|
|
from .app_commands import AppCommand |
|
|
|
from .webhook import Webhook |
|
|
|
|
|
|
|
TargetType = Union[ |
|
|
|
Guild, |
|
|
@ -91,6 +92,9 @@ if TYPE_CHECKING: |
|
|
|
Object, |
|
|
|
PartialIntegration, |
|
|
|
AutoModRule, |
|
|
|
ScheduledEvent, |
|
|
|
Webhook, |
|
|
|
AppCommand, |
|
|
|
None, |
|
|
|
] |
|
|
|
|
|
|
@ -597,6 +601,7 @@ class AuditLogEntry(Hashable): |
|
|
|
integrations: Mapping[int, PartialIntegration], |
|
|
|
app_commands: Mapping[int, AppCommand], |
|
|
|
automod_rules: Mapping[int, AutoModRule], |
|
|
|
webhooks: Mapping[int, Webhook], |
|
|
|
data: AuditLogEntryPayload, |
|
|
|
guild: Guild, |
|
|
|
): |
|
|
@ -606,6 +611,7 @@ class AuditLogEntry(Hashable): |
|
|
|
self._integrations: Mapping[int, PartialIntegration] = integrations |
|
|
|
self._app_commands: Mapping[int, AppCommand] = app_commands |
|
|
|
self._automod_rules: Mapping[int, AutoModRule] = automod_rules |
|
|
|
self._webhooks: Mapping[int, Webhook] = webhooks |
|
|
|
self._from_data(data) |
|
|
|
|
|
|
|
def _from_data(self, data: AuditLogEntryPayload) -> None: |
|
|
@ -744,12 +750,11 @@ class AuditLogEntry(Hashable): |
|
|
|
if self.action.target_type is None: |
|
|
|
return None |
|
|
|
|
|
|
|
if self._target_id is None: |
|
|
|
return None |
|
|
|
|
|
|
|
try: |
|
|
|
converter = getattr(self, '_convert_target_' + self.action.target_type) |
|
|
|
except AttributeError: |
|
|
|
if self._target_id is None: |
|
|
|
return None |
|
|
|
return Object(id=self._target_id) |
|
|
|
else: |
|
|
|
return converter(self._target_id) |
|
|
@ -782,7 +787,12 @@ class AuditLogEntry(Hashable): |
|
|
|
def _convert_target_channel(self, target_id: int) -> Union[abc.GuildChannel, Object]: |
|
|
|
return self.guild.get_channel(target_id) or Object(id=target_id) |
|
|
|
|
|
|
|
def _convert_target_user(self, target_id: int) -> Union[Member, User, Object]: |
|
|
|
def _convert_target_user(self, target_id: Optional[int]) -> Optional[Union[Member, User, Object]]: |
|
|
|
# For some reason the member_disconnect and member_move action types |
|
|
|
# do not have a non-null target_id so safeguard against that |
|
|
|
if target_id is None: |
|
|
|
return None |
|
|
|
|
|
|
|
return self._get_member(target_id) or Object(id=target_id, type=Member) |
|
|
|
|
|
|
|
def _convert_target_role(self, target_id: int) -> Union[Role, Object]: |
|
|
@ -862,3 +872,9 @@ class AuditLogEntry(Hashable): |
|
|
|
|
|
|
|
def _convert_target_auto_moderation(self, target_id: int) -> Union[AutoModRule, Object]: |
|
|
|
return self._automod_rules.get(target_id) or Object(target_id, type=AutoModRule) |
|
|
|
|
|
|
|
def _convert_target_webhook(self, target_id: int) -> Union[Webhook, Object]: |
|
|
|
# circular import |
|
|
|
from .webhook import Webhook |
|
|
|
|
|
|
|
return self._webhooks.get(target_id) or Object(target_id, type=Webhook) |
|
|
|