mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
add: stage instances events (#944)
* feat: add stage instances events * feat: add stage instances events * Add new line * Add new lines * Sort event declaration alphabetically * Move to types/discordeno * Update src/types/discordeno/eventHandlers.ts * Update src/types/discordeno/stage_instance.ts * Update src/types/guilds/guild.ts * Apply suggestions * Commit from GitHub Actions (Lint) * Remove DiscordenoStageInstance * Directly pass data.d * Commit from GitHub Actions (Lint) Co-authored-by: rigormorrtiss <rigormorrtiss@users.noreply.github.com> Co-authored-by: itohatweb <to@itoh.at>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -3,9 +3,13 @@ import type { EventHandlers } from "../types/discordeno/eventHandlers.ts";
|
||||
import type { EventEmitter } from "https://deno.land/std@0.96.0/node/events.ts";
|
||||
|
||||
export function proxyEvent(emitter: EventEmitter) {
|
||||
replaceEventHandlers(new Proxy(eventHandlers, {
|
||||
replaceEventHandlers(
|
||||
new Proxy(eventHandlers, {
|
||||
get(target, prop: keyof EventHandlers) {
|
||||
return target[prop] !== undefined ? target[prop] : ((...args: unknown[]) => emitter.emit(prop, ...args));
|
||||
return target[prop] !== undefined
|
||||
? target[prop]
|
||||
: ((...args: unknown[]) => emitter.emit(prop, ...args));
|
||||
},
|
||||
}));
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ThreadMember } from "../channels/threads/thread_member.ts";
|
||||
import { ThreadMembersUpdate } from "../channels/threads/thread_members_update.ts";
|
||||
import { IntegrationCreateUpdate } from "../integrations/integration_create_update.ts";
|
||||
import { ApplicationCommandCreateUpdateDelete } from "../interactions/commands/application_command_create_update_delete.ts";
|
||||
import {
|
||||
import type {
|
||||
DiscordGatewayPayload,
|
||||
Emoji,
|
||||
GatewayPayload,
|
||||
@@ -20,9 +20,10 @@ import {
|
||||
MessageReactionRemove,
|
||||
MessageReactionRemoveAll,
|
||||
PresenceUpdate,
|
||||
StageInstance,
|
||||
TypingStart,
|
||||
User,
|
||||
VoiceState
|
||||
VoiceState,
|
||||
} from "../mod.ts";
|
||||
import { VoiceServerUpdate } from "../voice/voice_server_update.ts";
|
||||
import { DebugArg } from "./debug_arg.ts";
|
||||
@@ -44,14 +45,22 @@ export type EventHandlersDefinitions = {
|
||||
/** Sent when a channel relevant to the current user is deleted. */
|
||||
channelDelete: [channel: DiscordenoChannel];
|
||||
/** Sent when a message pin is updated */
|
||||
channelPinsUpdate: [channel: DiscordenoChannel, guild?: DiscordenoGuild, lastPinTimestamp?: string | null];
|
||||
channelPinsUpdate: [
|
||||
channel: DiscordenoChannel,
|
||||
guild?: DiscordenoGuild,
|
||||
lastPinTimestamp?: string | null,
|
||||
];
|
||||
debug: [args: string | DebugArg, data?: string];
|
||||
/** Sent before every event. Discordeno awaits the execution of this event before main event gets sent. */
|
||||
dispatchRequirements: [data: DiscordGatewayPayload, shardId: number];
|
||||
/** Sent when a user is banned from a guild. */
|
||||
guildBanAdd: [guild: DiscordenoGuild, user: User, member?: DiscordenoMember];
|
||||
/** Sent when a user is unbanned from a guild. */
|
||||
guildBanRemove: [guild: DiscordenoGuild, user: User, member?: DiscordenoMember];
|
||||
guildBanRemove: [
|
||||
guild: DiscordenoGuild,
|
||||
user: User,
|
||||
member?: DiscordenoMember,
|
||||
];
|
||||
/**
|
||||
* This event can be sent in three different scenarios:
|
||||
* 1. When a user is initially connecting, to lazily load and backfill information for all unavailable guilds sent in the `READY` event. Guilds that are unavailable due to an outage will send a `GUILD_DELETE` event.
|
||||
@@ -74,27 +83,53 @@ export type EventHandlersDefinitions = {
|
||||
/** Sent when a guild becomes or was already unavailable due to an outage, or when the user leaves or is removed from a guild. If the `unavailable` field is not set, the user was removed from the guild. */
|
||||
guildDelete: [guild: DiscordenoGuild];
|
||||
/** Sent when a guild's emojis have been updated. */
|
||||
guildEmojisUpdate: [guild: DiscordenoGuild, emojis: Collection<bigint, Emoji>, oldEmojis: Collection<bigint, Emoji>];
|
||||
guildEmojisUpdate: [
|
||||
guild: DiscordenoGuild,
|
||||
emojis: Collection<bigint, Emoji>,
|
||||
oldEmojis: Collection<bigint, Emoji>,
|
||||
];
|
||||
/** Sent when a new user joins a guild. */
|
||||
guildMemberAdd: [guild: DiscordenoGuild, member: DiscordenoMember];
|
||||
/** Sent when a user is removed from a guild (leave/kick/ban). */
|
||||
guildMemberRemove: [guild: DiscordenoGuild, user: User, member?: DiscordenoMember];
|
||||
guildMemberRemove: [
|
||||
guild: DiscordenoGuild,
|
||||
user: User,
|
||||
member?: DiscordenoMember,
|
||||
];
|
||||
/** Sent when a guild member is updated. This will also fire when the user object of a guild member changes. */
|
||||
guildMemberUpdate: [guild: DiscordenoGuild, member: DiscordenoMember, oldMember?: DiscordenoMember];
|
||||
guildMemberUpdate: [
|
||||
guild: DiscordenoGuild,
|
||||
member: DiscordenoMember,
|
||||
oldMember?: DiscordenoMember,
|
||||
];
|
||||
/** Sent when a user uses a Slash Command. */
|
||||
interactionCreate: [data: Omit<Interaction, "member">, member?: DiscordenoMember];
|
||||
interactionCreate: [
|
||||
data: Omit<Interaction, "member">,
|
||||
member?: DiscordenoMember,
|
||||
];
|
||||
/** Sent when a user uses a Slash Command in a guild. */
|
||||
interactionGuildCreate: [data: Omit<Interaction, "member">, member: DiscordenoMember];
|
||||
interactionGuildCreate: [
|
||||
data: Omit<Interaction, "member">,
|
||||
member: DiscordenoMember,
|
||||
];
|
||||
/** Sent when a user uses a Slash Command in a dm. */
|
||||
interactionDMCreate: [data: Omit<Interaction, "member">];
|
||||
/** Sent when a message is created. */
|
||||
messageCreate: [message: DiscordenoMessage];
|
||||
/** Sent when a message is deleted. */
|
||||
messageDelete: [partial: { id: string; channel: DiscordenoChannel }, message?: DiscordenoMessage];
|
||||
messageDelete: [
|
||||
partial: { id: string; channel: DiscordenoChannel },
|
||||
message?: DiscordenoMessage,
|
||||
];
|
||||
/** Sent when a message is updated. */
|
||||
messageUpdate: [message: DiscordenoMessage, oldMessage: DiscordenoMessage];
|
||||
/** Sent when a user updates its nickname */
|
||||
nicknameUpdate: [guild: DiscordenoGuild, member: DiscordenoMember, nickname: string, oldNickname?: string];
|
||||
nicknameUpdate: [
|
||||
guild: DiscordenoGuild,
|
||||
member: DiscordenoMember,
|
||||
nickname: string,
|
||||
oldNickname?: string,
|
||||
];
|
||||
/** A user's presence is their current state on a guild. This event is sent when a user's presence or info, such as name or avatar, is updated. */
|
||||
presenceUpdate: [presence: PresenceUpdate, oldPresence?: PresenceUpdate];
|
||||
/** Sent before every event execution. Discordeno will not await its execution. */
|
||||
@@ -106,26 +141,52 @@ export type EventHandlersDefinitions = {
|
||||
/** Sent when a user removes a reaction from a message. */
|
||||
reactionRemove: [data: MessageReactionRemove, message?: DiscordenoMessage];
|
||||
/** Sent when a user explicitly removes all reactions from a message. */
|
||||
reactionRemoveAll: [payload: MessageReactionRemoveAll, message?: DiscordenoMessage];
|
||||
reactionRemoveAll: [
|
||||
payload: MessageReactionRemoveAll,
|
||||
message?: DiscordenoMessage,
|
||||
];
|
||||
/** Sent when a bot removes all instances of a given emoji from the reactions of a message. */
|
||||
reactionRemoveEmoji: [emoji: Partial<Emoji>, messageId: bigint, channelId: bigint, guildId?: bigint];
|
||||
reactionRemoveEmoji: [
|
||||
emoji: Partial<Emoji>,
|
||||
messageId: bigint,
|
||||
channelId: bigint,
|
||||
guildId?: bigint,
|
||||
];
|
||||
/** Sent when a guild role is created. */
|
||||
roleCreate: [guild: DiscordenoGuild, role: DiscordenoRole];
|
||||
/** Sent when a guild role is deleted. */
|
||||
roleDelete: [guild: DiscordenoGuild, role: DiscordenoRole];
|
||||
/** Sent when a guild role is updated. */
|
||||
roleUpdate: [guild: DiscordenoGuild, role: DiscordenoRole, old: DiscordenoRole];
|
||||
roleGained: [guild: DiscordenoGuild, member: DiscordenoMember, roleId: bigint];
|
||||
roleUpdate: [
|
||||
guild: DiscordenoGuild,
|
||||
role: DiscordenoRole,
|
||||
old: DiscordenoRole,
|
||||
];
|
||||
roleGained: [
|
||||
guild: DiscordenoGuild,
|
||||
member: DiscordenoMember,
|
||||
roleId: bigint,
|
||||
];
|
||||
roleLost: [guild: DiscordenoGuild, member: DiscordenoMember, roleId: bigint];
|
||||
shardReady: [shardId: number];
|
||||
/** Sent when a shard failed to load. */
|
||||
shardFailedToLoad: [shardId: number, unavailableGuildIds: Set<bigint>];
|
||||
/** 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 */
|
||||
threadUpdate: [cahnnel: DiscordenoChannel, oldChannel: DiscordenoChannel];
|
||||
/** Sent when the bot gains access to threads */
|
||||
threadListSync: [channels: Collection<bigint, DiscordenoChannel>, members: ThreadMember[], guildId: bigint];
|
||||
threadListSync: [
|
||||
channels: Collection<bigint, DiscordenoChannel>,
|
||||
members: ThreadMember[],
|
||||
guildId: bigint,
|
||||
];
|
||||
/** Sent when the current users thread member is updated */
|
||||
threadMemberUpdate: [threadMember: ThreadMember];
|
||||
/** Sent when anyone is added to or removed from a thread */
|
||||
@@ -139,7 +200,11 @@ export type EventHandlersDefinitions = {
|
||||
/** Sent when a user leaves a voice channel. Does not get sent when user switches the voice channel */
|
||||
voiceChannelLeave: [member: DiscordenoMember, channelId: bigint];
|
||||
/** Sent when a user switches the voice channel */
|
||||
voiceChannelSwitch: [member: DiscordenoMember, channelId: bigint, oldChannelId: bigint];
|
||||
voiceChannelSwitch: [
|
||||
member: DiscordenoMember,
|
||||
channelId: bigint,
|
||||
oldChannelId: bigint,
|
||||
];
|
||||
/** Sent when a voice server is updated with information for making the bot connect to a voice channel. */
|
||||
voiceServerUpdate: [payload: VoiceServerUpdate, guild: DiscordenoGuild];
|
||||
/** Sent when someone joins/leaves/moves voice channels. */
|
||||
@@ -158,8 +223,10 @@ export type EventHandlersDefinitions = {
|
||||
inviteCreate: [data: InviteCreate];
|
||||
/** Sent when an invite is deleted. */
|
||||
inviteDelete: [data: InviteDelete];
|
||||
}
|
||||
};
|
||||
|
||||
export type EventHandlers = {
|
||||
[E in keyof EventHandlersDefinitions]?: (...args: EventHandlersDefinitions[E]) => unknown;
|
||||
[E in keyof EventHandlersDefinitions]?: (
|
||||
...args: EventHandlersDefinitions[E]
|
||||
) => unknown;
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
/**
|
||||
|
||||
@@ -50,6 +50,9 @@ export interface GatewayPayload {
|
||||
| "INTEGRATION_CREATE"
|
||||
| "INTEGRATION_UPDATE"
|
||||
| "INTEGRATION_DELETE"
|
||||
| "STAGE_INSTANCE_CREATE"
|
||||
| "STAGE_INSTANCE_UPDATE"
|
||||
| "STAGE_INSTANCE_DELETE"
|
||||
| null;
|
||||
}
|
||||
|
||||
|
||||
@@ -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[];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { cache } from "../../src/cache.ts";
|
||||
import { deleteGuild } from "../../src/helpers/guilds/delete_guild.ts";
|
||||
import { delay } from "../../src/util/utils.ts";
|
||||
import { ws } from "../../src/ws/ws.ts";
|
||||
import { assertExists, assertEquals } from "../deps.ts";
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
|
||||
// Set necessary settings
|
||||
// Disables the logger which logs everything
|
||||
@@ -38,7 +38,7 @@ Deno.test({
|
||||
await startBot({
|
||||
token,
|
||||
eventHandlers: {
|
||||
ready: () => didReady = true
|
||||
ready: () => didReady = true,
|
||||
},
|
||||
intents: [
|
||||
"GuildMessages",
|
||||
|
||||
Reference in New Issue
Block a user