|
|
@ -4,6 +4,7 @@ from holster.enum import Enum |
|
|
|
|
|
|
|
from disco.gateway.packets import OPCode |
|
|
|
from disco.api.http import APIException |
|
|
|
from disco.util.paginator import Paginator |
|
|
|
from disco.util.snowflake import to_snowflake |
|
|
|
from disco.util.functional import cached_property |
|
|
|
from disco.types.base import ( |
|
|
@ -471,6 +472,18 @@ class Guild(SlottedModel, Permissible): |
|
|
|
def splash_url(self): |
|
|
|
return self.get_splash_url() |
|
|
|
|
|
|
|
@property |
|
|
|
def audit_log(self): |
|
|
|
return Paginator( |
|
|
|
self.client.api.guilds_auditlogs_list, |
|
|
|
'before', |
|
|
|
self.id, |
|
|
|
) |
|
|
|
|
|
|
|
def get_audit_log_entries(self, *args, **kwargs): |
|
|
|
return self.client.api.guilds_auditlogs_list(self.id, *args, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
AuditLogActionTypes = Enum( |
|
|
|
GUILD_UPDATE=1, |
|
|
|
CHANNEL_CREATE=10, |
|
|
@ -560,7 +573,7 @@ class AuditLogObjectChange(SlottedModel): |
|
|
|
|
|
|
|
class AuditLogEntry(SlottedModel): |
|
|
|
id = Field(snowflake) |
|
|
|
guild = Field(None) |
|
|
|
guild_id = Field(snowflake) |
|
|
|
user_id = Field(snowflake) |
|
|
|
target_id = Field(snowflake) |
|
|
|
action_type = Field(enum(AuditLogActionTypes)) |
|
|
@ -568,6 +581,38 @@ class AuditLogEntry(SlottedModel): |
|
|
|
options = DictField(text, text) |
|
|
|
reason = Field(text) |
|
|
|
|
|
|
|
_cached_target = Field(None) |
|
|
|
|
|
|
|
@classmethod |
|
|
|
def create(cls, client, users, webhooks, data, **kwargs): |
|
|
|
self = super(SlottedModel, cls).create(client, data, **kwargs) |
|
|
|
|
|
|
|
if self.action_type in MEMBER_ACTIONS: |
|
|
|
self._cached_target = users[self.target_id] |
|
|
|
elif self.action_type in WEBHOOK_ACTIONS: |
|
|
|
self._cached_target = webhooks[self.target_id] |
|
|
|
|
|
|
|
return self |
|
|
|
|
|
|
|
@cached_property |
|
|
|
def guild(self): |
|
|
|
return self.client.state.guilds.get(self.guild_id) |
|
|
|
|
|
|
|
@cached_property |
|
|
|
def user(self): |
|
|
|
return self.client.state.users.get(self.user_id) |
|
|
|
|
|
|
|
@cached_property |
|
|
|
def target(self): |
|
|
|
if self.action_type in GUILD_ACTIONS: |
|
|
|
return self.guild |
|
|
|
elif self.action_type in CHANNEL_ACTIONS: |
|
|
|
return self.guild.channels.get(self.target_id) |
|
|
|
elif self.action_type in MEMBER_ACTIONS: |
|
|
|
return self._cached_target or self.state.users.get(self.target_id) |
|
|
|
elif self.action_type in ROLE_ACTIONS: |
|
|
|
return self.guild.roles.get(self.target_id) |
|
|
|
elif self.action_type in WEBHOOK_ACTIONS: |
|
|
|
return self._cached_target |
|
|
|
elif self.action_type in EMOJI_ACTIONS: |
|
|
|
return self.guild.emojis.get(self.target_id) |
|
|
|