From aceefd44b64b856be5da65613f3a7ba426d950c8 Mon Sep 17 00:00:00 2001 From: Snazzah Date: Mon, 23 Sep 2024 18:33:39 -0500 Subject: [PATCH 1/3] feat: handle voice channel effect send events --- index.d.ts | 12 ++++++++++++ lib/Constants.d.ts | 4 ++++ lib/Constants.js | 5 +++++ lib/gateway/Shard.js | 29 +++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) diff --git a/index.d.ts b/index.d.ts index 72c76a272..feb85be81 100644 --- a/index.d.ts +++ b/index.d.ts @@ -191,6 +191,7 @@ declare namespace Eris { // Voice type ConverterCommand = "./ffmpeg" | "./avconv" | "ffmpeg" | "avconv"; type StageInstancePrivacyLevel = Constants["StageInstancePrivacyLevel"][keyof Constants["StageInstancePrivacyLevel"]]; + type VoiceChannelEffectAnimationType = Constants["VoiceChannelEffectAnimationTypes"][keyof Constants["VoiceChannelEffectAnimationTypes"]]; // Webhook type WebhookPayloadEdit = Pick; @@ -866,6 +867,16 @@ declare namespace Eris { selfStream: boolean; selfVideo: boolean; } + interface VoiceChannelEffect { + guild: Guild | Uncached; + channel: AnyVoiceChannel | Uncached; + user: User | Uncached; + emoji?: PartialEmoji; + animationType?: VoiceChannelEffectAnimationType; + animationID?: number; + soundID?: string | number; + soundVolume?: number; + } interface EventListeners { applicationCommandPermissionsUpdate: [applicationCommandPermissions: GuildApplicationCommandPermissions]; autoModerationActionExecution: [guild: Guild, action: AutoModerationActionExecution]; @@ -937,6 +948,7 @@ declare namespace Eris { unavailableGuildCreate: [guild: UnavailableGuild]; unknown: [packet: RawPacket, id?: number]; userUpdate: [user: User, oldUser: PartialUser | null]; + voiceChannelEffectSend: [effect: VoiceChannelEffect]; voiceChannelJoin: [member: Member, channel: AnyVoiceChannel]; voiceChannelLeave: [member: Member, channel: AnyVoiceChannel]; voiceChannelStatusUpdate: [channel: AnyVoiceChannel, oldChannel: VoiceStatus]; diff --git a/lib/Constants.d.ts b/lib/Constants.d.ts index 955ed5559..078d34222 100644 --- a/lib/Constants.d.ts +++ b/lib/Constants.d.ts @@ -674,6 +674,10 @@ export default interface Constants { AUTO: 1; FULL: 2; }; + VoiceChannelEffectAnimationTypes: { + PREMIUM: 0; + BASIC: 1; + }; VoiceOPCodes: { IDENTIFY: 0; SELECT_PROTOCOL: 1; diff --git a/lib/Constants.js b/lib/Constants.js index 471d8e6e3..654d124c5 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -851,6 +851,11 @@ module.exports.VideoQualityModes = { FULL: 2, }; +module.exports.VoiceChannelEffectAnimationTypes = { + PREMIUM: 0, + BASIC: 1, +}; + module.exports.VoiceOPCodes = { IDENTIFY: 0, SELECT_PROTOCOL: 1, diff --git a/lib/gateway/Shard.js b/lib/gateway/Shard.js index 795af9b12..23e715d28 100644 --- a/lib/gateway/Shard.js +++ b/lib/gateway/Shard.js @@ -911,6 +911,35 @@ class Shard extends EventEmitter { this.emit("voiceChannelStatusUpdate", channel, oldChannel); break; } + case "VOICE_CHANNEL_EFFECT_SEND": { + const channel = this.client.getChannel(packet.d.channel_id) ?? { id: packet.d.channel_id }; + const guild = this.client.guilds.get(packet.d.guild_id) ?? { id: packet.d.guild_id }; + const user = this.client.users.get(packet.d.user_id) ?? { id: packet.d.user_id }; + /** + * Fired when a user sends a voice channel effect + * @event Client#voiceChannelEffectSend + * @prop {Object} effect The effect that was sent + * @prop {Guild | Object} effect.guild The guild the effect was sent in. If the guild is not cached, this will be an object with an `id` key. No other property is guaranteed + * @prop {VoiceChannel | StageChannel | Object} effect.channel The voice channel the effect was sent in. If the channel is not cached, this will be an object with an `id` key. No other property is guaranteed + * @prop {User | Object} effect.user The user that sent the effect. If the user is not cached, this will be an object with an `id` key. No other property is guaranteed + * @prop {Object?} effect.emoji The emoji sent + * @prop {Number?} effect.animationType The animation type + * @prop {Number?} effect.animationID The animation ID + * @prop {(String | Number)?} effect.soundID The sound ID + * @prop {Number?} effect.soundVolume The volume of the sound (a number between 0 and 1) + */ + this.emit("voiceChannelEffectSend", { + channel: channel, + guild: guild, + user: user, + emoji: packet.d.emoji, + animationType: packet.d.animation_type, + animationID: packet.d.animation_id, + soundID: packet.d.sound_id, + soundVolume: packet.d.sound_volume, + }); + break; + } case "TYPING_START": { let member = null; const guild = this.client.guilds.get(packet.d.guild_id); From 5e39e7c8663bbe973d82fe2d726fa55a3be45036 Mon Sep 17 00:00:00 2001 From: Snazzah Date: Sat, 12 Oct 2024 18:25:26 -0500 Subject: [PATCH 2/3] fix: dont use nullish coalescing --- lib/gateway/Shard.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/gateway/Shard.js b/lib/gateway/Shard.js index 23e715d28..6dd5cb47a 100644 --- a/lib/gateway/Shard.js +++ b/lib/gateway/Shard.js @@ -912,9 +912,9 @@ class Shard extends EventEmitter { break; } case "VOICE_CHANNEL_EFFECT_SEND": { - const channel = this.client.getChannel(packet.d.channel_id) ?? { id: packet.d.channel_id }; - const guild = this.client.guilds.get(packet.d.guild_id) ?? { id: packet.d.guild_id }; - const user = this.client.users.get(packet.d.user_id) ?? { id: packet.d.user_id }; + const channel = this.client.getChannel(packet.d.channel_id) || { id: packet.d.channel_id }; + const guild = this.client.guilds.get(packet.d.guild_id) || { id: packet.d.guild_id }; + const user = this.client.users.get(packet.d.user_id) || { id: packet.d.user_id }; /** * Fired when a user sends a voice channel effect * @event Client#voiceChannelEffectSend From c4df7a7b4b652b93a076227b8f064bef61159dc1 Mon Sep 17 00:00:00 2001 From: Snazzah Date: Sat, 12 Oct 2024 18:27:33 -0500 Subject: [PATCH 3/3] chore: apply requested changes --- index.d.ts | 20 ++++++++++---------- lib/gateway/Shard.js | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/index.d.ts b/index.d.ts index feb85be81..9b007d43d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -867,16 +867,6 @@ declare namespace Eris { selfStream: boolean; selfVideo: boolean; } - interface VoiceChannelEffect { - guild: Guild | Uncached; - channel: AnyVoiceChannel | Uncached; - user: User | Uncached; - emoji?: PartialEmoji; - animationType?: VoiceChannelEffectAnimationType; - animationID?: number; - soundID?: string | number; - soundVolume?: number; - } interface EventListeners { applicationCommandPermissionsUpdate: [applicationCommandPermissions: GuildApplicationCommandPermissions]; autoModerationActionExecution: [guild: Guild, action: AutoModerationActionExecution]; @@ -1838,6 +1828,16 @@ declare namespace Eris { id: string; voiceState: OldVoiceState; } + interface VoiceChannelEffect { + animationID?: number; + animationType?: VoiceChannelEffectAnimationType | null; + channel: PossiblyUncachedSpeakableChannel; + emoji?: PartialEmoji | null; + guild: PossiblyUncachedGuild; + soundID?: string | number; + soundVolume?: number; + user: User | Uncached; + } interface VoiceConnectData { channel_id: string; endpoint: string; diff --git a/lib/gateway/Shard.js b/lib/gateway/Shard.js index 6dd5cb47a..f9810d7c3 100644 --- a/lib/gateway/Shard.js +++ b/lib/gateway/Shard.js @@ -919,14 +919,14 @@ class Shard extends EventEmitter { * Fired when a user sends a voice channel effect * @event Client#voiceChannelEffectSend * @prop {Object} effect The effect that was sent - * @prop {Guild | Object} effect.guild The guild the effect was sent in. If the guild is not cached, this will be an object with an `id` key. No other property is guaranteed + * @prop {Number?} effect.animationID The animation ID + * @prop {Number?} effect.animationType The animation type * @prop {VoiceChannel | StageChannel | Object} effect.channel The voice channel the effect was sent in. If the channel is not cached, this will be an object with an `id` key. No other property is guaranteed - * @prop {User | Object} effect.user The user that sent the effect. If the user is not cached, this will be an object with an `id` key. No other property is guaranteed * @prop {Object?} effect.emoji The emoji sent - * @prop {Number?} effect.animationType The animation type - * @prop {Number?} effect.animationID The animation ID + * @prop {Guild | Object} effect.guild The guild the effect was sent in. If the guild is not cached, this will be an object with an `id` key. No other property is guaranteed * @prop {(String | Number)?} effect.soundID The sound ID * @prop {Number?} effect.soundVolume The volume of the sound (a number between 0 and 1) + * @prop {User | Object} effect.user The user that sent the effect. If the user is not cached, this will be an object with an `id` key. No other property is guaranteed */ this.emit("voiceChannelEffectSend", { channel: channel,