Merge branch 'main' into builders

This commit is contained in:
Marcos Susaña 2022-07-05 00:03:41 -04:00 committed by GitHub
commit 9ddd9492a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 0 deletions

View File

@ -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<T> = (...args: [Session, number, T]) => void;
export type Handler<T extends unknown[]> = (...args: T) => unknown;
@ -167,6 +171,18 @@ export const WEBHOOKS_UPDATE: RawHandler<DiscordWebhookUpdate> = (session, _shar
session.emit("webhooksUpdate", { guildId: webhook.guild_id, channelId: webhook.channel_id });
};
export const INTEGRATION_CREATE: RawHandler<DiscordIntegration> = (session, _shardId, payload) => {
session.emit("integrationCreate", new Integration(session, payload));
};
export const INTEGRATION_UPDATE: RawHandler<DiscordIntegration> = (session, _shardId, payload) => {
session.emit("integrationCreate", new Integration(session, payload));
};
export const INTEGRATION_DELETE: RawHandler<DiscordIntegrationDelete> = (session, _shardId, payload) => {
session.emit("integrationDelete", { id: payload.id, guildId: payload.guild_id, applicationId: payload.application_id });
};
/*
export const MESSAGE_REACTION_ADD: RawHandler<DiscordMessageReactionAdd> = (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 }]>;
}

55
structures/Integration.ts Normal file
View File

@ -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;
}