mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(GuildAuditLogEntry): fix some incorrect types and runtime logic (#10849)
* fix(GuildAuditLogEntry): fix some incorrect types and runtime logic * chore: bite me
This commit is contained in:
@@ -89,6 +89,7 @@ const Targets = {
|
||||
* * GuildOnboarding
|
||||
* * GuildOnboardingPrompt
|
||||
* * SoundboardSound
|
||||
* * AutoModeration
|
||||
* * Unknown
|
||||
* @typedef {string} AuditLogTargetType
|
||||
*/
|
||||
@@ -202,7 +203,6 @@ class GuildAuditLogsEntry {
|
||||
|
||||
case AuditLogEvent.MemberMove:
|
||||
case AuditLogEvent.MessageDelete:
|
||||
case AuditLogEvent.MessageBulkDelete:
|
||||
this.extra = {
|
||||
channel: guild.channels.cache.get(data.options.channel_id) ?? { id: data.options.channel_id },
|
||||
count: Number(data.options.count),
|
||||
@@ -217,6 +217,7 @@ class GuildAuditLogsEntry {
|
||||
};
|
||||
break;
|
||||
|
||||
case AuditLogEvent.MessageBulkDelete:
|
||||
case AuditLogEvent.MemberDisconnect:
|
||||
this.extra = {
|
||||
count: Number(data.options.count),
|
||||
@@ -368,12 +369,14 @@ class GuildAuditLogsEntry {
|
||||
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 (targetType === Targets.Role) {
|
||||
this.target = guild.roles.cache.get(data.target_id) ?? { id: data.target_id };
|
||||
} else if (targetType === Targets.Emoji) {
|
||||
this.target = guild.emojis.cache.get(data.target_id) ?? { id: data.target_id };
|
||||
} else if (targetType === Targets.SoundboardSound) {
|
||||
this.target = guild.soundboardSounds.cache.get(data.target_id) ?? { id: data.target_id };
|
||||
} else if (data.target_id) {
|
||||
this.target = guild[`${targetType.toLowerCase()}s`]?.cache.get(data.target_id) ?? { id: data.target_id };
|
||||
this.target = { id: data.target_id };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,7 +401,8 @@ class GuildAuditLogsEntry {
|
||||
if (target < 120) return Targets.Thread;
|
||||
if (target < 130) return Targets.ApplicationCommand;
|
||||
if (target < 140) return Targets.SoundboardSound;
|
||||
if (target >= 143 && target < 150) return Targets.AutoModeration;
|
||||
if (target < 143) return Targets.AutoModeration;
|
||||
if (target < 146) return Targets.User;
|
||||
if (target >= 163 && target <= 165) return Targets.GuildOnboardingPrompt;
|
||||
if (target >= 160 && target < 170) return Targets.GuildOnboarding;
|
||||
return Targets.Unknown;
|
||||
@@ -483,7 +487,11 @@ class GuildAuditLogsEntry {
|
||||
AuditLogEvent.ThreadUpdate,
|
||||
AuditLogEvent.SoundboardSoundUpdate,
|
||||
AuditLogEvent.ApplicationCommandPermissionUpdate,
|
||||
AuditLogEvent.SoundboardSoundUpdate,
|
||||
AuditLogEvent.AutoModerationRuleUpdate,
|
||||
AuditLogEvent.AutoModerationBlockMessage,
|
||||
AuditLogEvent.AutoModerationFlagToChannel,
|
||||
AuditLogEvent.AutoModerationUserCommunicationDisabled,
|
||||
AuditLogEvent.OnboardingPromptUpdate,
|
||||
AuditLogEvent.OnboardingUpdate,
|
||||
].includes(action)
|
||||
|
||||
51
packages/discord.js/typings/index.d.ts
vendored
51
packages/discord.js/typings/index.d.ts
vendored
@@ -1607,9 +1607,9 @@ export class Guild extends AnonymousGuild {
|
||||
public editOnboarding(options: GuildOnboardingEditOptions): Promise<GuildOnboarding>;
|
||||
public editWelcomeScreen(options: WelcomeScreenEditOptions): Promise<WelcomeScreen>;
|
||||
public equals(guild: Guild): boolean;
|
||||
public fetchAuditLogs<Event extends GuildAuditLogsResolvable = null>(
|
||||
public fetchAuditLogs<Event extends GuildAuditLogsResolvable = AuditLogEvent>(
|
||||
options?: GuildAuditLogsFetchOptions<Event>,
|
||||
): Promise<GuildAuditLogs<Event>>;
|
||||
): Promise<GuildAuditLogs<Event extends null ? AuditLogEvent : Event>>;
|
||||
public fetchIntegrations(): Promise<Collection<Snowflake | string, Integration>>;
|
||||
public fetchOnboarding(): Promise<GuildOnboarding>;
|
||||
public fetchOwner(options?: BaseFetchOptions): Promise<GuildMember>;
|
||||
@@ -1666,7 +1666,7 @@ export class FileComponent extends Component<APIFileComponent> {
|
||||
public get spoiler(): boolean;
|
||||
}
|
||||
|
||||
export class GuildAuditLogs<Event extends GuildAuditLogsResolvable = AuditLogEvent> {
|
||||
export class GuildAuditLogs<Event extends AuditLogEvent = AuditLogEvent> {
|
||||
private constructor(guild: Guild, data: RawGuildAuditLogData);
|
||||
private applicationCommands: Collection<Snowflake, ApplicationCommand>;
|
||||
private webhooks: Collection<Snowflake, Webhook<WebhookType.ChannelFollower | WebhookType.Incoming>>;
|
||||
@@ -1678,33 +1678,30 @@ export class GuildAuditLogs<Event extends GuildAuditLogsResolvable = AuditLogEve
|
||||
}
|
||||
|
||||
export class GuildAuditLogsEntry<
|
||||
TAction extends GuildAuditLogsResolvable = AuditLogEvent,
|
||||
TAction extends AuditLogEvent = AuditLogEvent,
|
||||
TActionType extends GuildAuditLogsActionType = TAction extends keyof GuildAuditLogsTypes
|
||||
? GuildAuditLogsTypes[TAction][1]
|
||||
: GuildAuditLogsActionType,
|
||||
: 'All',
|
||||
TTargetType extends GuildAuditLogsTargetType = TAction extends keyof GuildAuditLogsTypes
|
||||
? GuildAuditLogsTypes[TAction][0]
|
||||
: GuildAuditLogsTargetType,
|
||||
TResolvedType = TAction extends null ? AuditLogEvent : TAction,
|
||||
: 'Unknown',
|
||||
> {
|
||||
private constructor(guild: Guild, data: RawGuildAuditLogEntryData, logs?: GuildAuditLogs);
|
||||
public static Targets: GuildAuditLogsTargets;
|
||||
public action: TResolvedType;
|
||||
public action: TAction;
|
||||
public actionType: TActionType;
|
||||
public changes: AuditLogChange[];
|
||||
public get createdAt(): Date;
|
||||
public get createdTimestamp(): number;
|
||||
public executorId: Snowflake | null;
|
||||
public executor: User | null;
|
||||
public extra: TResolvedType extends keyof GuildAuditLogsEntryExtraField
|
||||
? GuildAuditLogsEntryExtraField[TResolvedType]
|
||||
: null;
|
||||
public executor: User | PartialUser | null;
|
||||
public extra: TAction extends keyof GuildAuditLogsEntryExtraField ? GuildAuditLogsEntryExtraField[TAction] : null;
|
||||
public id: Snowflake;
|
||||
public reason: string | null;
|
||||
public targetId: Snowflake | null;
|
||||
public target: TTargetType extends keyof GuildAuditLogsEntryTargetField<TActionType>
|
||||
? GuildAuditLogsEntryTargetField<TActionType>[TTargetType]
|
||||
: Role | GuildEmoji | { id: Snowflake } | null;
|
||||
public target: TTargetType extends keyof GuildAuditLogsEntryTargetField<TAction>
|
||||
? GuildAuditLogsEntryTargetField<TAction>[TTargetType]
|
||||
: { id: Snowflake | undefined; [x: string]: unknown } | null;
|
||||
public targetType: TTargetType;
|
||||
public static actionType(action: AuditLogEvent): GuildAuditLogsActionType;
|
||||
public static targetType(target: AuditLogEvent): GuildAuditLogsTargetType;
|
||||
@@ -6346,9 +6343,9 @@ interface GuildAuditLogsTypes {
|
||||
[AuditLogEvent.AutoModerationRuleCreate]: ['AutoModeration', 'Create'];
|
||||
[AuditLogEvent.AutoModerationRuleUpdate]: ['AutoModeration', 'Update'];
|
||||
[AuditLogEvent.AutoModerationRuleDelete]: ['AutoModeration', 'Delete'];
|
||||
[AuditLogEvent.AutoModerationBlockMessage]: ['AutoModeration', 'Create'];
|
||||
[AuditLogEvent.AutoModerationFlagToChannel]: ['AutoModeration', 'Create'];
|
||||
[AuditLogEvent.AutoModerationUserCommunicationDisabled]: ['AutoModeration', 'Create'];
|
||||
[AuditLogEvent.AutoModerationBlockMessage]: ['User', 'Update'];
|
||||
[AuditLogEvent.AutoModerationFlagToChannel]: ['User', 'Update'];
|
||||
[AuditLogEvent.AutoModerationUserCommunicationDisabled]: ['User', 'Update'];
|
||||
[AuditLogEvent.OnboardingPromptCreate]: ['GuildOnboardingPrompt', 'Create'];
|
||||
[AuditLogEvent.OnboardingPromptUpdate]: ['GuildOnboardingPrompt', 'Update'];
|
||||
[AuditLogEvent.OnboardingPromptDelete]: ['GuildOnboardingPrompt', 'Delete'];
|
||||
@@ -6364,7 +6361,7 @@ export interface GuildAuditLogsEntryExtraField {
|
||||
[AuditLogEvent.MemberPrune]: { removed: number; days: number };
|
||||
[AuditLogEvent.MemberMove]: { channel: VoiceBasedChannel | { id: Snowflake }; count: number };
|
||||
[AuditLogEvent.MessageDelete]: { channel: GuildTextBasedChannel | { id: Snowflake }; count: number };
|
||||
[AuditLogEvent.MessageBulkDelete]: { channel: GuildTextBasedChannel | { id: Snowflake }; count: number };
|
||||
[AuditLogEvent.MessageBulkDelete]: { count: number };
|
||||
[AuditLogEvent.MessagePin]: { channel: GuildTextBasedChannel | { id: Snowflake }; messageId: Snowflake };
|
||||
[AuditLogEvent.MessageUnpin]: { channel: GuildTextBasedChannel | { id: Snowflake }; messageId: Snowflake };
|
||||
[AuditLogEvent.MemberDisconnect]: { count: number };
|
||||
@@ -6404,12 +6401,14 @@ export interface GuildAuditLogsEntryExtraField {
|
||||
};
|
||||
}
|
||||
|
||||
export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLogsActionType> {
|
||||
User: User | null;
|
||||
export interface GuildAuditLogsEntryTargetField<TAction extends AuditLogEvent> {
|
||||
User: User | PartialUser | null;
|
||||
Guild: Guild;
|
||||
Webhook: Webhook<WebhookType.ChannelFollower | WebhookType.Incoming>;
|
||||
Invite: Invite;
|
||||
Message: TActionType extends AuditLogEvent.MessageBulkDelete ? Guild | { id: Snowflake } : User;
|
||||
Emoji: GuildEmoji | { id: Snowflake };
|
||||
Role: Role | { id: Snowflake };
|
||||
Message: TAction extends AuditLogEvent.MessageBulkDelete ? GuildTextBasedChannel | { id: Snowflake } : User | null;
|
||||
Integration: Integration;
|
||||
Channel: NonThreadGuildBasedChannel | { id: Snowflake; [x: string]: unknown };
|
||||
Thread: AnyThreadChannel | { id: Snowflake; [x: string]: unknown };
|
||||
@@ -6418,8 +6417,8 @@ export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLo
|
||||
GuildScheduledEvent: GuildScheduledEvent;
|
||||
ApplicationCommand: ApplicationCommand | { id: Snowflake };
|
||||
AutoModerationRule: AutoModerationRule;
|
||||
GuildOnboardingPrompt: GuildOnboardingPrompt;
|
||||
SoundboardSound: { id: Snowflake };
|
||||
GuildOnboardingPrompt: GuildOnboardingPrompt | { id: Snowflake; [x: string]: unknown };
|
||||
SoundboardSound: SoundboardSound | { id: Snowflake };
|
||||
}
|
||||
|
||||
export interface GuildAuditLogsFetchOptions<Event extends GuildAuditLogsResolvable> {
|
||||
@@ -6432,10 +6431,10 @@ export interface GuildAuditLogsFetchOptions<Event extends GuildAuditLogsResolvab
|
||||
|
||||
export type GuildAuditLogsResolvable = AuditLogEvent | null;
|
||||
|
||||
export type GuildAuditLogsTargetType = GuildAuditLogsTypes[keyof GuildAuditLogsTypes][0] | 'All' | 'Unknown';
|
||||
export type GuildAuditLogsTargetType = GuildAuditLogsTypes[keyof GuildAuditLogsTypes][0] | 'Unknown';
|
||||
|
||||
export type GuildAuditLogsTargets = {
|
||||
[Key in GuildAuditLogsTargetType]: GuildAuditLogsTargetType;
|
||||
[Key in GuildAuditLogsTargetType]: Key;
|
||||
};
|
||||
|
||||
export type GuildBanResolvable = GuildBan | UserResolvable;
|
||||
|
||||
@@ -2272,7 +2272,7 @@ expectType<Promise<GuildAuditLogs<AuditLogEvent.IntegrationUpdate>>>(
|
||||
guild.fetchAuditLogs({ type: AuditLogEvent.IntegrationUpdate }),
|
||||
);
|
||||
|
||||
expectType<Promise<GuildAuditLogs<null>>>(guild.fetchAuditLogs({ type: null }));
|
||||
expectType<Promise<GuildAuditLogs<AuditLogEvent>>>(guild.fetchAuditLogs({ type: null }));
|
||||
expectType<Promise<GuildAuditLogs<AuditLogEvent>>>(guild.fetchAuditLogs());
|
||||
|
||||
expectType<Promise<GuildAuditLogsEntry<AuditLogEvent.MemberKick, 'Delete', 'User'> | undefined>>(
|
||||
@@ -2282,10 +2282,10 @@ expectAssignable<Promise<GuildAuditLogsEntry<AuditLogEvent.MemberKick, 'Delete',
|
||||
guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick }).then(al => al.entries.first()),
|
||||
);
|
||||
|
||||
expectType<Promise<GuildAuditLogsEntry<null, GuildAuditLogsActionType, GuildAuditLogsTargetType> | undefined>>(
|
||||
expectType<Promise<GuildAuditLogsEntry<AuditLogEvent, GuildAuditLogsActionType, GuildAuditLogsTargetType> | undefined>>(
|
||||
guild.fetchAuditLogs({ type: null }).then(al => al.entries.first()),
|
||||
);
|
||||
expectType<Promise<GuildAuditLogsEntry<null, GuildAuditLogsActionType, GuildAuditLogsTargetType> | undefined>>(
|
||||
expectType<Promise<GuildAuditLogsEntry<AuditLogEvent, GuildAuditLogsActionType, GuildAuditLogsTargetType> | undefined>>(
|
||||
guild.fetchAuditLogs().then(al => al.entries.first()),
|
||||
);
|
||||
|
||||
@@ -2304,15 +2304,18 @@ expectType<Promise<{ channel: GuildTextBasedChannel | { id: Snowflake }; count:
|
||||
guild.fetchAuditLogs({ type: AuditLogEvent.MessageDelete }).then(al => al.entries.first()?.extra),
|
||||
);
|
||||
|
||||
expectType<Promise<User | null | undefined>>(
|
||||
expectType<Promise<User | PartialUser | null | undefined>>(
|
||||
guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick }).then(al => al.entries.first()?.target),
|
||||
);
|
||||
expectType<Promise<StageInstance | undefined>>(
|
||||
guild.fetchAuditLogs({ type: AuditLogEvent.StageInstanceCreate }).then(al => al.entries.first()?.target),
|
||||
);
|
||||
expectType<Promise<User | undefined>>(
|
||||
expectType<Promise<User | null | undefined>>(
|
||||
guild.fetchAuditLogs({ type: AuditLogEvent.MessageDelete }).then(al => al.entries.first()?.target),
|
||||
);
|
||||
expectType<Promise<GuildTextBasedChannel | { id: string } | undefined>>(
|
||||
guild.fetchAuditLogs({ type: AuditLogEvent.MessageBulkDelete }).then(al => al.entries.first()?.target),
|
||||
);
|
||||
|
||||
declare const AuditLogChange: AuditLogChange;
|
||||
// @ts-expect-error
|
||||
|
||||
Reference in New Issue
Block a user