Skip to content

Commit

Permalink
feat(GuildAuditLogsEntry): expose extra integrationType in relevant l…
Browse files Browse the repository at this point in the history
…og types (#9796)

* feat(GuildAuditLogsEntry): expose ingrationType

* fix: not optional, if extra is present on these types

not necessary, as it is conditionally assigned

* fix: remove non-extra approach

* fix(types): string is not guaranteed to be the known enum

* fix: adapt type tests to new extra properties

* fix: include null in type, since extra is not always populated

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
  • Loading branch information
almostSouji and Jiralite authored Sep 17, 2023
1 parent ed14135 commit 3109798
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/discord.js/src/structures/GuildAuditLogsEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ class GuildAuditLogsEntry {
};
break;

case AuditLogEvent.MemberKick:
case AuditLogEvent.MemberRoleUpdate: {
if (data.integration_type) {
this.extra = {
integrationType: data.integration_type,
};
}
break;
}

default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5414,6 +5414,8 @@ interface GuildAuditLogsTypes {
export type GuildAuditLogsActionType = GuildAuditLogsTypes[keyof GuildAuditLogsTypes][1] | 'All';

export interface GuildAuditLogsEntryExtraField {
[AuditLogEvent.MemberKick]: { integrationType: string } | null;
[AuditLogEvent.MemberRoleUpdate]: { integrationType: string } | null;
[AuditLogEvent.MemberPrune]: { removed: number; days: number };
[AuditLogEvent.MemberMove]: { channel: VoiceBasedChannel | { id: Snowflake }; count: number };
[AuditLogEvent.MessageDelete]: { channel: GuildTextBasedChannel | { id: Snowflake }; count: number };
Expand Down
7 changes: 6 additions & 1 deletion packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2074,9 +2074,14 @@ expectType<Promise<GuildAuditLogsEntry<null, GuildAuditLogsActionType, GuildAudi
guild.fetchAuditLogs().then(al => al.entries.first()),
);

expectType<Promise<null | undefined>>(
expectType<Promise<{ integrationType: string } | null | undefined>>(
guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick }).then(al => al.entries.first()?.extra),
);

expectType<Promise<{ integrationType: string } | null | undefined>>(
guild.fetchAuditLogs({ type: AuditLogEvent.MemberRoleUpdate }).then(al => al.entries.first()?.extra),
);

expectType<Promise<StageChannel | { id: Snowflake } | undefined>>(
guild.fetchAuditLogs({ type: AuditLogEvent.StageInstanceCreate }).then(al => al.entries.first()?.extra),
);
Expand Down

0 comments on commit 3109798

Please sign in to comment.