From 182434277074b594e00bdaaeac9b7ab278b89e03 Mon Sep 17 00:00:00 2001 From: Conrad306 Date: Sun, 25 Jan 2026 01:04:08 -0500 Subject: [PATCH 1/3] feat(structures): add AuditLog structure --- .../structures/src/auditlog/AuditLogEntry.ts | 75 +++++++++++++ .../src/auditlog/AuditLogOptions.ts | 100 ++++++++++++++++++ packages/structures/src/auditlog/index.ts | 2 + packages/structures/src/index.ts | 1 + 4 files changed, 178 insertions(+) create mode 100644 packages/structures/src/auditlog/AuditLogEntry.ts create mode 100644 packages/structures/src/auditlog/AuditLogOptions.ts create mode 100644 packages/structures/src/auditlog/index.ts diff --git a/packages/structures/src/auditlog/AuditLogEntry.ts b/packages/structures/src/auditlog/AuditLogEntry.ts new file mode 100644 index 000000000000..0df323953260 --- /dev/null +++ b/packages/structures/src/auditlog/AuditLogEntry.ts @@ -0,0 +1,75 @@ +import { DiscordSnowflake } from '@sapphire/snowflake'; +import type { APIAuditLogEntry } from 'discord-api-types/v10'; +import { Structure } from '../Structure'; +import { kData } from '../utils/symbols'; +import { isIdSet } from '../utils/type-guards'; +import type { Partialize } from '../utils/types'; + +/** + * Represents an audit log entry on Discord. + * + * @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate` + * @remarks Intentionally does not export `changes` so that extending classes can resolve array to `AuditLogChange[]` + * @remarks Has substructure `AuditLogOptions`, which needs to be instantiated and stored by an extending class using it. + */ +export class AuditLogEntry extends Structure< + APIAuditLogEntry, + Omitted +> { + /** + * @param data - The raw data received from the API for the audit log entry. + */ + public constructor(data: Partialize) { + super(data); + } + + /** + * The id of the affected entity (webhook, user, role, etc.) + */ + public get targetId() { + return this[kData].target_id; + } + + /** + * The user or app that made the changes. + */ + public get userId() { + return this[kData].user_id; + } + + /** + * The id of the entry. + */ + public get id() { + return this[kData].id; + } + + /** + * The type of action that occurred. + */ + public get actionType() { + return this[kData].action_type; + } + + /** + * The reason for the change (0-512 characters) + */ + public get reason() { + return this[kData].reason; + } + + /** + * The timestamp the entry was created at. + */ + public get createdTimestamp() { + return isIdSet(this.id) ? DiscordSnowflake.timestampFrom(this.id) : null; + } + + /** + * The time the entry was created at. + */ + public get createdAt() { + const createdTimestamp = this.createdTimestamp; + return createdTimestamp ? new Date(createdTimestamp) : null; + } +} diff --git a/packages/structures/src/auditlog/AuditLogOptions.ts b/packages/structures/src/auditlog/AuditLogOptions.ts new file mode 100644 index 000000000000..f7954a38dfbb --- /dev/null +++ b/packages/structures/src/auditlog/AuditLogOptions.ts @@ -0,0 +1,100 @@ +/* eslint-disable tsdoc/syntax */ +import type { APIAuditLogOptions } from 'discord-api-types/v10'; +import { Structure } from '../Structure'; +import { kData } from '../utils/symbols'; +import type { Partialize } from '../utils/types'; + +/** + * Represents the audit log options on Discord. + * + * @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate` + */ +export class AuditLogOptions extends Structure< + APIAuditLogOptions, + Omitted +> { + /** + * @param data - The raw data received from the API for the audit log entry. + */ + public constructor(data: Partialize) { + super(data); + } + + /** + * Name of the auto moderation rule that was triggered. + */ + public get autoModerationRuleName() { + return this[kData].auto_moderation_rule_name; + } + + /** + * Trigger type of the auto moderation rule that was triggered. + */ + public get autoModerationRuleTriggerType() { + return this[kData].auto_moderation_rule_trigger_type; + } + + /** + * The channel in which the entities were targeted. + */ + public get channelId() { + return this[kData].channel_id; + } + + /** + * The number of entities that were targeted. + */ + public get count() { + return this[kData].count; + } + + /** + * Number of days after which inactive members were kicked. + */ + public get deleteMemberDays() { + return this[kData].delete_member_days; + } + + /** + * The id of the overwritten entity. + */ + public get id() { + return this[kData].id; + } + + /** + * The number of members removed by the prune. + */ + public get membersRemoved() { + return this[kData].members_removed; + } + + /** + * The id of the message that was targeted. + */ + public get messageId() { + return this[kData].message_id; + } + + /** + * Name of the role. + * #### Only present if the {@link AuditLogOptions.type} is set to `0` + */ + public get roleName() { + return this[kData].role_name; + } + + /** + * The type of overwritten entity - `"0"` for `role` or `"1"` for `member` + */ + public get type() { + return this[kData].type; + } + + /** + * The type of integration which performed the action. + */ + public get integrationType() { + return this[kData].integration_type; + } +} diff --git a/packages/structures/src/auditlog/index.ts b/packages/structures/src/auditlog/index.ts new file mode 100644 index 000000000000..f9720a250f77 --- /dev/null +++ b/packages/structures/src/auditlog/index.ts @@ -0,0 +1,2 @@ +export * from './AuditLogEntry.js'; +export * from './AuditLogOptions.js'; diff --git a/packages/structures/src/index.ts b/packages/structures/src/index.ts index d294ceeeaa38..579f6e4203b9 100644 --- a/packages/structures/src/index.ts +++ b/packages/structures/src/index.ts @@ -1,3 +1,4 @@ +export * from './auditlog/index.js'; export * from './automoderation/index.js'; export * from './bitfields/index.js'; export * from './channels/index.js'; From 018cf18d6ada3b051365886ff3e9144eb41e708f Mon Sep 17 00:00:00 2001 From: keston-dev Date: Sun, 25 Jan 2026 10:04:06 -0500 Subject: [PATCH 2/3] feat(structures): add AuditLog structure --- packages/structures/src/auditlog/AuditLog.ts | 19 +++++++++++++++++++ .../src/auditlog/AuditLogOptions.ts | 2 +- packages/structures/src/auditlog/index.ts | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 packages/structures/src/auditlog/AuditLog.ts diff --git a/packages/structures/src/auditlog/AuditLog.ts b/packages/structures/src/auditlog/AuditLog.ts new file mode 100644 index 000000000000..18bfdf74b23e --- /dev/null +++ b/packages/structures/src/auditlog/AuditLog.ts @@ -0,0 +1,19 @@ +import type { APIAuditLog } from 'discord-api-types/v10'; +import { Structure } from '../Structure'; +import type { Partialize } from '../utils/types'; + +/** + * Represents an audit log on Discord. + * + * @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate` + * @remarks Intentionally does not export `application_commands`, `audit_log_entries`, `auto_moderation_rules`, `guild_scheduled_events`, `integrations`, `threads`, `users`, and `webhooks`, + * so that extending classes can resolve objects to `ApplicationCommand[]`, `AuditLogEntry[]`, `AutoModerationRule[]`, `GuildScheduledEvent[]`, `GuildIntegration[]`, `ThreadChannel[]`, `User[]`, and `Webhook[]`, respectively. + */ +export class AuditLog extends Structure { + /** + * @param data - The raw data received from the API for the audit log. + */ + public constructor(data: Partialize) { + super(data); + } +} diff --git a/packages/structures/src/auditlog/AuditLogOptions.ts b/packages/structures/src/auditlog/AuditLogOptions.ts index f7954a38dfbb..bc4bc2b864ea 100644 --- a/packages/structures/src/auditlog/AuditLogOptions.ts +++ b/packages/structures/src/auditlog/AuditLogOptions.ts @@ -14,7 +14,7 @@ export class AuditLogOptions Omitted > { /** - * @param data - The raw data received from the API for the audit log entry. + * @param data - The raw data received from the API for the audit log options. */ public constructor(data: Partialize) { super(data); diff --git a/packages/structures/src/auditlog/index.ts b/packages/structures/src/auditlog/index.ts index f9720a250f77..7c963ea26d9b 100644 --- a/packages/structures/src/auditlog/index.ts +++ b/packages/structures/src/auditlog/index.ts @@ -1,2 +1,3 @@ +export * from './AuditLog.js'; export * from './AuditLogEntry.js'; export * from './AuditLogOptions.js'; From 9ad2c77e4f04af06f49a2a7e3579fe23f29ad033 Mon Sep 17 00:00:00 2001 From: keston-dev Date: Sat, 21 Feb 2026 12:25:48 -0500 Subject: [PATCH 3/3] fix: fix jsdoc and follow proposed xAt structure --- packages/structures/src/auditlog/AuditLog.ts | 4 ++-- packages/structures/src/auditlog/AuditLogEntry.ts | 4 ++-- packages/structures/src/auditlog/AuditLogOptions.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/structures/src/auditlog/AuditLog.ts b/packages/structures/src/auditlog/AuditLog.ts index 18bfdf74b23e..d764b41f581e 100644 --- a/packages/structures/src/auditlog/AuditLog.ts +++ b/packages/structures/src/auditlog/AuditLog.ts @@ -6,8 +6,8 @@ import type { Partialize } from '../utils/types'; * Represents an audit log on Discord. * * @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate` - * @remarks Intentionally does not export `application_commands`, `audit_log_entries`, `auto_moderation_rules`, `guild_scheduled_events`, `integrations`, `threads`, `users`, and `webhooks`, - * so that extending classes can resolve objects to `ApplicationCommand[]`, `AuditLogEntry[]`, `AutoModerationRule[]`, `GuildScheduledEvent[]`, `GuildIntegration[]`, `ThreadChannel[]`, `User[]`, and `Webhook[]`, respectively. + * @remarks Has substructures `ApplicationCommand`, `AuditLogEntry`, `AutoModerationRule`, `GuildScheduledEvent`, `GuildIntegration`, `ThreadChannel`, `User`, and `Webhook`, + * which need to be instantiated and stored by an extending class using it */ export class AuditLog extends Structure { /** diff --git a/packages/structures/src/auditlog/AuditLogEntry.ts b/packages/structures/src/auditlog/AuditLogEntry.ts index 0df323953260..ba3cd6ba84f6 100644 --- a/packages/structures/src/auditlog/AuditLogEntry.ts +++ b/packages/structures/src/auditlog/AuditLogEntry.ts @@ -66,9 +66,9 @@ export class AuditLogEntry ext } /** - * The time the entry was created at. + * The date the entry was created at. */ - public get createdAt() { + public get createdDate() { const createdTimestamp = this.createdTimestamp; return createdTimestamp ? new Date(createdTimestamp) : null; } diff --git a/packages/structures/src/auditlog/AuditLogOptions.ts b/packages/structures/src/auditlog/AuditLogOptions.ts index bc4bc2b864ea..c96cb4615ad0 100644 --- a/packages/structures/src/auditlog/AuditLogOptions.ts +++ b/packages/structures/src/auditlog/AuditLogOptions.ts @@ -1,4 +1,3 @@ -/* eslint-disable tsdoc/syntax */ import type { APIAuditLogOptions } from 'discord-api-types/v10'; import { Structure } from '../Structure'; import { kData } from '../utils/symbols'; @@ -35,7 +34,7 @@ export class AuditLogOptions } /** - * The channel in which the entities were targeted. + * The id of the channel in which the entities were targeted. */ public get channelId() { return this[kData].channel_id; @@ -78,7 +77,8 @@ export class AuditLogOptions /** * Name of the role. - * #### Only present if the {@link AuditLogOptions.type} is set to `0` + * + * @remarks Only present if the {@link AuditLogOptions.type} is set to `0` */ public get roleName() { return this[kData].role_name;