diff --git a/src/bot.ts b/src/bot.ts index 431abed1a..cf9374bd0 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -1,6 +1,6 @@ import { getGatewayBot } from "./helpers/misc/get_gateway_bot.ts"; import { rest } from "./rest/rest.ts"; -import type { EventHandlers } from "./types/discordeno/eventHandlers.ts"; +import type { EventHandlers } from "./types/discordeno/event_handlers.ts"; import { DiscordGatewayIntents } from "./types/gateway/gateway_intents.ts"; import { snowflakeToBigint } from "./util/bigint.ts"; import { GATEWAY_VERSION } from "./util/constants.ts"; diff --git a/src/handlers/channels/STAGE_INSTANCE_CREATE.ts b/src/handlers/channels/STAGE_INSTANCE_CREATE.ts new file mode 100644 index 000000000..d99387dc5 --- /dev/null +++ b/src/handlers/channels/STAGE_INSTANCE_CREATE.ts @@ -0,0 +1,7 @@ +import { eventHandlers } from "../../bot.ts"; +import type { StageInstance } from "../../types/channels/stage_instance.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; + +export function handleStageInstanceCreate(data: DiscordGatewayPayload) { + eventHandlers.stageInstanceCreate?.(data.d as StageInstance); +} diff --git a/src/handlers/channels/STAGE_INSTANCE_DELETE.ts b/src/handlers/channels/STAGE_INSTANCE_DELETE.ts new file mode 100644 index 000000000..43e765ba2 --- /dev/null +++ b/src/handlers/channels/STAGE_INSTANCE_DELETE.ts @@ -0,0 +1,7 @@ +import { eventHandlers } from "../../bot.ts"; +import type { StageInstance } from "../../types/channels/stage_instance.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; + +export function handleStageInstanceDelete(data: DiscordGatewayPayload) { + eventHandlers.stageInstanceDelete?.(data.d as StageInstance); +} diff --git a/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts b/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts new file mode 100644 index 000000000..d0cf177bf --- /dev/null +++ b/src/handlers/channels/STAGE_INSTANCE_UPDATE.ts @@ -0,0 +1,7 @@ +import { eventHandlers } from "../../bot.ts"; +import type { StageInstance } from "../../types/channels/stage_instance.ts"; +import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; + +export function handleStageInstanceUpdate(data: DiscordGatewayPayload) { + eventHandlers.stageInstanceUpdate?.(data.d as StageInstance); +} diff --git a/src/handlers/mod.ts b/src/handlers/mod.ts index 169e79d21..9155ffdb6 100644 --- a/src/handlers/mod.ts +++ b/src/handlers/mod.ts @@ -2,6 +2,9 @@ import { handleChannelCreate } from "./channels/CHANNEL_CREATE.ts"; import { handleChannelDelete } from "./channels/CHANNEL_DELETE.ts"; import { handleChannelPinsUpdate } from "./channels/CHANNEL_PINS_UPDATE.ts"; import { handleChannelUpdate } from "./channels/CHANNEL_UPDATE.ts"; +import { handleStageInstanceCreate } from "./channels/STAGE_INSTANCE_CREATE.ts"; +import { handleStageInstanceUpdate } from "./channels/STAGE_INSTANCE_UPDATE.ts"; +import { handleStageInstanceDelete } from "./channels/STAGE_INSTANCE_DELETE.ts"; import { handleThreadCreate } from "./channels/THREAD_CREATE.ts"; import { handleThreadDelete } from "./channels/THREAD_DELETE.ts"; import { handleThreadListSync } from "./channels/THREAD_LIST_SYNC.ts"; @@ -83,6 +86,9 @@ export { handleMessageUpdate, handlePresenceUpdate, handleReady, + handleStageInstanceCreate, + handleStageInstanceDelete, + handleStageInstanceUpdate, handleThreadCreate, handleThreadDelete, handleThreadListSync, @@ -110,6 +116,10 @@ export let handlers = { THREAD_LIST_SYNC: handleThreadListSync, THREAD_MEMBER_UPDATE: handleThreadMemberUpdate, THREAD_MEMBERS_UPDATE: handleThreadMembersUpdate, + STAGE_INSTANCE_CREATE: handleStageInstanceCreate, + STAGE_INSTANCE_UPDATE: handleStageInstanceUpdate, + STAGE_INSTANCE_DELETE: handleStageInstanceDelete, + // commands APPLICATION_COMMAND_CREATE: handleApplicationCommandCreate, APPLICATION_COMMAND_DELETE: handleApplicationCommandDelete, diff --git a/src/handlers/roles/GUILD_ROLE_CREATE.ts b/src/handlers/roles/GUILD_ROLE_CREATE.ts index c8801e2ce..1cae6d396 100644 --- a/src/handlers/roles/GUILD_ROLE_CREATE.ts +++ b/src/handlers/roles/GUILD_ROLE_CREATE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import type { GuildRoleCreate } from "../../types/mod.ts"; +import type { GuildRoleCreate } from "../../types/guilds/guild_role_create.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildRoleCreate(data: DiscordGatewayPayload) { diff --git a/src/handlers/roles/GUILD_ROLE_UPDATE.ts b/src/handlers/roles/GUILD_ROLE_UPDATE.ts index e3c1b445f..6ee6f7cba 100644 --- a/src/handlers/roles/GUILD_ROLE_UPDATE.ts +++ b/src/handlers/roles/GUILD_ROLE_UPDATE.ts @@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { structures } from "../../structures/mod.ts"; import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; -import type { GuildRoleUpdate } from "../../types/mod.ts"; +import type { GuildRoleUpdate } from "../../types/guilds/guild_role_update.ts"; import { snowflakeToBigint } from "../../util/bigint.ts"; export async function handleGuildRoleUpdate(data: DiscordGatewayPayload) { diff --git a/src/helpers/channels/delete_channel.ts b/src/helpers/channels/delete_channel.ts index ed443c78a..a6b0fc5e2 100644 --- a/src/helpers/channels/delete_channel.ts +++ b/src/helpers/channels/delete_channel.ts @@ -1,7 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { Errors } from "../../types/discordeno/errors.ts"; -import { ChannelTypes } from "../../types/mod.ts"; +import { ChannelTypes } from "../../types/channels/channel_types.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/channels/threads/add_to_thread.ts b/src/helpers/channels/threads/add_to_thread.ts index c38ce9ebe..aa5d3f1e5 100644 --- a/src/helpers/channels/threads/add_to_thread.ts +++ b/src/helpers/channels/threads/add_to_thread.ts @@ -1,6 +1,7 @@ import { cacheHandlers } from "../../../cache.ts"; import { rest } from "../../../rest/rest.ts"; -import { ChannelTypes, Errors } from "../../../types/mod.ts"; +import { ChannelTypes } from "../../../types/channels/channel_types.ts"; +import { Errors } from "../../../types/discordeno/errors.ts"; import { endpoints } from "../../../util/constants.ts"; //TODO(threads): this does not work rn /** Adds the current user to a thread. Returns a 204 empty response on success. Also requires the thread is not archived. Fires a Thread Members Update Gateway event.Adds another user to a thread. Requires the ability to send messages in the thread. Also requires the thread is not archived. Returns a 204 empty response on success. Fires a Thread Members Update Gateway event. diff --git a/src/helpers/guilds/get_welcome_screen.ts b/src/helpers/guilds/get_welcome_screen.ts index 2b20e2826..22a570e6a 100644 --- a/src/helpers/guilds/get_welcome_screen.ts +++ b/src/helpers/guilds/get_welcome_screen.ts @@ -1,5 +1,5 @@ import { rest } from "../../rest/rest.ts"; -import type { WelcomeScreen } from "../../types/mod.ts"; +import type { WelcomeScreen } from "../../types/guilds/welcome_screen.ts"; import { endpoints } from "../../util/constants.ts"; export async function getWelcomeScreen(guildId: bigint) { diff --git a/src/types/discordeno/eventHandlers.ts b/src/types/discordeno/event_handlers.ts similarity index 88% rename from src/types/discordeno/eventHandlers.ts rename to src/types/discordeno/event_handlers.ts index 77a4076ca..e4dc7ffdb 100644 --- a/src/types/discordeno/eventHandlers.ts +++ b/src/types/discordeno/event_handlers.ts @@ -4,27 +4,26 @@ import { DiscordenoMember } from "../../structures/member.ts"; import { DiscordenoMessage } from "../../structures/message.ts"; import { DiscordenoRole } from "../../structures/role.ts"; import { Collection } from "../../util/collection.ts"; +import { PresenceUpdate } from "../activity/presence_update.ts"; +import { StageInstance } from "../channels/stage_instance.ts"; import { ThreadMember } from "../channels/threads/thread_member.ts"; import { ThreadMembersUpdate } from "../channels/threads/thread_members_update.ts"; +import { Emoji } from "../emojis/emoji.ts"; +import { GatewayPayload } from "../gateway/gateway_payload.ts"; +import { DiscordGatewayPayload } from "../gateway/gateway_payload.ts"; import { IntegrationCreateUpdate } from "../integrations/integration_create_update.ts"; +import { IntegrationDelete } from "../integrations/integration_delete.ts"; import { ApplicationCommandCreateUpdateDelete } from "../interactions/commands/application_command_create_update_delete.ts"; -import { - DiscordGatewayPayload, - Emoji, - GatewayPayload, - IntegrationDelete, - Interaction, - InviteCreate, - InviteDelete, - MessageReactionAdd, - MessageReactionRemove, - MessageReactionRemoveAll, - PresenceUpdate, - TypingStart, - User, - VoiceState, -} from "../mod.ts"; +import { Interaction } from "../interactions/interaction.ts"; +import { InviteCreate } from "../invites/invite_create.ts"; +import { InviteDelete } from "../invites/invite_delete.ts"; +import { MessageReactionAdd } from "../messages/message_reaction_add.ts"; +import { MessageReactionRemove } from "../messages/message_reaction_remove.ts"; +import { MessageReactionRemoveAll } from "../messages/message_reaction_remove_all.ts"; +import { TypingStart } from "../misc/typing_start.ts"; +import { User } from "../users/user.ts"; import { VoiceServerUpdate } from "../voice/voice_server_update.ts"; +import { VoiceState } from "../voice/voice_state.ts"; import { DebugArg } from "./debug_arg.ts"; import { GuildUpdateChange } from "./guild_update_change.ts"; @@ -170,6 +169,12 @@ export type EventHandlersDefinitions = { shardReady: [shardId: number]; /** Sent when a shard failed to load. */ shardFailedToLoad: [shardId: number, unavailableGuildIds: Set]; + /** Sent when a Stage instance is created (i.e. the Stage is now "live"). */ + stageInstanceCreate: [instance: StageInstance]; + /** Sent when a Stage instance has been deleted (i.e. the Stage has been closed). */ + stageInstanceDelete: [instance: StageInstance]; + /** Sent when a Stage instance has been updated. */ + stageInstanceUpdate: [instance: StageInstance]; /** Sent when a thread is created */ threadCreate: [channel: DiscordenoChannel]; /** Sent when a thread is updated */ diff --git a/src/types/discordeno/mod.ts b/src/types/discordeno/mod.ts index a0bf26172..b5446dccc 100644 --- a/src/types/discordeno/mod.ts +++ b/src/types/discordeno/mod.ts @@ -2,7 +2,7 @@ export * from "./create_slash_command.ts"; export * from "./debug_arg.ts"; export * from "./edit_webhook_message.ts"; export * from "./errors.ts"; -export * from "./eventHandlers.ts"; +export * from "./event_handlers.ts"; export * from "./file_content.ts"; export * from "./guild_member.ts"; export * from "./guild_update_change.ts"; diff --git a/src/types/gateway/gateway_intents.ts b/src/types/gateway/gateway_intents.ts index cb7f43944..b5bdf63a5 100644 --- a/src/types/gateway/gateway_intents.ts +++ b/src/types/gateway/gateway_intents.ts @@ -10,6 +10,15 @@ export enum DiscordGatewayIntents { * - CHANNEL_UPDATE * - CHANNEL_DELETE * - CHANNEL_PINS_UPDATE + * - THREAD_CREATE + * - THREAD_UPDATE + * - THREAD_DELETE + * - THREAD_LIST_SYNC + * - THREAD_MEMBER_UPDATE + * - THREAD_MEMBERS_UPDATE + * - STAGE_INSTANCE_CREATE + * - STAGE_INSTANCE_UPDATE + * - STAGE_INSTANCE_DELETE */ Guilds = 1 << 0, /** diff --git a/src/types/gateway/gateway_payload.ts b/src/types/gateway/gateway_payload.ts index 47694c6af..a47ea5459 100644 --- a/src/types/gateway/gateway_payload.ts +++ b/src/types/gateway/gateway_payload.ts @@ -50,6 +50,9 @@ export interface GatewayPayload { | "INTEGRATION_CREATE" | "INTEGRATION_UPDATE" | "INTEGRATION_DELETE" + | "STAGE_INSTANCE_CREATE" + | "STAGE_INSTANCE_UPDATE" + | "STAGE_INSTANCE_DELETE" | null; } diff --git a/src/types/guilds/guild.ts b/src/types/guilds/guild.ts index 5caab451e..53bb68c83 100644 --- a/src/types/guilds/guild.ts +++ b/src/types/guilds/guild.ts @@ -12,6 +12,7 @@ import { DiscordPremiumTiers } from "./premium_tiers.ts"; import { DiscordSystemChannelFlags } from "./system_channel_flags.ts"; import { DiscordVerificationLevels } from "./verification_levels.ts"; import { WelcomeScreen } from "./welcome_screen.ts"; +import type { StageInstance } from "../channels/stage_instance.ts"; /** https://discord.com/developers/docs/resources/guild#guild-object */ export interface Guild { @@ -112,4 +113,6 @@ export interface Guild { welcomeScreen?: WelcomeScreen; /** `true` if this guild is designated as NSFW */ nsfw: boolean; + /** Stage instances in the guild */ + stageInstances?: StageInstance[]; }