Audit Log Entry Event (#2719)

* Create GUILD_AUDIT_LOG_ENTRY_CREATE.ts

* Update mod.ts

* Update bot.ts

* Update GUILD_AUDIT_LOG_ENTRY_CREATE.ts

* Update shared.ts
This commit is contained in:
Skillz4Killz
2023-01-12 17:46:05 -06:00
committed by GitHub
parent c888bb9cf1
commit 945b1f2007
3 changed files with 13 additions and 0 deletions

4
bot.ts
View File

@@ -230,6 +230,7 @@ export function createEventHandlers(
return {
debug: events.debug ?? ignore,
auditLogEntryCreate: events.auditLogEntryCreate ?? ignore,
automodRuleCreate: events.automodRuleCreate ?? ignore,
automodRuleUpdate: events.automodRuleUpdate ?? ignore,
automodRuleDelete: events.automodRuleDelete ?? ignore,
@@ -550,6 +551,7 @@ export function createTransformers(options: Partial<Transformers>) {
export interface EventHandlers {
debug: (text: string, ...args: any[]) => unknown;
auditLogEntryCreate: (bot: Bot, log: AuditLogEntry, guildId: bigint) => unknown;
automodRuleCreate: (bot: Bot, rule: AutoModerationRule) => unknown;
automodRuleUpdate: (bot: Bot, rule: AutoModerationRule) => unknown;
automodRuleDelete: (bot: Bot, rule: AutoModerationRule) => unknown;
@@ -800,6 +802,7 @@ export interface BotGatewayHandlerOptions {
STAGE_INSTANCE_CREATE: typeof handlers.handleStageInstanceCreate;
STAGE_INSTANCE_UPDATE: typeof handlers.handleStageInstanceUpdate;
STAGE_INSTANCE_DELETE: typeof handlers.handleStageInstanceDelete;
GUILD_AUDIT_LOG_ENTRY_CREATE: typeof handlers.handleGuildAuditLogEntryCreate;
GUILD_BAN_ADD: typeof handlers.handleGuildBanAdd;
GUILD_BAN_REMOVE: typeof handlers.handleGuildBanRemove;
GUILD_CREATE: typeof handlers.handleGuildCreate;
@@ -869,6 +872,7 @@ export function createBotGatewayHandlers(
handlers.handleStageInstanceDelete,
// guilds
GUILD_AUDIT_LOG_ENTRY_CREATE: options.GUILD_AUDIT_LOG_ENTRY_CREATE ?? handlers.handleGuildAuditLogEntryCreate,
GUILD_BAN_ADD: options.GUILD_BAN_ADD ?? handlers.handleGuildBanAdd,
GUILD_BAN_REMOVE: options.GUILD_BAN_REMOVE ?? handlers.handleGuildBanRemove,
GUILD_CREATE: options.GUILD_CREATE ?? handlers.handleGuildCreate,

View File

@@ -0,0 +1,8 @@
import type { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordAuditLogEntry } from "../../types/discord.ts";
export async function handleGuildAuditLogEntryCreate(bot: Bot, data: DiscordGatewayPayload) {
// TODO: better type here
const payload = data.d as DiscordAuditLogEntry & { guild_id: string };
bot.events.auditLogEntryCreate(bot, bot.transformers.auditLogEntry(bot, payload), bot.transformers.snowflake(payload.guild_id));
}

View File

@@ -1,5 +1,6 @@
export * from "./scheduledEvents/mod.ts";
export * from "./GUILD_AUDIT_LOG_ENTRY_CREATE.ts";
export * from "./GUILD_BAN_ADD.ts";
export * from "./GUILD_BAN_REMOVE.ts";
export * from "./GUILD_CREATE.ts";