feat: v13 guildAuditLogEntryCreate event

#9092 djs
This commit is contained in:
Elysia
2023-02-12 15:52:03 +07:00
parent f28ea5c031
commit 7329a53b34
7 changed files with 64 additions and 8 deletions

View File

@@ -225,7 +225,7 @@ class GuildAuditLogs {
*/
this.entries = new Collection();
for (const item of data.audit_log_entries) {
const entry = new GuildAuditLogsEntry(this, guild, item);
const entry = new GuildAuditLogsEntry(guild, item, this);
this.entries.set(entry.id, entry);
}
}
@@ -384,7 +384,7 @@ class GuildAuditLogs {
* Audit logs entry.
*/
class GuildAuditLogsEntry {
constructor(logs, guild, data) {
constructor(guild, data, logs) {
const targetType = GuildAuditLogs.targetType(data.action_type);
/**
* The target type of this entry
@@ -410,6 +410,12 @@ class GuildAuditLogsEntry {
*/
this.reason = data.reason ?? null;
/**
* The id of the user that executed this entry
* @type {?Snowflake}
*/
this.executorId = data.user_id;
/**
* The user that executed this entry
* @type {?User}
@@ -417,7 +423,7 @@ class GuildAuditLogsEntry {
this.executor = data.user_id
? guild.client.options.partials.includes(PartialTypes.USER)
? guild.client.users._add({ id: data.user_id })
: guild.client.users.cache.get(data.user_id)
: guild.client.users.cache.get(data.user_id) ?? null
: null;
/**
@@ -521,6 +527,12 @@ class GuildAuditLogsEntry {
break;
}
/**
* The id of the target of this entry
* @type {?Snowflake}
*/
this.targetId = data.target_id;
/**
* The target of this entry
* @type {?AuditLogEntryTarget}
@@ -536,12 +548,12 @@ class GuildAuditLogsEntry {
} else if (targetType === Targets.USER && data.target_id) {
this.target = guild.client.options.partials.includes(PartialTypes.USER)
? guild.client.users._add({ id: data.target_id })
: guild.client.users.cache.get(data.target_id);
: guild.client.users.cache.get(data.target_id) ?? null;
} else if (targetType === Targets.GUILD) {
this.target = guild.client.guilds.cache.get(data.target_id);
} else if (targetType === Targets.WEBHOOK) {
this.target =
logs.webhooks.get(data.target_id) ??
logs?.webhooks.get(data.target_id) ??
new Webhook(
guild.client,
this.changes.reduce(
@@ -576,10 +588,10 @@ class GuildAuditLogsEntry {
this.target =
data.action_type === Actions.MESSAGE_BULK_DELETE
? guild.channels.cache.get(data.target_id) ?? { id: data.target_id }
: guild.client.users.cache.get(data.target_id);
: guild.client.users.cache.get(data.target_id) ?? null;
} else if (targetType === Targets.INTEGRATION) {
this.target =
logs.integrations.get(data.target_id) ??
logs?.integrations.get(data.target_id) ??
new Integration(
guild.client,
this.changes.reduce(