From 59633b8ed60c51011576dcb050d7959b45065c1a Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 6 Apr 2021 21:40:03 +0200 Subject: [PATCH] f --- .../integrations/INTEGRATION_CREATE.ts | 29 ++++++------------- .../integrations/INTEGRATION_DELETE.ts | 19 ++++++------ .../integrations/INTEGRATION_UPDATE.ts | 29 ++++++------------- 3 files changed, 27 insertions(+), 50 deletions(-) diff --git a/src/handlers/integrations/INTEGRATION_CREATE.ts b/src/handlers/integrations/INTEGRATION_CREATE.ts index 4148db518..255df04c1 100644 --- a/src/handlers/integrations/INTEGRATION_CREATE.ts +++ b/src/handlers/integrations/INTEGRATION_CREATE.ts @@ -1,28 +1,17 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import { + DiscordIntegrationCreateUpdate, + IntegrationCreateUpdate, +} from "../../types/integration/integration_create_update.ts"; +import { snakeKeysToCamelCase } from "../../util/utils.ts"; export function handleIntegrationCreate( data: DiscordGatewayPayload, ) { - const { - guild_id: guildId, - enable_emoticons: enableEmoticons, - expire_behavior: expireBehavior, - expire_grace_period: expireGracePeriod, - subscriber_count: subscriberCount, - role_id: roleId, - synced_at: syncedAt, - ...rest - } = data.d as IntegrationCreateUpdateEvent; + const payload = data.d as DiscordIntegrationCreateUpdate; - eventHandlers.integrationCreate?.({ - ...rest, - guildId, - enableEmoticons, - expireBehavior, - expireGracePeriod, - syncedAt, - subscriberCount, - roleId, - }); + eventHandlers.integrationCreate?.( + snakeKeysToCamelCase(payload) as IntegrationCreateUpdate, + ); } diff --git a/src/handlers/integrations/INTEGRATION_DELETE.ts b/src/handlers/integrations/INTEGRATION_DELETE.ts index c89ae3d3b..af1ed9d15 100644 --- a/src/handlers/integrations/INTEGRATION_DELETE.ts +++ b/src/handlers/integrations/INTEGRATION_DELETE.ts @@ -1,16 +1,15 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import { + DiscordIntegrationDelete, + IntegrationDelete, +} from "../../types/integration/integration_delete.ts"; +import { snakeKeysToCamelCase } from "../../util/utils.ts"; export function handleIntegrationDelete(data: DiscordGatewayPayload) { - const { - guild_id: guildId, - application_id: applicationId, - ...rest - } = data.d as IntegrationDeleteEvent; + const payload = data.d as DiscordIntegrationDelete; - eventHandlers.integrationDelete?.({ - ...rest, - applicationId, - guildId, - }); + eventHandlers.integrationDelete?.( + snakeKeysToCamelCase(payload) as IntegrationDelete, + ); } diff --git a/src/handlers/integrations/INTEGRATION_UPDATE.ts b/src/handlers/integrations/INTEGRATION_UPDATE.ts index 13fb98bed..db56de2cd 100644 --- a/src/handlers/integrations/INTEGRATION_UPDATE.ts +++ b/src/handlers/integrations/INTEGRATION_UPDATE.ts @@ -1,26 +1,15 @@ import { eventHandlers } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; +import { + DiscordIntegrationCreateUpdate, + IntegrationCreateUpdate, +} from "../../types/integration/integration_create_update.ts"; +import { snakeKeysToCamelCase } from "../../util/utils.ts"; export function handleIntegrationUpdate(data: DiscordGatewayPayload) { - const { - enable_emoticons: enableEmoticons, - expire_behavior: expireBehavior, - expire_grace_period: expireGracePeriod, - role_id: roleId, - subscriber_count: subscriberCount, - synced_at: syncedAt, - guild_id: guildId, - ...rest - } = data.d as IntegrationCreateUpdateEvent; + const payload = data.d as DiscordIntegrationCreateUpdate; - eventHandlers.integrationUpdate?.({ - ...rest, - guildId, - subscriberCount, - enableEmoticons, - expireGracePeriod, - roleId, - expireBehavior, - syncedAt, - }); + eventHandlers.integrationUpdate?.( + snakeKeysToCamelCase(payload) as IntegrationCreateUpdate, + ); }