Skip to content

Commit

Permalink
docs(GuildAuditLogs): Fix and reimplement type definitions (#8108)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite authored Jun 17, 2022
1 parent 90a98fe commit 4155136
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 26 deletions.
19 changes: 0 additions & 19 deletions packages/discord.js/src/structures/GuildAuditLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,6 @@ const Integration = require('./Integration');
const Webhook = require('./Webhook');
const { flatten } = require('../util/Util');

/**
* The target type of an entry. Here are the available types:
* * Guild
* * Channel
* * User
* * Role
* * Invite
* * Webhook
* * Emoji
* * Message
* * Integration
* * StageInstance
* * Sticker
* * Thread
* * GuildScheduledEvent
* * ApplicationCommandPermission
* @typedef {string} AuditLogTargetType
*/

/**
* Audit logs entries are held in this class.
*/
Expand Down
76 changes: 74 additions & 2 deletions packages/discord.js/src/structures/GuildAuditLogsEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,78 @@ const Targets = {
* @typedef {string} AuditLogActionType
*/

/**
* The target type of an entry. Here are the available types:
* * Guild
* * Channel
* * User
* * Role
* * Invite
* * Webhook
* * Emoji
* * Message
* * Integration
* * StageInstance
* * Sticker
* * Thread
* * GuildScheduledEvent
* * ApplicationCommandPermission
* @typedef {string} AuditLogTargetType
*/

/**
* The action of an entry. Here are the available actions:
* * GuildUpdate
* * ChannelCreate
* * ChannelUpdate
* * ChannelDelete
* * ChannelOverwriteCreate
* * ChannelOverwriteUpdate
* * ChannelOverwriteDelete
* * MemberKick
* * MemberPrune
* * MemberBanAdd
* * MemberBanRemove
* * MemberUpdate
* * MemberRoleUpdate
* * MemberMove
* * MemberDisconnect
* * BotAdd
* * RoleCreate
* * RoleUpdate
* * RoleDelete
* * InviteCreate
* * InviteUpdate
* * InviteDelete
* * WebhookCreate
* * WebhookUpdate
* * WebhookDelete
* * EmojiCreate
* * EmojiUpdate
* * EmojiDelete
* * MessageDelete
* * MessageBulkDelete
* * MessagePin
* * MessageUnpin
* * IntegrationCreate
* * IntegrationUpdate
* * IntegrationDelete
* * StageInstanceCreate
* * StageInstanceUpdate
* * StageInstanceDelete
* * StickerCreate
* * StickerUpdate
* * StickerDelete
* * GuildScheduledEventCreate
* * GuildScheduledEventUpdate
* * GuildScheduledEventDelete
* * ThreadCreate
* * ThreadUpdate
* * ThreadDelete
* * ApplicationCommandPermissionUpdate
* @typedef {string} AuditLogAction
*/

/**
* Audit logs entry.
*/
Expand Down Expand Up @@ -341,7 +413,7 @@ class GuildAuditLogsEntry {

/**
* Finds the target type of a guild audit log entry.
* @param {AuditLogAction} target The action target.
* @param {AuditLogEvent} target The action target
* @returns {AuditLogTargetType}
*/
static targetType(target) {
Expand All @@ -364,7 +436,7 @@ class GuildAuditLogsEntry {

/**
* Finds the action type from the guild audit log entry action.
* @param {AuditLogAction} action The action target.
* @param {AuditLogEvent} action The action target
* @returns {AuditLogActionType}
*/
static actionType(action) {
Expand Down
10 changes: 5 additions & 5 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ export class GuildAuditLogsEntry<
TActionType extends GuildAuditLogsActionType = TAction extends keyof GuildAuditLogsTypes
? GuildAuditLogsTypes[TAction][1]
: 'All',
TTargetType extends GuildAuditLogsTarget = TAction extends keyof GuildAuditLogsTypes
TTargetType extends GuildAuditLogsTargetType = TAction extends keyof GuildAuditLogsTypes
? GuildAuditLogsTypes[TAction][0]
: 'Unknown',
> {
Expand All @@ -1211,8 +1211,8 @@ export class GuildAuditLogsEntry<
? GuildAuditLogsEntryTargetField<TActionType>[TTargetType]
: Role | GuildEmoji | { id: Snowflake } | null;
public targetType: TTargetType;
public static actionType(action: number): GuildAuditLogsActionType;
public static targetType(target: number): GuildAuditLogsTarget;
public static actionType(action: AuditLogEvent): GuildAuditLogsActionType;
public static targetType(target: AuditLogEvent): GuildAuditLogsTargetType;
public toJSON(): unknown;
}

Expand Down Expand Up @@ -4497,10 +4497,10 @@ export interface GuildAuditLogsFetchOptions<T extends GuildAuditLogsResolvable>

export type GuildAuditLogsResolvable = AuditLogEvent | null;

export type GuildAuditLogsTarget = GuildAuditLogsTypes[keyof GuildAuditLogsTypes][0] | 'All' | 'Unknown';
export type GuildAuditLogsTargetType = GuildAuditLogsTypes[keyof GuildAuditLogsTypes][0] | 'All' | 'Unknown';

export type GuildAuditLogsTargets = {
[key in GuildAuditLogsTarget]: GuildAuditLogsTarget;
[key in GuildAuditLogsTargetType]: GuildAuditLogsTargetType;
};

export type GuildBanResolvable = GuildBan | UserResolvable;
Expand Down

0 comments on commit 4155136

Please sign in to comment.