diff --git a/index.d.ts b/index.d.ts index c35c735e4..913424824 100644 --- a/index.d.ts +++ b/index.d.ts @@ -356,7 +356,31 @@ declare namespace Eris { INTEGRATION_UPDATE: 81; INTEGRATION_DELETE: 82; }; - } + MessageTypes: { + DEFAULT: 0; + RECIPIENT_ADD: 1; + RECIPIENT_REMOVE: 2; + CALL: 3; + CHANNEL_NAME_CHANGE: 4; + CHANNEL_ICON_CHANGE: 5; + CHANNEL_PINNED_MESSAGE: 6; + GUILD_MEMBER_JOIN: 7; + USER_PREMIUM_GUILD_SUBSCRIPTION: 8; + USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1: 9; + USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2: 10; + USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3: 11; + CHANNEL_FOLLOW_ADD: 12; + }; + ChannelTypes: { + GUILD_TEXT: 0; + DM: 1; + GUILD_VOICE: 2; + GROUP_DM: 3; + GUILD_CATEGORY: 4; + GUILD_NEWS: 5; + GUILD_STORE: 6; + }; +} export const Constants: Constants; diff --git a/lib/Constants.js b/lib/Constants.js index fd2c6b288..a480ed2ca 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -172,3 +172,29 @@ module.exports.MessageFlags = { IS_CROSSPOST: 1 << 1, SUPPRESS_EMBEDS: 1 << 2 }; + +module.exports.MessageTypes = { + DEFAULT: 0, + RECIPIENT_ADD: 1, + RECIPIENT_REMOVE: 2, + CALL: 3, + CHANNEL_NAME_CHANGE: 4, + CHANNEL_ICON_CHANGE: 5, + CHANNEL_PINNED_MESSAGE: 6, + GUILD_MEMBER_JOIN: 7, + USER_PREMIUM_GUILD_SUBSCRIPTION: 8, + USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1: 9, + USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2: 10, + USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3: 11, + CHANNEL_FOLLOW_ADD: 12 +}; + +module.exports.ChannelTypes = { + GUILD_TEXT: 0, + DM: 1, + GUILD_VOICE: 2, + GROUP_DM: 3, + GUILD_CATEGORY: 4, + GUILD_NEWS: 5, + GUILD_STORE: 6 +}; diff --git a/lib/gateway/Shard.js b/lib/gateway/Shard.js index de1bf89f9..d8110e36e 100644 --- a/lib/gateway/Shard.js +++ b/lib/gateway/Shard.js @@ -6,9 +6,8 @@ const Channel = require("../structures/Channel"); const GroupChannel = require("../structures/GroupChannel"); const GuildChannel = require("../structures/GuildChannel"); const PrivateChannel = require("../structures/PrivateChannel"); -const Constants = require("../Constants"); +const {GATEWAY_VERSION, GatewayOPCodes, ChannelTypes} = require("../Constants"); const ExtendedUser = require("../structures/ExtendedUser"); -const OPCodes = Constants.GatewayOPCodes; const User = require("../structures/User"); let WebSocket = typeof window !== "undefined" ? window.WebSocket : require("ws"); @@ -172,7 +171,7 @@ class Shard extends EventEmitter { resume() { this.status = "resuming"; - this.sendWS(OPCodes.RESUME, { + this.sendWS(GatewayOPCodes.RESUME, { token: this.client.token, session_id: this.sessionID, seq: this.seq @@ -186,7 +185,7 @@ class Shard extends EventEmitter { } const identify = { token: this.client.token, - v: Constants.GATEWAY_VERSION, + v: GATEWAY_VERSION, compress: !!this.client.options.compress, large_threshold: this.client.options.largeThreshold, guild_subscriptions: !!this.client.options.guildSubscriptions, @@ -202,7 +201,7 @@ class Shard extends EventEmitter { if(this.presence.status) { identify.presence = this.presence; } - this.sendWS(OPCodes.IDENTIFY, identify, true); + this.sendWS(GatewayOPCodes.IDENTIFY, identify, true); } wsEvent(packet) { @@ -326,7 +325,7 @@ class Shard extends EventEmitter { } const member = guild.members.get(packet.d.id = packet.d.user_id); if(!member) { - const channel = guild.channels.find((channel) => channel.type === 2 && channel.voiceMembers.get(packet.d.id)); + const channel = guild.channels.find((channel) => channel.type === ChannelTypes.GUILD_VOICE && channel.voiceMembers.get(packet.d.id)); if(channel) { channel.voiceMembers.remove(packet.d); this.emit("debug", "VOICE_STATE_UPDATE member null but in channel: " + packet.d.id, this.id); @@ -353,7 +352,7 @@ class Shard extends EventEmitter { if(oldChannelID) { oldChannel = guild.channels.get(oldChannelID); } - if(packet.d.channel_id && (newChannel = guild.channels.get(packet.d.channel_id)) && newChannel.type === 2) { // Welcome to Discord, where one can "join" text channels + if(packet.d.channel_id && (newChannel = guild.channels.get(packet.d.channel_id)) && newChannel.type === ChannelTypes.GUILD_VOICE) { // Welcome to Discord, where one can "join" text channels if(oldChannel) { /** * Fired when a guild member switches voice channels @@ -966,7 +965,7 @@ class Shard extends EventEmitter { break; } case "CHANNEL_DELETE": { - if(packet.d.type === 1 || packet.d.type === undefined) { + if(packet.d.type === ChannelTypes.DM || packet.d.type === undefined) { if(this.id === 0) { const channel = this.client.privateChannels.remove(packet.d); if(channel) { @@ -990,13 +989,13 @@ class Shard extends EventEmitter { if(!channel) { break; } - if(channel.type === 2) { + if(channel.type === ChannelTypes.GUILD_VOICE) { channel.voiceMembers.forEach((member) => { this.emit("voiceChannelLeave", channel.voiceMembers.remove(member), channel); }); } this.emit("channelDelete", channel); - } else if(packet.d.type === 3) { + } else if(packet.d.type === ChannelTypes.GROUP_DM) { if(this.id === 0) { this.emit("channelDelete", this.client.groupChannels.remove(packet.d)); } @@ -1249,10 +1248,10 @@ class Shard extends EventEmitter { }); packet.d.private_channels.forEach((channel) => { - if(channel.type === undefined || channel.type === 1) { + if(channel.type === undefined || channel.type === ChannelTypes.DM) { this.client.privateChannelMap[channel.recipients[0].id] = channel.id; this.client.privateChannels.add(channel, this.client, true); - } else if(channel.type === 3) { + } else if(channel.type === ChannelTypes.GROUP_DM) { this.client.groupChannels.add(channel, this.client, true); } else { this.emit("warn", new Error("Unhandled READY private_channel type: " + JSON.stringify(channel, null, 2))); @@ -1456,7 +1455,7 @@ class Shard extends EventEmitter { } requestGuildSync(guildID) { - this.sendWS(OPCodes.SYNC_GUILD, guildID); + this.sendWS(GatewayOPCodes.SYNC_GUILD, guildID); } createGuild(_guild) { @@ -1502,7 +1501,7 @@ class Shard extends EventEmitter { } requestGuildMembers(guildID, query, limit) { - this.sendWS(OPCodes.GET_GUILD_MEMBERS, { + this.sendWS(GatewayOPCodes.GET_GUILD_MEMBERS, { guild_id: guildID, query: query || "", limit: limit || 0 @@ -1681,30 +1680,30 @@ class Shard extends EventEmitter { } switch(packet.op) { - case OPCodes.EVENT: { + case GatewayOPCodes.EVENT: { if(!this.client.options.disableEvents[packet.t]) { this.wsEvent(packet); } break; } - case OPCodes.HEARTBEAT: { + case GatewayOPCodes.HEARTBEAT: { this.heartbeat(); break; } - case OPCodes.INVALID_SESSION: { + case GatewayOPCodes.INVALID_SESSION: { this.seq = 0; this.sessionID = null; this.emit("warn", "Invalid session, reidentifying!", this.id); this.identify(); break; } - case OPCodes.RECONNECT: { + case GatewayOPCodes.RECONNECT: { this.disconnect({ reconnect: "auto" }); break; } - case OPCodes.HELLO: { + case GatewayOPCodes.HELLO: { if(packet.d.heartbeat_interval > 0) { if(this.heartbeatInterval) { clearInterval(this.heartbeatInterval); @@ -1730,7 +1729,7 @@ class Shard extends EventEmitter { this.emit("hello", packet.d._trace, this.id); break; /* eslint-enable no-unreachable */ } - case OPCodes.HEARTBEAT_ACK: { + case GatewayOPCodes.HEARTBEAT_ACK: { this.lastHeartbeatAck = true; this.lastHeartbeatReceived = new Date().getTime(); break; @@ -1750,7 +1749,7 @@ class Shard extends EventEmitter { } this.lastHeartbeatAck = false; this.lastHeartbeatSent = new Date().getTime(); - this.sendWS(OPCodes.HEARTBEAT, this.seq, true); + this.sendWS(GatewayOPCodes.HEARTBEAT, this.seq, true); } sendWS(op, _data) { @@ -1764,7 +1763,7 @@ class Shard extends EventEmitter { this.emit("debug", JSON.stringify({op: op, d: _data}), this.id); } }; - if(op === OPCodes.STATUS_UPDATE) { + if(op === GatewayOPCodes.STATUS_UPDATE) { ++waitFor; this.presenceUpdateBucket.queue(func); } @@ -1815,7 +1814,7 @@ class Shard extends EventEmitter { } sendStatusUpdate() { - this.sendWS(OPCodes.STATUS_UPDATE, { + this.sendWS(GatewayOPCodes.STATUS_UPDATE, { afk: !!this.presence.afk, // For push notifications game: this.presence.game, since: this.presence.status === "idle" ? Date.now() : 0, diff --git a/lib/rest/Endpoints.js b/lib/rest/Endpoints.js index b6e07e49a..bde480bec 100644 --- a/lib/rest/Endpoints.js +++ b/lib/rest/Endpoints.js @@ -1,8 +1,8 @@ "use strict"; -const Constants = require("../Constants"); +const {REST_VERSION} = require("../Constants"); -module.exports.BASE_URL = "/api/v" + Constants.REST_VERSION; +module.exports.BASE_URL = "/api/v" + REST_VERSION; module.exports.CDN_URL = "https://cdn.discordapp.com"; module.exports.CHANNEL = (chanID) => `/channels/${chanID}`; diff --git a/lib/structures/Channel.js b/lib/structures/Channel.js index e68150dfe..9de006653 100644 --- a/lib/structures/Channel.js +++ b/lib/structures/Channel.js @@ -1,6 +1,7 @@ "use strict"; const Base = require("./Base"); +const {ChannelTypes} = require("../Constants"); /** * Represents a channel. You also probably want to look at CategoryChannel, GroupChannel, NewsChannel, PrivateChannel, TextChannel, and VoiceChannel. @@ -21,25 +22,25 @@ class Channel extends Base { static from(data, client) { switch(data.type) { - case 0: { + case ChannelTypes.GUILD_TEXT: { return new TextChannel(data, client); } - case 1: { + case ChannelTypes.DM: { return new PrivateChannel(data, client); } - case 2: { + case ChannelTypes.GUILD_VOICE: { return new VoiceChannel(data, client); } - case 3: { + case ChannelTypes.GROUP_DM: { return new GroupChannel(data, client); } - case 4: { + case ChannelTypes.GUILD_CATEGORY: { return new CategoryChannel(data, client); } - case 5: { + case ChannelTypes.GUILD_NEWS: { return new NewsChannel(data, client); } - case 6: { + case ChannelTypes.GUILD_STORE: { return new StoreChannel(data, client); } } diff --git a/lib/structures/GroupChannel.js b/lib/structures/GroupChannel.js index 3f942ca0f..c0155e73f 100644 --- a/lib/structures/GroupChannel.js +++ b/lib/structures/GroupChannel.js @@ -1,7 +1,7 @@ "use strict"; const Collection = require("../util/Collection"); -const Constants = require("../Constants"); +const {ImageFormats, ImageSizeBoundaries} = require("../Constants"); const Endpoints = require("../rest/Endpoints"); const PrivateChannel = require("./PrivateChannel"); const User = require("./User"); @@ -75,12 +75,12 @@ class GroupChannel extends PrivateChannel { // (╯°□°)╯︵ ┻━┻ * @arg {Number} [size] The size of the icon (any power of two between 16 and 2048) */ dynamicIconURL(format, size) { - if(!format || !Constants.ImageFormats.includes(format.toLowerCase())) { + if(!format || !ImageFormats.includes(format.toLowerCase())) { format = this._client.options.defaultImageFormat; } if( - size < Constants.ImageSizeBoundaries.MINIMUM || - size > Constants.ImageSizeBoundaries.MAXIMUM || + size < ImageSizeBoundaries.MINIMUM || + size > ImageSizeBoundaries.MAXIMUM || (size & (size - 1)) ) { size = this._client.options.defaultImageSize; diff --git a/lib/structures/Guild.js b/lib/structures/Guild.js index 68c0a2c7d..1a2368c8f 100644 --- a/lib/structures/Guild.js +++ b/lib/structures/Guild.js @@ -3,7 +3,7 @@ const Base = require("./Base"); const Channel = require("./Channel"); const {CDN_URL} = require("../rest/Endpoints"); -const Constants = require("../Constants"); +const {ImageFormats, ImageSizeBoundaries} = require("../Constants"); const Collection = require("../util/Collection"); const GuildChannel = require("./GuildChannel"); const Member = require("./Member"); @@ -164,12 +164,12 @@ class Guild extends Base { * @arg {Number} [size] The size of the icon (any power of two between 16 and 2048) */ dynamicIconURL(format, size) { - if(!format || !Constants.ImageFormats.includes(format.toLowerCase())) { + if(!format || !ImageFormats.includes(format.toLowerCase())) { format = this.shard.client.options.defaultImageFormat; } if( - size < Constants.ImageSizeBoundaries.MINIMUM || - size > Constants.ImageSizeBoundaries.MAXIMUM || + size < ImageSizeBoundaries.MINIMUM || + size > ImageSizeBoundaries.MAXIMUM || (size & (size - 1)) ) { size = this.shard.client.options.defaultImageSize; @@ -191,12 +191,12 @@ class Guild extends Base { * @param {Number} [size] The size of the icon (any power of two between 16 and 2048) */ dynamicSplashURL(format,size){ - if(!format || !Constants.ImageFormats.includes(format.toLowerCase())){ + if(!format || !ImageFormats.includes(format.toLowerCase())){ format = this.shard.client.options.defaultImageFormat; } if( - size < Constants.ImageSizeBoundaries.MINIMUM || - size > Constants.ImageSizeBoundaries.MAXIMUM || + size < ImageSizeBoundaries.MINIMUM || + size > ImageSizeBoundaries.MAXIMUM || (size & (size - 1)) ) { size = this.shard.client.options.defaultImageSize; @@ -210,12 +210,12 @@ class Guild extends Base { * @param {Number} [size] The size of the icon (any power of two between 16 and 2048) */ dynamicBannerURL(format,size){ - if(!format || !Constants.ImageFormats.includes(format.toLowerCase())){ + if(!format || !ImageFormats.includes(format.toLowerCase())){ format = this.shard.client.options.defaultImageFormat; } if( - size < Constants.ImageSizeBoundaries.MINIMUM || - size > Constants.ImageSizeBoundaries.MAXIMUM || + size < ImageSizeBoundaries.MINIMUM || + size > ImageSizeBoundaries.MAXIMUM || (size & (size - 1)) ) { size = this.shard.client.options.defaultImageSize; diff --git a/lib/structures/GuildAuditLogEntry.js b/lib/structures/GuildAuditLogEntry.js index c530380a9..6171b45d7 100644 --- a/lib/structures/GuildAuditLogEntry.js +++ b/lib/structures/GuildAuditLogEntry.js @@ -2,7 +2,7 @@ const Base = require("./Base"); const Invite = require("./Invite"); -const Constants = require("../Constants"); +const {AuditLogActions} = require("../Constants"); /** * Represents a guild audit log entry describing a moderation action @@ -91,7 +91,7 @@ class GuildAuditLogEntry extends Base { } else if(this.actionType < 20) { // Channel return this.guild && this.guild.channels.get(this.targetID); } else if(this.actionType < 30) { // Member - if(this.actionType === Constants.AuditLogActions.MEMBER_MOVE || this.actionType === Constants.AuditLogActions.MEMBER_DISCONNECT) { // MEMBER_MOVE / MEMBER_DISCONNECT + if(this.actionType === AuditLogActions.MEMBER_MOVE || this.actionType === AuditLogActions.MEMBER_DISCONNECT) { // MEMBER_MOVE / MEMBER_DISCONNECT return null; } return this.guild && this.guild.members.get(this.targetID); diff --git a/lib/structures/Message.js b/lib/structures/Message.js index 7fc7d99e3..c8ec19c89 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -2,7 +2,7 @@ const Base = require("./Base"); const Call = require("./Call"); -const {SystemJoinMessages} = require("../Constants"); +const {SystemJoinMessages, MessageTypes} = require("../Constants"); const User = require("./User"); /** @@ -82,16 +82,16 @@ class Message extends Base { } else { this.member = null; } - if(this.type === 0 || this.type === undefined); - else if(this.type === 1) { + if(this.type === MessageTypes.DEFAULT || this.type === undefined); + else if(this.type === MessageTypes.RECIPIENT_ADD) { data.content = `${this.author.mention} added <@${data.mentions[0].id}>.`; - } else if(this.type === 2) { + } else if(this.type === MessageTypes.RECIPIENT_REMOVE) { if(this.author.id === data.mentions[0].id) { data.content = `@${this.author.username} left the group.`; } else { data.content = `${this.author.mention} removed @${data.mentions[0].username}.`; } - } else if(this.type === 3) { // (╯°□°)╯︵ ┻━┻ + } else if(this.type === MessageTypes.CALL) { // (╯°□°)╯︵ ┻━┻ if(data.call.ended_timestamp) { if((!this.channel.lastCall || this.channel.lastCall.endedTimestamp < Date.parse(data.call.ended_timestamp))) { data.call.id = this.id; @@ -109,19 +109,19 @@ class Message extends Base { } data.content = `${this.author.mention} started a call. — Join the call.`; } - } else if(this.type === 4) { + } else if(this.type === MessageTypes.CHANNEL_NAME_CHANGE) { data.content = `${this.author.mention} changed the channel name: ${data.content}`; - } else if(this.type === 5) { + } else if(this.type === MessageTypes.CHANNEL_ICON_CHANGE) { data.content = `${this.author.mention} changed the channel icon.`; - } else if(this.type === 6) { + } else if(this.type === MessageTypes.CHANNEL_PINNED_MESSAGE) { data.content = `${this.author.mention} pinned a message to this channel. See all the pins.`; - } else if(this.type === 7) { + } else if(this.type === MessageTypes.GUILD_MEMBER_JOIN) { data.content = SystemJoinMessages[~~(this.createdAt % SystemJoinMessages.length)].replace(/%user%/g, this.author.mention); - } else if(this.type === 8) { + } else if(this.type === MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION) { data.content = `${this.author.mention} just boosted the server!`; - } else if(this.type === 9 || this.type === 10 || this.type === 11) { + } else if(this.type === MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1 || this.type === MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2 || this.type === MessageTypes.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3) { data.content = `${this.author.mention} just boosted the server! ${this.channel.guild ? this.channel.guild.name : data.guild_id} has achieved **Level ${this.type - 8}!**`; - } else if(this.type === 12) { + } else if(this.type === MessageTypes.CHANNEL_FOLLOW_ADD) { data.content = `${this.author.mention} has added ${data.content} to this channel`; } else { client.emit("warn", "Unhandled MESSAGE_CREATE type: " + JSON.stringify(data, null, 2)); diff --git a/lib/structures/PrivateChannel.js b/lib/structures/PrivateChannel.js index 86afd5977..f96595aae 100644 --- a/lib/structures/PrivateChannel.js +++ b/lib/structures/PrivateChannel.js @@ -4,7 +4,7 @@ const Channel = require("./Channel"); const Collection = require("../util/Collection"); const Endpoints = require("../rest/Endpoints"); const Message = require("./Message"); -const OPCodes = require("../Constants").GatewayOPCodes; +const {GatewayOPCodes, ChannelTypes} = require("../Constants"); const User = require("./User"); /** @@ -24,7 +24,7 @@ class PrivateChannel extends Channel { this.lastMessageID = data.last_message_id; this.rateLimitPerUser = data.rate_limit_per_user; this.call = this.lastCall = null; - if(this.type === 1 || this.type === undefined) { + if(this.type === ChannelTypes.DM || this.type === undefined) { this.recipient = new User(data.recipients[0], client); } this.messages = new Collection(Message, client.options.messageLimit); @@ -44,7 +44,7 @@ class PrivateChannel extends Channel { * Check if the channel has an existing call */ syncCall() { - this._client.shards.values().next().value.sendWS(OPCodes.SYNC_CALL, { + this._client.shards.values().next().value.sendWS(GatewayOPCodes.SYNC_CALL, { channel_id: this.id }); } diff --git a/lib/structures/User.js b/lib/structures/User.js index d0fbd8e34..bf5738ed0 100644 --- a/lib/structures/User.js +++ b/lib/structures/User.js @@ -2,7 +2,7 @@ const Base = require("./Base"); const {CDN_URL} = require("../rest/Endpoints"); -const Constants = require("../Constants"); +const {ImageSizeBoundaries, ImageFormats} = require("../Constants"); /** * Represents a user @@ -72,12 +72,12 @@ class User extends Base { return this.defaultAvatarURL; } - if(!format || !Constants.ImageFormats.includes(format.toLowerCase())) { + if(!format || !ImageFormats.includes(format.toLowerCase())) { format = this.avatar.startsWith("a_") ? "gif" : this._client.options.defaultImageFormat; } if( - size < Constants.ImageSizeBoundaries.MINIMUM || - size > Constants.ImageSizeBoundaries.MAXIMUM || + size < ImageSizeBoundaries.MINIMUM || + size > ImageSizeBoundaries.MAXIMUM || (size & (size - 1)) ) { size = this._client.options.defaultImageSize; diff --git a/lib/voice/VoiceConnection.js b/lib/voice/VoiceConnection.js index ff3cb19cd..9fd6bc1a3 100644 --- a/lib/voice/VoiceConnection.js +++ b/lib/voice/VoiceConnection.js @@ -1,9 +1,8 @@ "use strict"; const ChildProcess = require("child_process"); -const Constants = require("../Constants"); +const {VoiceOPCodes, GatewayOPCodes} = require("../Constants"); const Dgram = require("dgram"); -const OPCodes = Constants.VoiceOPCodes; const Piper = require("./Piper"); const VoiceDataStream = require("./VoiceDataStream"); let WebSocket = typeof window !== "undefined" ? window.WebSocket : require("ws"); @@ -210,7 +209,7 @@ class VoiceConnection extends EventEmitter { clearTimeout(connectionTimeout); connectionTimeout = null; } - this.sendWS(OPCodes.IDENTIFY, { + this.sendWS(VoiceOPCodes.IDENTIFY, { server_id: this.id === "call" ? data.channel_id : this.id, user_id: data.user_id, session_id: data.session_id, @@ -223,7 +222,7 @@ class VoiceConnection extends EventEmitter { this.emit("debug", "Rec: " + JSON.stringify(packet)); } switch(packet.op) { - case OPCodes.READY: { + case VoiceOPCodes.READY: { if(packet.d.heartbeat_interval > 0) { if(this.heartbeatInterval) { clearInterval(this.heartbeatInterval); @@ -257,7 +256,7 @@ class VoiceConnection extends EventEmitter { } const localPort = parseInt(packet.readUIntLE(packet.length - 2, 2).toString(10)); - this.sendWS(OPCodes.SELECT_PROTOCOL, { + this.sendWS(VoiceOPCodes.SELECT_PROTOCOL, { protocol: "udp", data: { address: localIP, @@ -288,7 +287,7 @@ class VoiceConnection extends EventEmitter { this._sendPacket(udpMessage); break; } - case OPCodes.SESSION_DESCRIPTION: { + case VoiceOPCodes.SESSION_DESCRIPTION: { this.mode = packet.d.mode; this.secret = new Uint8Array(new ArrayBuffer(packet.d.secret_key.length)); for(let i = 0; i < packet.d.secret_key.length; ++i) { @@ -304,7 +303,7 @@ class VoiceConnection extends EventEmitter { this.resume(); break; } - case OPCodes.HEARTBEAT: { + case VoiceOPCodes.HEARTBEAT: { /** * Fired when the voice connection receives a pong * @event VoiceConnection#pong @@ -313,7 +312,7 @@ class VoiceConnection extends EventEmitter { this.emit("pong", Date.now() - packet.d); break; } - case OPCodes.SPEAKING: { + case VoiceOPCodes.SPEAKING: { this.ssrcUserMap[packet.d.ssrc] = packet.d.user_id; /** * Fired when a user begins speaking @@ -406,7 +405,7 @@ class VoiceConnection extends EventEmitter { } heartbeat() { - this.sendWS(OPCodes.HEARTBEAT, Date.now()); + this.sendWS(VoiceOPCodes.HEARTBEAT, Date.now()); } /** @@ -667,7 +666,7 @@ class VoiceConnection extends EventEmitter { setSpeaking(value) { if((value = !!value) != this.speaking) { this.speaking = value; - this.sendWS(OPCodes.SPEAKING, { + this.sendWS(VoiceOPCodes.SPEAKING, { speaking: value, delay: 0, ssrc: this.ssrc @@ -697,7 +696,7 @@ class VoiceConnection extends EventEmitter { */ updateVoiceState(selfMute, selfDeaf) { if(this.shard.sendWS) { - this.shard.sendWS(Constants.GatewayOPCodes.VOICE_STATE_UPDATE, { + this.shard.sendWS(GatewayOPCodes.VOICE_STATE_UPDATE, { guild_id: this.id === "call" ? null : this.id, channel_id: this.channelID || null, self_mute: !!selfMute,