mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Let the WS handler handle leaving servers
This commit is contained in:
@@ -563,74 +563,30 @@ var InternalClient = (function () {
|
||||
//def leaveServer
|
||||
|
||||
InternalClient.prototype.leaveServer = function leaveServer(srv) {
|
||||
var _this10 = this;
|
||||
|
||||
var server = this.resolver.resolveServer(srv);
|
||||
if (!server) {
|
||||
return Promise.reject(new Error("server did not resolve"));
|
||||
}
|
||||
|
||||
return this.apiRequest("del", _Constants.Endpoints.ME_SERVER(server.id), true).then(function () {
|
||||
// remove channels of server then the server
|
||||
for (var _iterator2 = server.channels, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var chan = _ref2;
|
||||
|
||||
_this10.channels.remove(chan);
|
||||
}
|
||||
// remove server
|
||||
_this10.servers.remove(server);
|
||||
});
|
||||
return this.apiRequest("del", _Constants.Endpoints.ME_SERVER(server.id), true);
|
||||
};
|
||||
|
||||
//def deleteServer
|
||||
|
||||
InternalClient.prototype.deleteServer = function deleteServer(srv) {
|
||||
var _this11 = this;
|
||||
|
||||
var server = this.resolver.resolveServer(srv);
|
||||
if (!server) {
|
||||
return Promise.reject(new Error("server did not resolve"));
|
||||
}
|
||||
|
||||
return this.apiRequest("del", _Constants.Endpoints.SERVER(server.id), true).then(function () {
|
||||
// remove channels of server then the server
|
||||
for (var _iterator3 = server.channels, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||||
var _ref3;
|
||||
|
||||
if (_isArray3) {
|
||||
if (_i3 >= _iterator3.length) break;
|
||||
_ref3 = _iterator3[_i3++];
|
||||
} else {
|
||||
_i3 = _iterator3.next();
|
||||
if (_i3.done) break;
|
||||
_ref3 = _i3.value;
|
||||
}
|
||||
|
||||
var chan = _ref3;
|
||||
|
||||
_this11.channels.remove(chan);
|
||||
}
|
||||
// remove server
|
||||
_this11.servers.remove(server);
|
||||
});
|
||||
return this.apiRequest("del", _Constants.Endpoints.SERVER(server.id), true);
|
||||
};
|
||||
|
||||
// def loginWithToken
|
||||
// email and password are optional
|
||||
|
||||
InternalClient.prototype.loginWithToken = function loginWithToken(token, email, password) {
|
||||
var _this12 = this;
|
||||
var _this10 = this;
|
||||
|
||||
this.state = _ConnectionState2["default"].LOGGED_IN;
|
||||
this.token = token;
|
||||
@@ -638,7 +594,7 @@ var InternalClient = (function () {
|
||||
this.password = password;
|
||||
|
||||
return this.getGateway().then(function (url) {
|
||||
_this12.createWS(url);
|
||||
_this10.createWS(url);
|
||||
return token;
|
||||
});
|
||||
};
|
||||
@@ -646,14 +602,14 @@ var InternalClient = (function () {
|
||||
// def login
|
||||
|
||||
InternalClient.prototype.login = function login(email, password) {
|
||||
var _this13 = this;
|
||||
var _this11 = this;
|
||||
|
||||
var client = this.client;
|
||||
|
||||
if (!this.tokenCacher.done) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
setTimeout(function () {
|
||||
_this13.login(email, password).then(resolve)["catch"](reject);
|
||||
_this11.login(email, password).then(resolve)["catch"](reject);
|
||||
}, 20);
|
||||
});
|
||||
} else {
|
||||
@@ -674,16 +630,16 @@ var InternalClient = (function () {
|
||||
email: email,
|
||||
password: password
|
||||
}).then(function (res) {
|
||||
_this13.client.emit("debug", "direct API login, cached token was unavailable");
|
||||
_this11.client.emit("debug", "direct API login, cached token was unavailable");
|
||||
var token = res.token;
|
||||
_this13.tokenCacher.setToken(email, password, token);
|
||||
return _this13.loginWithToken(token, email, password);
|
||||
_this11.tokenCacher.setToken(email, password, token);
|
||||
return _this11.loginWithToken(token, email, password);
|
||||
}, function (error) {
|
||||
_this13.websocket = null;
|
||||
_this11.websocket = null;
|
||||
throw error;
|
||||
})["catch"](function (error) {
|
||||
_this13.websocket = null;
|
||||
_this13.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
_this11.websocket = null;
|
||||
_this11.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
client.emit("disconnected");
|
||||
throw error;
|
||||
});
|
||||
@@ -692,28 +648,28 @@ var InternalClient = (function () {
|
||||
// def logout
|
||||
|
||||
InternalClient.prototype.logout = function logout() {
|
||||
var _this14 = this;
|
||||
var _this12 = this;
|
||||
|
||||
if (this.state === _ConnectionState2["default"].DISCONNECTED || this.state === _ConnectionState2["default"].IDLE) {
|
||||
return Promise.reject(new Error("Client is not logged in!"));
|
||||
}
|
||||
|
||||
return this.apiRequest("post", _Constants.Endpoints.LOGOUT, true).then(function () {
|
||||
if (_this14.websocket) {
|
||||
_this14.websocket.close(1000);
|
||||
_this14.websocket = null;
|
||||
if (_this12.websocket) {
|
||||
_this12.websocket.close(1000);
|
||||
_this12.websocket = null;
|
||||
}
|
||||
_this14.token = null;
|
||||
_this14.email = null;
|
||||
_this14.password = null;
|
||||
_this14.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
_this12.token = null;
|
||||
_this12.email = null;
|
||||
_this12.password = null;
|
||||
_this12.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
});
|
||||
};
|
||||
|
||||
// def startPM
|
||||
|
||||
InternalClient.prototype.startPM = function startPM(resUser) {
|
||||
var _this15 = this;
|
||||
var _this13 = this;
|
||||
|
||||
var user = this.resolver.resolveUser(resUser);
|
||||
if (!user) {
|
||||
@@ -723,27 +679,27 @@ var InternalClient = (function () {
|
||||
return this.apiRequest("post", _Constants.Endpoints.ME_CHANNELS, true, {
|
||||
recipient_id: user.id
|
||||
}).then(function (res) {
|
||||
return _this15.private_channels.add(new _StructuresPMChannel2["default"](res, _this15.client));
|
||||
return _this13.private_channels.add(new _StructuresPMChannel2["default"](res, _this13.client));
|
||||
});
|
||||
};
|
||||
|
||||
// def getGateway
|
||||
|
||||
InternalClient.prototype.getGateway = function getGateway() {
|
||||
var _this16 = this;
|
||||
var _this14 = this;
|
||||
|
||||
if (this.gatewayURL) {
|
||||
return Promise.resolve(this.gatewayURL);
|
||||
}
|
||||
return this.apiRequest("get", _Constants.Endpoints.GATEWAY, true).then(function (res) {
|
||||
return _this16.gatewayURL = res.url;
|
||||
return _this14.gatewayURL = res.url;
|
||||
});
|
||||
};
|
||||
|
||||
// def sendMessage
|
||||
|
||||
InternalClient.prototype.sendMessage = function sendMessage(where, _content) {
|
||||
var _this17 = this;
|
||||
var _this15 = this;
|
||||
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
|
||||
@@ -766,26 +722,26 @@ var InternalClient = (function () {
|
||||
}
|
||||
|
||||
return this.resolver.resolveChannel(where).then(function (destination) {
|
||||
var content = _this17.resolver.resolveString(_content);
|
||||
var content = _this15.resolver.resolveString(_content);
|
||||
|
||||
if (options.file) {
|
||||
return _this17.resolver.resolveFile(options.file.file).then(function (file) {
|
||||
return _this17.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, {
|
||||
return _this15.resolver.resolveFile(options.file.file).then(function (file) {
|
||||
return _this15.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, {
|
||||
content: content,
|
||||
tts: options.tts
|
||||
}, {
|
||||
name: options.file.name,
|
||||
file: file
|
||||
}).then(function (res) {
|
||||
return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this17.client));
|
||||
return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this15.client));
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return _this17.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, {
|
||||
return _this15.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, {
|
||||
content: content,
|
||||
tts: options.tts
|
||||
}).then(function (res) {
|
||||
return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this17.client));
|
||||
return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this15.client));
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -794,7 +750,7 @@ var InternalClient = (function () {
|
||||
// def sendFile
|
||||
|
||||
InternalClient.prototype.sendFile = function sendFile(where, _file, name, content) {
|
||||
var _this18 = this;
|
||||
var _this16 = this;
|
||||
|
||||
if (!name) {
|
||||
if (_file instanceof String || typeof _file === "string") {
|
||||
@@ -814,12 +770,12 @@ var InternalClient = (function () {
|
||||
}
|
||||
|
||||
return this.resolver.resolveChannel(where).then(function (channel) {
|
||||
return _this18.resolver.resolveFile(_file).then(function (file) {
|
||||
return _this18.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, content, {
|
||||
return _this16.resolver.resolveFile(_file).then(function (file) {
|
||||
return _this16.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, content, {
|
||||
name: name,
|
||||
file: file
|
||||
}).then(function (res) {
|
||||
return channel.messages.add(new _StructuresMessage2["default"](res, channel, _this18.client));
|
||||
return channel.messages.add(new _StructuresMessage2["default"](res, channel, _this16.client));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -828,7 +784,7 @@ var InternalClient = (function () {
|
||||
// def deleteMessage
|
||||
|
||||
InternalClient.prototype.deleteMessage = function deleteMessage(_message) {
|
||||
var _this19 = this;
|
||||
var _this17 = this;
|
||||
|
||||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
||||
|
||||
@@ -839,7 +795,7 @@ var InternalClient = (function () {
|
||||
|
||||
var chain = options.wait ? delay(options.wait) : Promise.resolve();
|
||||
return chain.then(function () {
|
||||
return _this19.apiRequest("del", _Constants.Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id), true);
|
||||
return _this17.apiRequest("del", _Constants.Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id), true);
|
||||
}).then(function () {
|
||||
return message.channel.messages.remove(message);
|
||||
});
|
||||
@@ -853,19 +809,19 @@ var InternalClient = (function () {
|
||||
|
||||
var messages = [];
|
||||
var channel;
|
||||
for (var _iterator4 = _messages, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
|
||||
var _ref4;
|
||||
for (var _iterator2 = _messages, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray4) {
|
||||
if (_i4 >= _iterator4.length) break;
|
||||
_ref4 = _iterator4[_i4++];
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i4 = _iterator4.next();
|
||||
if (_i4.done) break;
|
||||
_ref4 = _i4.value;
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var _message = _ref4;
|
||||
var _message = _ref2;
|
||||
|
||||
var message = this.resolver.resolveMessage(_message);
|
||||
if (!message) return Promise.reject(new Error("Something other than a message could not be resolved in the array..."));
|
||||
@@ -895,7 +851,7 @@ var InternalClient = (function () {
|
||||
// def updateMessage
|
||||
|
||||
InternalClient.prototype.updateMessage = function updateMessage(msg, _content) {
|
||||
var _this20 = this;
|
||||
var _this18 = this;
|
||||
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
|
||||
@@ -911,14 +867,14 @@ var InternalClient = (function () {
|
||||
content: content,
|
||||
tts: options.tts
|
||||
}).then(function (res) {
|
||||
return message.channel.messages.update(message, new _StructuresMessage2["default"](res, message.channel, _this20.client));
|
||||
return message.channel.messages.update(message, new _StructuresMessage2["default"](res, message.channel, _this18.client));
|
||||
});
|
||||
};
|
||||
|
||||
// def getChannelLogs
|
||||
|
||||
InternalClient.prototype.getChannelLogs = function getChannelLogs(_channel) {
|
||||
var _this21 = this;
|
||||
var _this19 = this;
|
||||
|
||||
var limit = arguments.length <= 1 || arguments[1] === undefined ? 50 : arguments[1];
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
@@ -926,21 +882,21 @@ var InternalClient = (function () {
|
||||
return this.resolver.resolveChannel(_channel).then(function (channel) {
|
||||
var qsObject = { limit: limit };
|
||||
if (options.before) {
|
||||
var res = _this21.resolver.resolveMessage(options.before);
|
||||
var res = _this19.resolver.resolveMessage(options.before);
|
||||
if (res) {
|
||||
qsObject.before = res.id;
|
||||
}
|
||||
}
|
||||
if (options.after) {
|
||||
var res = _this21.resolver.resolveMessage(options.after);
|
||||
var res = _this19.resolver.resolveMessage(options.after);
|
||||
if (res) {
|
||||
qsObject.after = res.id;
|
||||
}
|
||||
}
|
||||
|
||||
return _this21.apiRequest("get", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id) + "?" + _querystring2["default"].stringify(qsObject), true).then(function (res) {
|
||||
return _this19.apiRequest("get", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id) + "?" + _querystring2["default"].stringify(qsObject), true).then(function (res) {
|
||||
return res.map(function (msg) {
|
||||
return channel.messages.add(new _StructuresMessage2["default"](msg, channel, _this21.client));
|
||||
return channel.messages.add(new _StructuresMessage2["default"](msg, channel, _this19.client));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -949,13 +905,13 @@ var InternalClient = (function () {
|
||||
// def getBans
|
||||
|
||||
InternalClient.prototype.getBans = function getBans(server) {
|
||||
var _this22 = this;
|
||||
var _this20 = this;
|
||||
|
||||
server = this.resolver.resolveServer(server);
|
||||
|
||||
return this.apiRequest("get", _Constants.Endpoints.SERVER_BANS(server.id), true).then(function (res) {
|
||||
return res.map(function (ban) {
|
||||
return _this22.users.add(new _StructuresUser2["default"](ban.user, _this22.client));
|
||||
return _this20.users.add(new _StructuresUser2["default"](ban.user, _this20.client));
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -963,7 +919,7 @@ var InternalClient = (function () {
|
||||
// def createChannel
|
||||
|
||||
InternalClient.prototype.createChannel = function createChannel(server, name) {
|
||||
var _this23 = this;
|
||||
var _this21 = this;
|
||||
|
||||
var type = arguments.length <= 2 || arguments[2] === undefined ? "text" : arguments[2];
|
||||
|
||||
@@ -975,23 +931,23 @@ var InternalClient = (function () {
|
||||
}).then(function (res) {
|
||||
var channel;
|
||||
if (res.type === "text") {
|
||||
channel = new _StructuresTextChannel2["default"](res, _this23.client, server);
|
||||
channel = new _StructuresTextChannel2["default"](res, _this21.client, server);
|
||||
} else {
|
||||
channel = new _StructuresVoiceChannel2["default"](res, _this23.client, server);
|
||||
channel = new _StructuresVoiceChannel2["default"](res, _this21.client, server);
|
||||
}
|
||||
return server.channels.add(_this23.channels.add(channel));
|
||||
return server.channels.add(_this21.channels.add(channel));
|
||||
});
|
||||
};
|
||||
|
||||
// def deleteChannel
|
||||
|
||||
InternalClient.prototype.deleteChannel = function deleteChannel(_channel) {
|
||||
var _this24 = this;
|
||||
var _this22 = this;
|
||||
|
||||
return this.resolver.resolveChannel(_channel).then(function (channel) {
|
||||
return _this24.apiRequest("del", _Constants.Endpoints.CHANNEL(channel.id), true).then(function () {
|
||||
return _this22.apiRequest("del", _Constants.Endpoints.CHANNEL(channel.id), true).then(function () {
|
||||
channel.server.channels.remove(channel);
|
||||
_this24.channels.remove(channel);
|
||||
_this22.channels.remove(channel);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1029,7 +985,7 @@ var InternalClient = (function () {
|
||||
// def moveMember
|
||||
|
||||
InternalClient.prototype.moveMember = function moveMember(user, channel) {
|
||||
var _this25 = this;
|
||||
var _this23 = this;
|
||||
|
||||
user = this.resolver.resolveUser(user);
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
@@ -1039,7 +995,7 @@ var InternalClient = (function () {
|
||||
if (channel.type !== "voice") {
|
||||
throw new Error("Can't moveMember into a non-voice channel");
|
||||
} else {
|
||||
return _this25.apiRequest("patch", _Constants.Endpoints.SERVER_MEMBERS(server.id) + "/" + user.id, true, { channel_id: channel.id }).then(function (res) {
|
||||
return _this23.apiRequest("patch", _Constants.Endpoints.SERVER_MEMBERS(server.id) + "/" + user.id, true, { channel_id: channel.id }).then(function (res) {
|
||||
user.voiceChannel = channel;
|
||||
return res;
|
||||
});
|
||||
@@ -1091,15 +1047,15 @@ var InternalClient = (function () {
|
||||
// def createRole
|
||||
|
||||
InternalClient.prototype.createRole = function createRole(server, data) {
|
||||
var _this26 = this;
|
||||
var _this24 = this;
|
||||
|
||||
server = this.resolver.resolveServer(server);
|
||||
|
||||
return this.apiRequest("post", _Constants.Endpoints.SERVER_ROLES(server.id), true).then(function (res) {
|
||||
var role = server.roles.add(new _StructuresRole2["default"](res, server, _this26.client));
|
||||
var role = server.roles.add(new _StructuresRole2["default"](res, server, _this24.client));
|
||||
|
||||
if (data) {
|
||||
return _this26.updateRole(role, data);
|
||||
return _this24.updateRole(role, data);
|
||||
}
|
||||
return role;
|
||||
});
|
||||
@@ -1108,7 +1064,7 @@ var InternalClient = (function () {
|
||||
// def updateRole
|
||||
|
||||
InternalClient.prototype.updateRole = function updateRole(role, data) {
|
||||
var _this27 = this;
|
||||
var _this25 = this;
|
||||
|
||||
role = this.resolver.resolveRole(role);
|
||||
var server = this.resolver.resolveServer(role.server);
|
||||
@@ -1124,19 +1080,19 @@ var InternalClient = (function () {
|
||||
|
||||
if (data.permissions) {
|
||||
newData.permissions = 0;
|
||||
for (var _iterator5 = data.permissions, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
|
||||
var _ref5;
|
||||
for (var _iterator3 = data.permissions, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||||
var _ref3;
|
||||
|
||||
if (_isArray5) {
|
||||
if (_i5 >= _iterator5.length) break;
|
||||
_ref5 = _iterator5[_i5++];
|
||||
if (_isArray3) {
|
||||
if (_i3 >= _iterator3.length) break;
|
||||
_ref3 = _iterator3[_i3++];
|
||||
} else {
|
||||
_i5 = _iterator5.next();
|
||||
if (_i5.done) break;
|
||||
_ref5 = _i5.value;
|
||||
_i3 = _iterator3.next();
|
||||
if (_i3.done) break;
|
||||
_ref3 = _i3.value;
|
||||
}
|
||||
|
||||
var perm = _ref5;
|
||||
var perm = _ref3;
|
||||
|
||||
if (perm instanceof String || typeof perm === "string") {
|
||||
newData.permissions |= _Constants.Permissions[perm] || 0;
|
||||
@@ -1147,7 +1103,7 @@ var InternalClient = (function () {
|
||||
}
|
||||
|
||||
return this.apiRequest("patch", _Constants.Endpoints.SERVER_ROLES(server.id) + "/" + role.id, true, newData).then(function (res) {
|
||||
return server.roles.update(role, new _StructuresRole2["default"](res, server, _this27.client));
|
||||
return server.roles.update(role, new _StructuresRole2["default"](res, server, _this25.client));
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1164,7 +1120,7 @@ var InternalClient = (function () {
|
||||
//def addMemberToRole
|
||||
|
||||
InternalClient.prototype.addMemberToRole = function addMemberToRole(member, roles) {
|
||||
var _this28 = this;
|
||||
var _this26 = this;
|
||||
|
||||
member = this.resolver.resolveUser(member);
|
||||
|
||||
@@ -1181,7 +1137,7 @@ var InternalClient = (function () {
|
||||
}
|
||||
} else {
|
||||
roles = roles.map(function (r) {
|
||||
return _this28.resolver.resolveRole(r);
|
||||
return _this26.resolver.resolveRole(r);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1219,19 +1175,19 @@ var InternalClient = (function () {
|
||||
|
||||
var roledata = role.server.rolesOf(member);
|
||||
if (roledata) {
|
||||
for (var _iterator6 = roledata, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
|
||||
var _ref6;
|
||||
for (var _iterator4 = roledata, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
|
||||
var _ref4;
|
||||
|
||||
if (_isArray6) {
|
||||
if (_i6 >= _iterator6.length) break;
|
||||
_ref6 = _iterator6[_i6++];
|
||||
if (_isArray4) {
|
||||
if (_i4 >= _iterator4.length) break;
|
||||
_ref4 = _iterator4[_i4++];
|
||||
} else {
|
||||
_i6 = _iterator6.next();
|
||||
if (_i6.done) break;
|
||||
_ref6 = _i6.value;
|
||||
_i4 = _iterator4.next();
|
||||
if (_i4.done) break;
|
||||
_ref4 = _i4.value;
|
||||
}
|
||||
|
||||
var r = _ref6;
|
||||
var r = _ref4;
|
||||
|
||||
if (r.id == role.id) {
|
||||
return r;
|
||||
@@ -1244,7 +1200,7 @@ var InternalClient = (function () {
|
||||
//def removeMemberFromRole
|
||||
|
||||
InternalClient.prototype.removeMemberFromRole = function removeMemberFromRole(member, roles) {
|
||||
var _this29 = this;
|
||||
var _this27 = this;
|
||||
|
||||
member = this.resolver.resolveUser(member);
|
||||
|
||||
@@ -1261,7 +1217,7 @@ var InternalClient = (function () {
|
||||
}
|
||||
} else {
|
||||
roles = roles.map(function (r) {
|
||||
return _this29.resolver.resolveRole(r);
|
||||
return _this27.resolver.resolveRole(r);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1269,19 +1225,19 @@ var InternalClient = (function () {
|
||||
return r && r.id || r;
|
||||
});
|
||||
|
||||
for (var _iterator7 = roles, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) {
|
||||
var _ref7;
|
||||
for (var _iterator5 = roles, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
|
||||
var _ref5;
|
||||
|
||||
if (_isArray7) {
|
||||
if (_i7 >= _iterator7.length) break;
|
||||
_ref7 = _iterator7[_i7++];
|
||||
if (_isArray5) {
|
||||
if (_i5 >= _iterator5.length) break;
|
||||
_ref5 = _iterator5[_i5++];
|
||||
} else {
|
||||
_i7 = _iterator7.next();
|
||||
if (_i7.done) break;
|
||||
_ref7 = _i7.value;
|
||||
_i5 = _iterator5.next();
|
||||
if (_i5.done) break;
|
||||
_ref5 = _i5.value;
|
||||
}
|
||||
|
||||
var role = _ref7;
|
||||
var role = _ref5;
|
||||
|
||||
if (!role.server.memberMap[member.id]) {
|
||||
return Promise.reject(new Error("member not in server"));
|
||||
@@ -1302,7 +1258,7 @@ var InternalClient = (function () {
|
||||
// def createInvite
|
||||
|
||||
InternalClient.prototype.createInvite = function createInvite(chanServ, options) {
|
||||
var _this30 = this;
|
||||
var _this28 = this;
|
||||
|
||||
return this.resolver.resolveChannel(chanServ).then(function (channel) {
|
||||
if (!options) {
|
||||
@@ -1316,8 +1272,8 @@ var InternalClient = (function () {
|
||||
options.xkcdpass = options.xkcd || false;
|
||||
}
|
||||
|
||||
return _this30.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true, options).then(function (res) {
|
||||
return new _StructuresInvite2["default"](res, _this30.channels.get("id", res.channel.id), _this30.client);
|
||||
return _this28.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true, options).then(function (res) {
|
||||
return new _StructuresInvite2["default"](res, _this28.channels.get("id", res.channel.id), _this28.client);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1335,7 +1291,7 @@ var InternalClient = (function () {
|
||||
//def getInvite
|
||||
|
||||
InternalClient.prototype.getInvite = function getInvite(invite) {
|
||||
var _this31 = this;
|
||||
var _this29 = this;
|
||||
|
||||
invite = this.resolver.resolveInviteID(invite);
|
||||
if (!invite) {
|
||||
@@ -1343,11 +1299,11 @@ var InternalClient = (function () {
|
||||
}
|
||||
|
||||
return this.apiRequest("get", _Constants.Endpoints.INVITE(invite), true).then(function (res) {
|
||||
if (!_this31.channels.has("id", res.channel.id)) {
|
||||
return new _StructuresInvite2["default"](res, null, _this31.client);
|
||||
if (!_this29.channels.has("id", res.channel.id)) {
|
||||
return new _StructuresInvite2["default"](res, null, _this29.client);
|
||||
}
|
||||
return _this31.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(res.channel.id), true, { validate: invite }).then(function (res2) {
|
||||
return new _StructuresInvite2["default"](res2, _this31.channels.get("id", res.channel.id), _this31.client);
|
||||
return _this29.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(res.channel.id), true, { validate: invite }).then(function (res2) {
|
||||
return new _StructuresInvite2["default"](res2, _this29.channels.get("id", res.channel.id), _this29.client);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1355,22 +1311,22 @@ var InternalClient = (function () {
|
||||
//def getInvites
|
||||
|
||||
InternalClient.prototype.getInvites = function getInvites(channel) {
|
||||
var _this32 = this;
|
||||
var _this30 = this;
|
||||
|
||||
if (!(channel instanceof _StructuresChannel2["default"])) {
|
||||
var server = this.resolver.resolveServer(channel);
|
||||
if (server) {
|
||||
return this.apiRequest("get", _Constants.Endpoints.SERVER_INVITES(server.id), true).then(function (res) {
|
||||
return res.map(function (data) {
|
||||
return new _StructuresInvite2["default"](data, _this32.channels.get("id", data.channel.id), _this32.client);
|
||||
return new _StructuresInvite2["default"](data, _this30.channels.get("id", data.channel.id), _this30.client);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
return _this32.apiRequest("get", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true).then(function (res) {
|
||||
return _this30.apiRequest("get", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true).then(function (res) {
|
||||
return res.map(function (data) {
|
||||
return new _StructuresInvite2["default"](data, _this32.channels.get("id", data.channel.id), _this32.client);
|
||||
return new _StructuresInvite2["default"](data, _this30.channels.get("id", data.channel.id), _this30.client);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1379,7 +1335,7 @@ var InternalClient = (function () {
|
||||
//def overwritePermissions
|
||||
|
||||
InternalClient.prototype.overwritePermissions = function overwritePermissions(channel, role, updated) {
|
||||
var _this33 = this;
|
||||
var _this31 = this;
|
||||
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
if (!channel instanceof _StructuresServerChannel2["default"]) {
|
||||
@@ -1392,7 +1348,7 @@ var InternalClient = (function () {
|
||||
};
|
||||
|
||||
if (role instanceof String || typeof role === "string") {
|
||||
role = _this33.resolver.resolveUser(role) || _this33.resolver.resolveRole(role);
|
||||
role = _this31.resolver.resolveUser(role) || _this31.resolver.resolveRole(role);
|
||||
}
|
||||
|
||||
if (role instanceof _StructuresUser2["default"]) {
|
||||
@@ -1425,7 +1381,7 @@ var InternalClient = (function () {
|
||||
}
|
||||
}
|
||||
|
||||
return _this33.apiRequest("put", _Constants.Endpoints.CHANNEL_PERMISSIONS(channel.id) + "/" + data.id, true, data);
|
||||
return _this31.apiRequest("put", _Constants.Endpoints.CHANNEL_PERMISSIONS(channel.id) + "/" + data.id, true, data);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1462,49 +1418,49 @@ var InternalClient = (function () {
|
||||
//def sendTyping
|
||||
|
||||
InternalClient.prototype.sendTyping = function sendTyping(channel) {
|
||||
var _this34 = this;
|
||||
var _this32 = this;
|
||||
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
return _this34.apiRequest("post", _Constants.Endpoints.CHANNEL(channel.id) + "/typing", true);
|
||||
return _this32.apiRequest("post", _Constants.Endpoints.CHANNEL(channel.id) + "/typing", true);
|
||||
});
|
||||
};
|
||||
|
||||
//def startTyping
|
||||
|
||||
InternalClient.prototype.startTyping = function startTyping(channel) {
|
||||
var _this35 = this;
|
||||
var _this33 = this;
|
||||
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
|
||||
if (_this35.intervals.typing[channel.id]) {
|
||||
if (_this33.intervals.typing[channel.id]) {
|
||||
// typing interval already exists, leave it alone
|
||||
throw new Error("Already typing in that channel");
|
||||
}
|
||||
|
||||
_this35.intervals.typing[channel.id] = setInterval(function () {
|
||||
return _this35.sendTyping(channel)["catch"](function (error) {
|
||||
return _this35.emit("error", error);
|
||||
_this33.intervals.typing[channel.id] = setInterval(function () {
|
||||
return _this33.sendTyping(channel)["catch"](function (error) {
|
||||
return _this33.emit("error", error);
|
||||
});
|
||||
}, 4000);
|
||||
|
||||
return _this35.sendTyping(channel);
|
||||
return _this33.sendTyping(channel);
|
||||
});
|
||||
};
|
||||
|
||||
//def stopTyping
|
||||
|
||||
InternalClient.prototype.stopTyping = function stopTyping(channel) {
|
||||
var _this36 = this;
|
||||
var _this34 = this;
|
||||
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
|
||||
if (!_this36.intervals.typing[channel.id]) {
|
||||
if (!_this34.intervals.typing[channel.id]) {
|
||||
// typing interval doesn"t exist
|
||||
throw new Error("Not typing in that channel");
|
||||
}
|
||||
|
||||
clearInterval(_this36.intervals.typing[channel.id]);
|
||||
_this36.intervals.typing[channel.id] = false;
|
||||
clearInterval(_this34.intervals.typing[channel.id]);
|
||||
_this34.intervals.typing[channel.id] = false;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1595,7 +1551,7 @@ var InternalClient = (function () {
|
||||
//def updateChannel
|
||||
|
||||
InternalClient.prototype.updateChannel = function updateChannel(channel, data) {
|
||||
var _this37 = this;
|
||||
var _this35 = this;
|
||||
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
if (!channel) {
|
||||
@@ -1624,7 +1580,7 @@ var InternalClient = (function () {
|
||||
|
||||
data.bitrate *= 1000; // convert to bits before sending
|
||||
|
||||
return _this37.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, data).then(function (res) {
|
||||
return _this35.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, data).then(function (res) {
|
||||
channel.name = data.name;
|
||||
channel.topic = data.topic;
|
||||
channel.position = data.position;
|
||||
@@ -1681,7 +1637,7 @@ var InternalClient = (function () {
|
||||
};
|
||||
|
||||
InternalClient.prototype.createWS = function createWS(url) {
|
||||
var _this38 = this;
|
||||
var _this36 = this;
|
||||
|
||||
var self = this;
|
||||
var client = self.client;
|
||||
@@ -1715,14 +1671,14 @@ var InternalClient = (function () {
|
||||
this.websocket.onclose = function (code) {
|
||||
self.websocket = null;
|
||||
self.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
self.disconnected(_this38.client.options.autoReconnect);
|
||||
self.disconnected(_this36.client.options.autoReconnect);
|
||||
};
|
||||
|
||||
this.websocket.onerror = function (e) {
|
||||
client.emit("error", e);
|
||||
self.websocket = null;
|
||||
self.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
self.disconnected(_this38.client.options.autoReconnect);
|
||||
self.disconnected(_this36.client.options.autoReconnect);
|
||||
};
|
||||
|
||||
this.websocket.onmessage = function (e) {
|
||||
@@ -1751,11 +1707,11 @@ var InternalClient = (function () {
|
||||
|
||||
self.user = self.users.add(new _StructuresUser2["default"](data.user, client));
|
||||
|
||||
_this38.forceFetchCount = {};
|
||||
_this38.forceFetchQueue = [];
|
||||
_this38.forceFetchLength = 1;
|
||||
_this38.autoReconnectInterval = 1000;
|
||||
_this38.sessionID = data.session_id;
|
||||
_this36.forceFetchCount = {};
|
||||
_this36.forceFetchQueue = [];
|
||||
_this36.forceFetchLength = 1;
|
||||
_this36.autoReconnectInterval = 1000;
|
||||
_this36.sessionID = data.session_id;
|
||||
|
||||
data.guilds.forEach(function (server) {
|
||||
if (!server.unavailable) {
|
||||
@@ -1893,53 +1849,53 @@ var InternalClient = (function () {
|
||||
if (!data.unavailable) {
|
||||
client.emit("serverDeleted", server);
|
||||
|
||||
for (var _iterator8 = server.channels, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
|
||||
var _ref8;
|
||||
for (var _iterator6 = server.channels, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
|
||||
var _ref6;
|
||||
|
||||
if (_isArray8) {
|
||||
if (_i8 >= _iterator8.length) break;
|
||||
_ref8 = _iterator8[_i8++];
|
||||
if (_isArray6) {
|
||||
if (_i6 >= _iterator6.length) break;
|
||||
_ref6 = _iterator6[_i6++];
|
||||
} else {
|
||||
_i8 = _iterator8.next();
|
||||
if (_i8.done) break;
|
||||
_ref8 = _i8.value;
|
||||
_i6 = _iterator6.next();
|
||||
if (_i6.done) break;
|
||||
_ref6 = _i6.value;
|
||||
}
|
||||
|
||||
var channel = _ref8;
|
||||
var channel = _ref6;
|
||||
|
||||
self.channels.remove(channel);
|
||||
}
|
||||
|
||||
self.servers.remove(server);
|
||||
|
||||
for (var _iterator9 = server.members, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) {
|
||||
var _ref9;
|
||||
for (var _iterator7 = server.members, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) {
|
||||
var _ref7;
|
||||
|
||||
if (_isArray9) {
|
||||
if (_i9 >= _iterator9.length) break;
|
||||
_ref9 = _iterator9[_i9++];
|
||||
if (_isArray7) {
|
||||
if (_i7 >= _iterator7.length) break;
|
||||
_ref7 = _iterator7[_i7++];
|
||||
} else {
|
||||
_i9 = _iterator9.next();
|
||||
if (_i9.done) break;
|
||||
_ref9 = _i9.value;
|
||||
_i7 = _iterator7.next();
|
||||
if (_i7.done) break;
|
||||
_ref7 = _i7.value;
|
||||
}
|
||||
|
||||
var user = _ref9;
|
||||
var user = _ref7;
|
||||
|
||||
var found = false;
|
||||
for (var _iterator10 = self.servers, _isArray10 = Array.isArray(_iterator10), _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) {
|
||||
var _ref10;
|
||||
for (var _iterator8 = self.servers, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
|
||||
var _ref8;
|
||||
|
||||
if (_isArray10) {
|
||||
if (_i10 >= _iterator10.length) break;
|
||||
_ref10 = _iterator10[_i10++];
|
||||
if (_isArray8) {
|
||||
if (_i8 >= _iterator8.length) break;
|
||||
_ref8 = _iterator8[_i8++];
|
||||
} else {
|
||||
_i10 = _iterator10.next();
|
||||
if (_i10.done) break;
|
||||
_ref10 = _i10.value;
|
||||
_i8 = _iterator8.next();
|
||||
if (_i8.done) break;
|
||||
_ref8 = _i8.value;
|
||||
}
|
||||
|
||||
var s = _ref10;
|
||||
var s = _ref8;
|
||||
|
||||
if (s.members.get("id", user.id)) {
|
||||
found = true;
|
||||
@@ -2198,7 +2154,7 @@ var InternalClient = (function () {
|
||||
data.id = data.id || user.id;
|
||||
data.avatar = data.avatar || user.avatar;
|
||||
data.discriminator = data.discriminator || user.discriminator;
|
||||
_this38.email = data.email || _this38.email;
|
||||
_this36.email = data.email || _this36.email;
|
||||
|
||||
var presenceUser = new _StructuresUser2["default"](data, client);
|
||||
|
||||
@@ -2298,19 +2254,19 @@ var InternalClient = (function () {
|
||||
|
||||
var testtime = Date.now();
|
||||
|
||||
for (var _iterator11 = data.members, _isArray11 = Array.isArray(_iterator11), _i11 = 0, _iterator11 = _isArray11 ? _iterator11 : _iterator11[Symbol.iterator]();;) {
|
||||
var _ref11;
|
||||
for (var _iterator9 = data.members, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) {
|
||||
var _ref9;
|
||||
|
||||
if (_isArray11) {
|
||||
if (_i11 >= _iterator11.length) break;
|
||||
_ref11 = _iterator11[_i11++];
|
||||
if (_isArray9) {
|
||||
if (_i9 >= _iterator9.length) break;
|
||||
_ref9 = _iterator9[_i9++];
|
||||
} else {
|
||||
_i11 = _iterator11.next();
|
||||
if (_i11.done) break;
|
||||
_ref11 = _i11.value;
|
||||
_i9 = _iterator9.next();
|
||||
if (_i9.done) break;
|
||||
_ref9 = _i9.value;
|
||||
}
|
||||
|
||||
var user = _ref11;
|
||||
var user = _ref9;
|
||||
|
||||
server.memberMap[user.user.id] = {
|
||||
roles: user.roles,
|
||||
@@ -2340,7 +2296,7 @@ var InternalClient = (function () {
|
||||
|
||||
break;
|
||||
case _Constants.PacketType.FRIEND_ADD:
|
||||
if (_this38.user.bot) {
|
||||
if (_this36.user.bot) {
|
||||
return;
|
||||
}
|
||||
if (data.type === 1) {
|
||||
@@ -2371,7 +2327,7 @@ var InternalClient = (function () {
|
||||
}
|
||||
break;
|
||||
case _Constants.PacketType.FRIEND_REMOVE:
|
||||
if (_this38.user.bot) {
|
||||
if (_this36.user.bot) {
|
||||
return;
|
||||
}
|
||||
var user = self.friends.get("id", data.id);
|
||||
|
||||
Reference in New Issue
Block a user