Skip to content

Commit 5b86dbb

Browse files
authored
Merge pull request #341 from Blockzilla101/add-events
feat: add audit log create event
2 parents 637edf5 + 715110e commit 5b86dbb

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Guild } from '../../../mod.ts'
2+
import { transformAuditLogEntryPayload } from '../../structures/guild.ts'
3+
import { GuildAuditLogEntryCreatePayload } from '../../types/gateway.ts'
4+
import type { Gateway, GatewayEventHandler } from '../mod.ts'
5+
6+
export const guildAuditLogEntryCreate: GatewayEventHandler = async (
7+
gateway: Gateway,
8+
d: GuildAuditLogEntryCreatePayload
9+
) => {
10+
const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id)
11+
if (guild != null) {
12+
const entry = transformAuditLogEntryPayload(d)
13+
gateway.client.emit('guildAuditLogEntryCreate', guild, entry)
14+
}
15+
}

src/gateway/handlers/mod.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import type { Interaction } from '../../structures/interactions.ts'
6363
import type { CommandContext, ParsedCommand } from '../../commands/command.ts'
6464
import type { RequestMethods } from '../../rest/types.ts'
6565
import type { PartialInvitePayload } from '../../types/invite.ts'
66-
import type { GuildChannels } from '../../types/guild.ts'
66+
import type { AuditLogEntry, GuildChannels } from '../../types/guild.ts'
6767
import type {
6868
ThreadChannel,
6969
ThreadMember
@@ -76,6 +76,7 @@ import { threadMemberUpdate } from './threadMemberUpdate.ts'
7676
import { threadListSync } from './threadListSync.ts'
7777
import { guildStickersUpdate } from './guildStickersUpdate.ts'
7878
import { MessageSticker } from '../../structures/messageSticker.ts'
79+
import { guildAuditLogEntryCreate } from './guildAuditLogEntryCreate.ts'
7980

8081
export const gatewayHandlers: {
8182
[eventCode in GatewayEvents]: GatewayEventHandler | undefined
@@ -124,7 +125,8 @@ export const gatewayHandlers: {
124125
THREAD_LIST_SYNC: threadListSync,
125126
THREAD_MEMBERS_UPDATE: threadMembersUpdate,
126127
THREAD_MEMBER_UPDATE: threadMemberUpdate,
127-
GUILD_STICKERS_UPDATE: guildStickersUpdate
128+
GUILD_STICKERS_UPDATE: guildStickersUpdate,
129+
GUILD_AUDIT_LOG_ENTRY_CREATE: guildAuditLogEntryCreate
128130
}
129131

130132
export interface VoiceServerUpdateData {
@@ -177,6 +179,12 @@ export type ClientEvents = {
177179
* @param user The User who was banned
178180
*/
179181
guildBanAdd: [guild: Guild, user: User]
182+
/**
183+
* A new audit log entry was created
184+
* @param guild The guild in which the entry was created
185+
* @param entry The entry that was created
186+
*/
187+
guildAuditLogEntryCreate: [guild: Guild, entry: AuditLogEntry]
180188
/**
181189
* A ban from a User in Guild was elevated
182190
* @param guild Guild from which ban was removed

src/structures/guild.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,8 @@ export class GuildIntegration extends Base {
732732
}
733733
}
734734

735-
function transformAuditLogEntryPayload(d: AuditLogEntryPayload): AuditLogEntry {
735+
export function transformAuditLogEntryPayload(
736+
d: AuditLogEntryPayload
737+
): AuditLogEntry {
736738
return toCamelCase(d)
737739
}

src/types/gateway.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
import type { Guild } from '../structures/guild.ts'
44
import type { Member } from '../structures/member.ts'
55
import type { EmojiPayload } from './emoji.ts'
6-
import type { GuildPayload, MemberPayload } from './guild.ts'
6+
import type {
7+
AuditLogEntryPayload,
8+
GuildPayload,
9+
MemberPayload
10+
} from './guild.ts'
711
import type {
812
ActivityGame,
913
ActivityPayload,
@@ -53,7 +57,9 @@ export enum GatewayCloseCodes {
5357
export enum GatewayIntents {
5458
GUILDS = 1 << 0,
5559
GUILD_MEMBERS = 1 << 1,
60+
/** @deprecated Use GUILD_MODERATION instead */
5661
GUILD_BANS = 1 << 2,
62+
GUILD_MODERATION = 1 << 2,
5763
/** @deprecated Use GUILD_EMOJIS_AND_STICKERS instead */
5864
GUILD_EMOJIS = 1 << 3,
5965
GUILD_EMOJIS_AND_STICKERS = 1 << 3,
@@ -84,6 +90,7 @@ export enum GatewayEvents {
8490
Guild_Delete = 'GUILD_DELETE',
8591
Guild_Ban_Add = 'GUILD_BAN_ADD',
8692
Guild_Ban_Remove = 'GUILD_BAN_REMOVE',
93+
Guild_Audit_Log_Entry_Create = 'GUILD_AUDIT_LOG_ENTRY_CREATE',
8794
Guild_Emojis_Update = 'GUILD_EMOJIS_UPDATE',
8895
Guild_Stickers_Update = 'GUILD_STICKERS_UPDATE',
8996
Guild_Integrations_Update = 'GUILD_INTEGRATIONS_UPDATE',
@@ -198,6 +205,10 @@ export interface GuildBanRemovePayload {
198205
user: UserPayload
199206
}
200207

208+
export interface GuildAuditLogEntryCreatePayload extends AuditLogEntryPayload {
209+
guild_id: string
210+
}
211+
201212
export interface GuildEmojiUpdatePayload {
202213
guild_id: string
203214
emojis: EmojiPayload[]

0 commit comments

Comments
 (0)