-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(structures): add AuditLog structure #11402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
keston-dev
wants to merge
5
commits into
discordjs:main
Choose a base branch
from
keston-dev:feat/audit-log-structure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+198
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1824342
feat(structures): add AuditLog structure
keston-dev 018cf18
feat(structures): add AuditLog structure
keston-dev 7955d5d
Merge branch 'main' of https://github.com/discordjs/discord.js into f…
keston-dev 9ad2c77
fix: fix jsdoc and follow proposed xAt structure
keston-dev 5223298
Merge branch 'main' into feat/audit-log-structure
keston-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 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<Omitted extends keyof APIAuditLog | '' = ''> extends Structure<APIAuditLog, Omitted> { | ||
| /** | ||
| * @param data - The raw data received from the API for the audit log. | ||
| */ | ||
| public constructor(data: Partialize<APIAuditLog, Omitted>) { | ||
| super(data); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<Omitted extends keyof APIAuditLogEntry | '' = ''> extends Structure< | ||
| APIAuditLogEntry, | ||
| Omitted | ||
| > { | ||
| /** | ||
| * @param data - The raw data received from the API for the audit log entry. | ||
| */ | ||
| public constructor(data: Partialize<APIAuditLogEntry, Omitted>) { | ||
| 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 date the entry was created at. | ||
| */ | ||
| public get createdDate() { | ||
| const createdTimestamp = this.createdTimestamp; | ||
| return createdTimestamp ? new Date(createdTimestamp) : null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| 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<Omitted extends keyof APIAuditLogOptions | '' = ''> extends Structure< | ||
| APIAuditLogOptions, | ||
| Omitted | ||
| > { | ||
| /** | ||
| * @param data - The raw data received from the API for the audit log options. | ||
| */ | ||
| public constructor(data: Partialize<APIAuditLogOptions, Omitted>) { | ||
| 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 id of 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. | ||
| * | ||
| * @remarks 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export * from './AuditLog.js'; | ||
| export * from './AuditLogEntry.js'; | ||
| export * from './AuditLogOptions.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AuditLogChangeshould be a substructure too and is missing completely