From 1e527cd24ca87320e9d76d8ccdac4e55e34956cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Serna?= Date: Mon, 4 Jul 2022 20:54:05 -0300 Subject: [PATCH 1/5] Add Integration structure --- structures/Integration.ts | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 structures/Integration.ts diff --git a/structures/Integration.ts b/structures/Integration.ts new file mode 100644 index 0000000..852cfb3 --- /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?: string }) { + 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?: string; + + 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 From cb20e1f04dee76d4937d315fcafc76c235541819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Serna?= Date: Mon, 4 Jul 2022 21:02:50 -0300 Subject: [PATCH 2/5] Fix Integration account property --- structures/Integration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structures/Integration.ts b/structures/Integration.ts index 852cfb3..4d21059 100644 --- a/structures/Integration.ts +++ b/structures/Integration.ts @@ -50,6 +50,6 @@ export class Integration implements Model { revoked?: boolean; user?: DiscordUser; - account?: DiscordIntegrationAccount; + account: DiscordIntegrationAccount; application?: DiscordIntegrationApplication; } \ No newline at end of file From a36e0915e55dfb866376e8818d9375363cebde97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Serna?= Date: Mon, 4 Jul 2022 21:11:16 -0300 Subject: [PATCH 3/5] Add integrationCreate action --- handlers/Actions.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/handlers/Actions.ts b/handlers/Actions.ts index e1dd524..575f312 100644 --- a/handlers/Actions.ts +++ b/handlers/Actions.ts @@ -25,7 +25,8 @@ import type { // DiscordThreadMemberUpdate, // DiscordThreadMembersUpdate, DiscordThreadListSync, - DiscordWebhookUpdate + DiscordWebhookUpdate, + DiscordIntegration } from "../vendor/external.ts"; import type { Snowflake } from "../util/Snowflake.ts"; import type { Session } from "../session/Session.ts"; @@ -39,6 +40,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 +169,10 @@ 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 MESSAGE_REACTION_ADD: RawHandler = (session, _shardId, reaction) => { session.emit("messageReactionAdd", null); @@ -226,6 +232,7 @@ export interface Events { "threadDelete": Handler<[ThreadChannel]>; "threadListSync": Handler<[{ guildId: Snowflake, channelIds: Snowflake[], threads: ThreadChannel[], members: ThreadMember[] }]> "interactionCreate": Handler<[Interaction]>; + "integrationCreate": Handler<[DiscordIntegration]>; "raw": Handler<[unknown, number]>; "webhooksUpdate": Handler<[{ guildId: Snowflake, channelId: Snowflake }]>; } From c05d8113bd23d6c91d9bcee6b19e00c03cdcdd97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Serna?= Date: Mon, 4 Jul 2022 21:12:39 -0300 Subject: [PATCH 4/5] Update Integration structure --- structures/Integration.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/structures/Integration.ts b/structures/Integration.ts index 4d21059..3514250 100644 --- a/structures/Integration.ts +++ b/structures/Integration.ts @@ -10,7 +10,7 @@ import type { } from "../vendor/external.ts"; export class Integration implements Model { - constructor(session: Session, data: DiscordIntegration & { guild_id?: string }) { + constructor(session: Session, data: DiscordIntegration & { guild_id?: Snowflake }) { this.id = data.id; this.session = session; @@ -35,7 +35,7 @@ export class Integration implements Model { id: Snowflake; session: Session; - guildId?: string; + guildId?: Snowflake; name: string type: "twitch" | "youtube" | "discord"; From 59755f2f6eeff0f21a53304d3471d4ab1b4d5740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Serna?= Date: Mon, 4 Jul 2022 21:53:31 -0300 Subject: [PATCH 5/5] Add integration-Update/Delete action --- handlers/Actions.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/handlers/Actions.ts b/handlers/Actions.ts index 575f312..40afec9 100644 --- a/handlers/Actions.ts +++ b/handlers/Actions.ts @@ -26,7 +26,8 @@ import type { // DiscordThreadMembersUpdate, DiscordThreadListSync, DiscordWebhookUpdate, - DiscordIntegration + DiscordIntegration, + DiscordIntegrationDelete } from "../vendor/external.ts"; import type { Snowflake } from "../util/Snowflake.ts"; import type { Session } from "../session/Session.ts"; @@ -173,6 +174,14 @@ export const INTEGRATION_CREATE: RawHandler = (session, _sha 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); @@ -233,6 +242,8 @@ export interface Events { "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 }]>; }