mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
Use resolveChannel instead of resolveVoiceChannel for joinVoiceChannel and get rid of resolveVoiceChannel
This commit is contained in:
@@ -269,46 +269,46 @@ var InternalClient = (function () {
|
|||||||
InternalClient.prototype.joinVoiceChannel = function joinVoiceChannel(chann) {
|
InternalClient.prototype.joinVoiceChannel = function joinVoiceChannel(chann) {
|
||||||
var _this3 = this;
|
var _this3 = this;
|
||||||
|
|
||||||
var channel = this.resolver.resolveVoiceChannel(chann);
|
return this.resolver.resolveChannel(chann).then(function (channel) {
|
||||||
|
if (!channel) {
|
||||||
|
return Promise.reject(new Error("voice channel does not exist"));
|
||||||
|
}
|
||||||
|
return _this3.leaveVoiceChannel().then(function () {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
var session,
|
||||||
|
token,
|
||||||
|
server = channel.server,
|
||||||
|
endpoint;
|
||||||
|
|
||||||
if (!channel) {
|
var check = function check(m) {
|
||||||
return Promise.reject(new Error("voice channel does not exist"));
|
var data = JSON.parse(m);
|
||||||
}
|
if (data.t === "VOICE_STATE_UPDATE") {
|
||||||
return this.leaveVoiceChannel().then(function () {
|
session = data.d.session_id;
|
||||||
return new Promise(function (resolve, reject) {
|
} else if (data.t === "VOICE_SERVER_UPDATE") {
|
||||||
var session,
|
token = data.d.token;
|
||||||
token,
|
endpoint = data.d.endpoint;
|
||||||
server = channel.server,
|
var chan = _this3.voiceConnection = new _VoiceVoiceConnection2["default"](channel, _this3.client, session, token, server, endpoint);
|
||||||
endpoint;
|
|
||||||
|
|
||||||
var check = function check(m) {
|
chan.on("ready", function () {
|
||||||
var data = JSON.parse(m);
|
return resolve(chan);
|
||||||
if (data.t === "VOICE_STATE_UPDATE") {
|
});
|
||||||
session = data.d.session_id;
|
chan.on("error", reject);
|
||||||
} else if (data.t === "VOICE_SERVER_UPDATE") {
|
|
||||||
token = data.d.token;
|
|
||||||
endpoint = data.d.endpoint;
|
|
||||||
var chan = _this3.voiceConnection = new _VoiceVoiceConnection2["default"](channel, _this3.client, session, token, server, endpoint);
|
|
||||||
|
|
||||||
chan.on("ready", function () {
|
_this3.client.emit("debug", "removed temporary voice websocket listeners");
|
||||||
return resolve(chan);
|
_this3.websocket.removeListener("message", check);
|
||||||
});
|
}
|
||||||
chan.on("error", reject);
|
};
|
||||||
|
|
||||||
_this3.client.emit("debug", "removed temporary voice websocket listeners");
|
_this3.websocket.on("message", check);
|
||||||
_this3.websocket.removeListener("message", check);
|
_this3.sendWS({
|
||||||
}
|
op: 4,
|
||||||
};
|
d: {
|
||||||
|
"guild_id": server.id,
|
||||||
_this3.websocket.on("message", check);
|
"channel_id": channel.id,
|
||||||
_this3.sendWS({
|
"self_mute": false,
|
||||||
op: 4,
|
"self_deaf": false
|
||||||
d: {
|
}
|
||||||
"guild_id": server.id,
|
});
|
||||||
"channel_id": channel.id,
|
|
||||||
"self_mute": false,
|
|
||||||
"self_deaf": false
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -236,14 +236,6 @@ var Resolver = (function () {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
Resolver.prototype.resolveVoiceChannel = function resolveVoiceChannel(resource) {
|
|
||||||
// resolveChannel will also work but this is more apt
|
|
||||||
if (resource instanceof _StructuresVoiceChannel2["default"]) {
|
|
||||||
return resource;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
Resolver.prototype.resolveChannel = function resolveChannel(resource) {
|
Resolver.prototype.resolveChannel = function resolveChannel(resource) {
|
||||||
/*
|
/*
|
||||||
accepts a Message, Channel, Server, String ID, User
|
accepts a Message, Channel, Server, String ID, User
|
||||||
|
|||||||
@@ -200,45 +200,45 @@ export default class InternalClient {
|
|||||||
|
|
||||||
//def joinVoiceChannel
|
//def joinVoiceChannel
|
||||||
joinVoiceChannel(chann) {
|
joinVoiceChannel(chann) {
|
||||||
var channel = this.resolver.resolveVoiceChannel(chann);
|
return this.resolver.resolveChannel(chann).then(channel => {
|
||||||
|
if (!channel) {
|
||||||
|
return Promise.reject(new Error("voice channel does not exist"));
|
||||||
|
}
|
||||||
|
return this.leaveVoiceChannel()
|
||||||
|
.then(() => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var session, token, server = channel.server, endpoint;
|
||||||
|
|
||||||
if (!channel) {
|
var check = m => {
|
||||||
return Promise.reject(new Error("voice channel does not exist"));
|
var data = JSON.parse(m);
|
||||||
}
|
if (data.t === "VOICE_STATE_UPDATE") {
|
||||||
return this.leaveVoiceChannel()
|
session = data.d.session_id;
|
||||||
.then(() => {
|
} else if (data.t === "VOICE_SERVER_UPDATE") {
|
||||||
return new Promise((resolve, reject) => {
|
token = data.d.token;
|
||||||
var session, token, server = channel.server, endpoint;
|
endpoint = data.d.endpoint;
|
||||||
|
var chan = this.voiceConnection = new VoiceConnection(
|
||||||
|
channel, this.client, session, token, server, endpoint
|
||||||
|
);
|
||||||
|
|
||||||
var check = m => {
|
chan.on("ready", () => resolve(chan));
|
||||||
var data = JSON.parse(m);
|
chan.on("error", reject);
|
||||||
if (data.t === "VOICE_STATE_UPDATE") {
|
|
||||||
session = data.d.session_id;
|
|
||||||
} else if (data.t === "VOICE_SERVER_UPDATE") {
|
|
||||||
token = data.d.token;
|
|
||||||
endpoint = data.d.endpoint;
|
|
||||||
var chan = this.voiceConnection = new VoiceConnection(
|
|
||||||
channel, this.client, session, token, server, endpoint
|
|
||||||
);
|
|
||||||
|
|
||||||
chan.on("ready", () => resolve(chan));
|
this.client.emit("debug", "removed temporary voice websocket listeners");
|
||||||
chan.on("error", reject);
|
this.websocket.removeListener("message", check);
|
||||||
|
|
||||||
this.client.emit("debug", "removed temporary voice websocket listeners");
|
}
|
||||||
this.websocket.removeListener("message", check);
|
};
|
||||||
|
|
||||||
}
|
this.websocket.on("message", check);
|
||||||
};
|
this.sendWS({
|
||||||
|
op: 4,
|
||||||
this.websocket.on("message", check);
|
d: {
|
||||||
this.sendWS({
|
"guild_id": server.id,
|
||||||
op: 4,
|
"channel_id": channel.id,
|
||||||
d: {
|
"self_mute": false,
|
||||||
"guild_id": server.id,
|
"self_deaf": false
|
||||||
"channel_id": channel.id,
|
}
|
||||||
"self_mute": false,
|
});
|
||||||
"self_deaf": false
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -166,14 +166,6 @@ export default class Resolver {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveVoiceChannel(resource) {
|
|
||||||
// resolveChannel will also work but this is more apt
|
|
||||||
if (resource instanceof VoiceChannel) {
|
|
||||||
return resource;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
resolveChannel(resource) {
|
resolveChannel(resource) {
|
||||||
/*
|
/*
|
||||||
accepts a Message, Channel, Server, String ID, User
|
accepts a Message, Channel, Server, String ID, User
|
||||||
|
|||||||
Reference in New Issue
Block a user