diff --git a/handlers/Actions.ts b/handlers/Actions.ts index a5cf1e8..8d302e5 100644 --- a/handlers/Actions.ts +++ b/handlers/Actions.ts @@ -26,6 +26,9 @@ import type { DiscordThreadListSync, DiscordUser, DiscordWebhookUpdate, + DiscordIntegration, + DiscordIntegrationDelete + } from "../vendor/external.ts"; import type { Snowflake } from "../util/Snowflake.ts"; import type { Session } from "../session/Session.ts"; @@ -39,6 +42,7 @@ import Message from "../structures/Message.ts"; import User from "../structures/User.ts"; import Guild from "../structures/guilds/Guild.ts"; import Interaction from "../structures/interactions/Interaction.ts"; +import { Integration } from "../structures/Integration.ts" export type RawHandler = (...args: [Session, number, T]) => void; export type Handler = (...args: T) => unknown; @@ -167,6 +171,18 @@ export const WEBHOOKS_UPDATE: RawHandler = (session, _shar session.emit("webhooksUpdate", { guildId: webhook.guild_id, channelId: webhook.channel_id }); }; +export const INTEGRATION_CREATE: RawHandler = (session, _shardId, payload) => { + session.emit("integrationCreate", new Integration(session, payload)); +}; + +export const INTEGRATION_UPDATE: RawHandler = (session, _shardId, payload) => { + session.emit("integrationCreate", new Integration(session, payload)); +}; + +export const INTEGRATION_DELETE: RawHandler = (session, _shardId, payload) => { + session.emit("integrationDelete", { id: payload.id, guildId: payload.guild_id, applicationId: payload.application_id }); +}; + /* export const MESSAGE_REACTION_ADD: RawHandler = (session, _shardId, reaction) => { session.emit("messageReactionAdd", null); @@ -226,6 +242,9 @@ export interface Events { "threadDelete": Handler<[ThreadChannel]>; "threadListSync": Handler<[{ guildId: Snowflake, channelIds: Snowflake[], threads: ThreadChannel[], members: ThreadMember[] }]> "interactionCreate": Handler<[Interaction]>; + "integrationCreate": Handler<[DiscordIntegration]>; + "integrationUpdate": Handler<[DiscordIntegration]>; + "integrationDelete": Handler<[{ id: Snowflake, guildId?: Snowflake, applicationId?: Snowflake }]>; "raw": Handler<[unknown, number]>; "webhooksUpdate": Handler<[{ guildId: Snowflake, channelId: Snowflake }]>; } diff --git a/structures/Integration.ts b/structures/Integration.ts new file mode 100644 index 0000000..3514250 --- /dev/null +++ b/structures/Integration.ts @@ -0,0 +1,55 @@ +import type { Model } from "./Base.ts"; +import type { Snowflake } from "../util/Snowflake.ts"; +import type { Session } from "../session/Session.ts"; +import type { + DiscordIntegration, + DiscordIntegrationAccount, + DiscordIntegrationApplication, + DiscordUser, + IntegrationExpireBehaviors +} from "../vendor/external.ts"; + +export class Integration implements Model { + constructor(session: Session, data: DiscordIntegration & { guild_id?: Snowflake }) { + this.id = data.id; + this.session = session; + + data.guild_id ? this.guildId = data.guild_id : null; + + this.name = data.name; + this.type = data.type; + this.enabled = !!data.enabled; + this.syncing = !!data.syncing; + this.roleId = data.role_id; + this.enableEmoticons = !!data.enable_emoticons; + this.expireBehavior = data.expire_behavior; + this.expireGracePeriod = data.expire_grace_period; + this.syncedAt = data.synced_at; + this.subscriberCount = data.subscriber_count; + this.revoked = !!data.revoked; + + this.user = data.user; + this.account = data.account; + this.application = data.application; + } + + id: Snowflake; + session: Session; + guildId?: Snowflake; + + name: string + type: "twitch" | "youtube" | "discord"; + enabled?: boolean; + syncing?: boolean; + roleId?: string; + enableEmoticons?: boolean; + expireBehavior?: IntegrationExpireBehaviors; + expireGracePeriod?: number; + syncedAt?: string; + subscriberCount?: number; + revoked?: boolean; + + user?: DiscordUser; + account: DiscordIntegrationAccount; + application?: DiscordIntegrationApplication; +} \ No newline at end of file