Skip to content

Commit

Permalink
feat(GuildAuditLogsEntry): onboarding events (#9726)
Browse files Browse the repository at this point in the history
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 9, 2024
1 parent d8e94d8 commit 3654efe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/discord.js/src/structures/GuildAuditLogsEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const { DiscordSnowflake } = require('@sapphire/snowflake');
const { AuditLogOptionsType, AuditLogEvent } = require('discord-api-types/v10');
const AutoModerationRule = require('./AutoModerationRule');
const { GuildOnboardingPrompt } = require('./GuildOnboardingPrompt');
const { GuildScheduledEvent } = require('./GuildScheduledEvent');
const Integration = require('./Integration');
const Invite = require('./Invite');
Expand All @@ -29,6 +30,8 @@ const Targets = {
Thread: 'Thread',
ApplicationCommand: 'ApplicationCommand',
AutoModeration: 'AutoModeration',
GuildOnboarding: 'GuildOnboarding',
GuildOnboardingPrompt: 'GuildOnboardingPrompt',
Unknown: 'Unknown',
};

Expand All @@ -49,10 +52,11 @@ const Targets = {
* * A thread
* * An application command
* * An auto moderation rule
* * A guild onboarding prompt
* * An object with an id key if target was deleted or fake entity
* * An object where the keys represent either the new value or the old value
* @typedef {?(Object|Guild|BaseChannel|User|Role|Invite|Webhook|GuildEmoji|Message|Integration|StageInstance|Sticker|
* GuildScheduledEvent|ApplicationCommand|AutoModerationRule)} AuditLogEntryTarget
* GuildScheduledEvent|ApplicationCommand|AutoModerationRule|GuildOnboardingPrompt)} AuditLogEntryTarget
*/

/**
Expand Down Expand Up @@ -80,6 +84,9 @@ const Targets = {
* * Thread
* * GuildScheduledEvent
* * ApplicationCommandPermission
* * GuildOnboarding
* * GuildOnboardingPrompt
* * Unknown
* @typedef {string} AuditLogTargetType
*/

Expand Down Expand Up @@ -349,6 +356,13 @@ class GuildAuditLogsEntry {
changesReduce(this.changes, { id: data.target_id, guild_id: guild.id }),
guild,
);
} else if (targetType === Targets.GuildOnboardingPrompt) {
this.target =
data.action_type === AuditLogEvent.OnboardingPromptCreate
? new GuildOnboardingPrompt(guild.client, changesReduce(this.changes, { id: data.target_id }), guild.id)
: changesReduce(this.changes, { id: data.target_id });
} else if (targetType === Targets.GuildOnboarding) {
this.target = changesReduce(this.changes, { id: data.target_id });
} else if (data.target_id) {
this.target = guild[`${targetType.toLowerCase()}s`]?.cache.get(data.target_id) ?? { id: data.target_id };
}
Expand All @@ -375,6 +389,8 @@ class GuildAuditLogsEntry {
if (target < 120) return Targets.Thread;
if (target < 130) return Targets.ApplicationCommand;
if (target >= 140 && target < 150) return Targets.AutoModeration;
if (target >= 163 && target <= 165) return Targets.GuildOnboardingPrompt;
if (target >= 160 && target < 170) return Targets.GuildOnboarding;
return Targets.Unknown;
}

Expand Down Expand Up @@ -402,6 +418,8 @@ class GuildAuditLogsEntry {
AuditLogEvent.ThreadCreate,
AuditLogEvent.AutoModerationRuleCreate,
AuditLogEvent.AutoModerationBlockMessage,
AuditLogEvent.OnboardingPromptCreate,
AuditLogEvent.OnboardingCreate,
].includes(action)
) {
return 'Create';
Expand All @@ -428,6 +446,7 @@ class GuildAuditLogsEntry {
AuditLogEvent.GuildScheduledEventDelete,
AuditLogEvent.ThreadDelete,
AuditLogEvent.AutoModerationRuleDelete,
AuditLogEvent.OnboardingPromptDelete,
].includes(action)
) {
return 'Delete';
Expand All @@ -452,6 +471,8 @@ class GuildAuditLogsEntry {
AuditLogEvent.ThreadUpdate,
AuditLogEvent.ApplicationCommandPermissionUpdate,
AuditLogEvent.AutoModerationRuleUpdate,
AuditLogEvent.OnboardingPromptUpdate,
AuditLogEvent.OnboardingUpdate,
].includes(action)
) {
return 'Update';
Expand Down
6 changes: 6 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5784,6 +5784,11 @@ interface GuildAuditLogsTypes {
[AuditLogEvent.AutoModerationBlockMessage]: ['AutoModerationRule', 'Create'];
[AuditLogEvent.AutoModerationFlagToChannel]: ['AutoModerationRule', 'Create'];
[AuditLogEvent.AutoModerationUserCommunicationDisabled]: ['AutoModerationRule', 'Create'];
[AuditLogEvent.OnboardingPromptCreate]: ['GuildOnboardingPrompt', 'Create'];
[AuditLogEvent.OnboardingPromptUpdate]: ['GuildOnboardingPrompt', 'Update'];
[AuditLogEvent.OnboardingPromptDelete]: ['GuildOnboardingPrompt', 'Delete'];
[AuditLogEvent.OnboardingCreate]: ['GuildOnboarding', 'Create'];
[AuditLogEvent.OnboardingUpdate]: ['GuildOnboarding', 'Update'];
}

export type GuildAuditLogsActionType = GuildAuditLogsTypes[keyof GuildAuditLogsTypes][1] | 'All';
Expand Down Expand Up @@ -5848,6 +5853,7 @@ export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLo
GuildScheduledEvent: GuildScheduledEvent;
ApplicationCommand: ApplicationCommand | { id: Snowflake };
AutoModerationRule: AutoModerationRule;
GuildOnboardingPrompt: GuildOnboardingPrompt;
}

export interface GuildAuditLogsFetchOptions<Event extends GuildAuditLogsResolvable> {
Expand Down

0 comments on commit 3654efe

Please sign in to comment.