Skip to content

Commit

Permalink
feat(GuildAuditLogs): add threads (#6195)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckohen committed Jul 28, 2021
1 parent f060a3f commit 26ba0e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/structures/GuildAuditLogs.js
Expand Up @@ -23,6 +23,7 @@ const Util = require('../util/Util');
* * INTEGRATION
* * STAGE_INSTANCE
* * STICKER
* * THREAD
* @typedef {string} AuditLogTargetType
*/

Expand All @@ -44,6 +45,7 @@ const Targets = {
INTEGRATION: 'INTEGRATION',
STAGE_INSTANCE: 'STAGE_INSTANCE',
STICKER: 'STICKER',
THREAD: 'THREAD',
UNKNOWN: 'UNKNOWN',
};

Expand Down Expand Up @@ -91,6 +93,9 @@ const Targets = {
* * STICKER_CREATE: 90
* * STICKER_UPDATE: 91
* * STICKER_DELETE: 92
* * THREAD_CREATE: 110
* * THREAD_UPDATE: 111
* * THREAD_DELETE: 112
* @typedef {?(number|string)} AuditLogAction
*/

Expand Down Expand Up @@ -142,6 +147,9 @@ const Actions = {
STICKER_CREATE: 90,
STICKER_UPDATE: 91,
STICKER_DELETE: 92,
THREAD_CREATE: 110,
THREAD_UPDATE: 111,
THREAD_DELETE: 112,
};

/**
Expand All @@ -150,6 +158,7 @@ const Actions = {
class GuildAuditLogs {
constructor(guild, data) {
if (data.users) for (const user of data.users) guild.client.users._add(user);
if (data.threads) for (const thread of data.threads) guild.client.channels._add(thread, guild);
/**
* Cached webhooks
* @type {Collection<Snowflake, Webhook>}
Expand Down Expand Up @@ -207,6 +216,7 @@ class GuildAuditLogs {
* * An integration
* * A stage instance
* * A sticker
* * A thread
* * An object with an id key if target was deleted
* * An object where the keys represent either the new value or the old value
* @typedef {?(Object|Guild|Channel|User|Role|Invite|Webhook|GuildEmoji|Message|Integration|StageInstance|Sticker)}
Expand All @@ -230,6 +240,8 @@ class GuildAuditLogs {
if (target < 83) return Targets.INTEGRATION;
if (target < 86) return Targets.STAGE_INSTANCE;
if (target < 100) return Targets.STICKER;
if (target < 110) return Targets.UNKNOWN;
if (target < 120) return Targets.THREAD;
return Targets.UNKNOWN;
}

Expand Down Expand Up @@ -262,6 +274,7 @@ class GuildAuditLogs {
Actions.INTEGRATION_CREATE,
Actions.STAGE_INSTANCE_CREATE,
Actions.STICKER_CREATE,
Actions.THREAD_CREATE,
].includes(action)
) {
return 'CREATE';
Expand All @@ -285,6 +298,7 @@ class GuildAuditLogs {
Actions.INTEGRATION_DELETE,
Actions.STAGE_INSTANCE_DELETE,
Actions.STICKER_DELETE,
Actions.THREAD_DELETE,
].includes(action)
) {
return 'DELETE';
Expand All @@ -305,6 +319,7 @@ class GuildAuditLogs {
Actions.INTEGRATION_UPDATE,
Actions.STAGE_INSTANCE_UPDATE,
Actions.STICKER_UPDATE,
Actions.THREAD_UPDATE,
].includes(action)
) {
return 'UPDATE';
Expand Down Expand Up @@ -520,7 +535,7 @@ class GuildAuditLogsEntry {
),
guild,
);
} else if (targetType === Targets.CHANNEL) {
} else if (targetType === Targets.CHANNEL || targetType === Targets.THREAD) {
this.target =
guild.channels.cache.get(data.target_id) ??
this.changes.reduce(
Expand Down
5 changes: 5 additions & 0 deletions typings/index.d.ts
Expand Up @@ -661,6 +661,7 @@ export class GuildAuditLogsEntry {
| Integration
| StageInstance
| Sticker
| ThreadChannel
| { id: Snowflake }
| null;
public targetType: GuildAuditLogsTarget;
Expand Down Expand Up @@ -3443,6 +3444,9 @@ export interface GuildAuditLogsActions {
STICKER_CREATE?: number;
STICKER_UPDATE?: number;
STICKER_DELETE?: number;
THREAD_CREATE?: number;
THREAD_UPDATE?: number;
THREAD_DELETE?: number;
}

export type GuildAuditLogsActionType = 'CREATE' | 'DELETE' | 'UPDATE' | 'ALL';
Expand All @@ -3469,6 +3473,7 @@ export interface GuildAuditLogsTargets {
INTEGRATION?: string;
STAGE_INSTANCE?: string;
STICKER?: string;
THREAD?: string;
UNKNOWN?: string;
}

Expand Down

0 comments on commit 26ba0e1

Please sign in to comment.