mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Merge pull request #519 from Hackzzila/indev
Added nonce support to 'sendMessage'
This commit is contained in:
@@ -80,6 +80,7 @@ var Client = (function (_EventEmitter) {
|
||||
this.options.shardId = options.shardId || 0;
|
||||
this.options.shardCount = options.shardCount || 0;
|
||||
this.options.disableEveryone = options.disableEveryone || false;
|
||||
this.options.bot = options.bot === undefined || options.bot === true ? true : false;
|
||||
|
||||
if (typeof options.shardCount === "number" && typeof options.shardId === "number" && options.shardCount > 0) {
|
||||
this.options.shard = [options.shardId, options.shardCount];
|
||||
|
||||
@@ -631,8 +631,6 @@ var InternalClient = (function () {
|
||||
// email and password are optional
|
||||
|
||||
InternalClient.prototype.loginWithToken = function loginWithToken(token, email, password) {
|
||||
var _this9 = this;
|
||||
|
||||
this.setup();
|
||||
|
||||
this.state = _ConnectionState2["default"].LOGGED_IN;
|
||||
@@ -640,23 +638,25 @@ var InternalClient = (function () {
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
|
||||
var self = this;
|
||||
return this.getGateway().then(function (url) {
|
||||
_this9.createWS(url);
|
||||
return token;
|
||||
self.token = self.client.options.bot && !self.token.startsWith("Bot ") ? "Bot " + self.token : self.token;
|
||||
self.createWS(url);
|
||||
return self.token;
|
||||
});
|
||||
};
|
||||
|
||||
// def login
|
||||
|
||||
InternalClient.prototype.login = function login(email, password) {
|
||||
var _this10 = this;
|
||||
var _this9 = this;
|
||||
|
||||
var client = this.client;
|
||||
|
||||
if (!this.tokenCacher.done) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
setTimeout(function () {
|
||||
_this10.login(email, password).then(resolve)["catch"](reject);
|
||||
_this9.login(email, password).then(resolve)["catch"](reject);
|
||||
}, 20);
|
||||
});
|
||||
} else {
|
||||
@@ -677,16 +677,16 @@ var InternalClient = (function () {
|
||||
email: email,
|
||||
password: password
|
||||
}).then(function (res) {
|
||||
_this10.client.emit("debug", "direct API login, cached token was unavailable");
|
||||
_this9.client.emit("debug", "direct API login, cached token was unavailable");
|
||||
var token = res.token;
|
||||
_this10.tokenCacher.setToken(email, password, token);
|
||||
return _this10.loginWithToken(token, email, password);
|
||||
_this9.tokenCacher.setToken(email, password, token);
|
||||
return _this9.loginWithToken(token, email, password);
|
||||
}, function (error) {
|
||||
_this10.websocket = null;
|
||||
_this9.websocket = null;
|
||||
throw error;
|
||||
})["catch"](function (error) {
|
||||
_this10.websocket = null;
|
||||
_this10.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
_this9.websocket = null;
|
||||
_this9.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
client.emit("disconnected");
|
||||
throw error;
|
||||
});
|
||||
@@ -695,21 +695,21 @@ var InternalClient = (function () {
|
||||
// def logout
|
||||
|
||||
InternalClient.prototype.logout = function logout() {
|
||||
var _this11 = this;
|
||||
var _this10 = this;
|
||||
|
||||
if (this.state === _ConnectionState2["default"].DISCONNECTED || this.state === _ConnectionState2["default"].IDLE) {
|
||||
return Promise.reject(new Error("Client is not logged in!"));
|
||||
}
|
||||
|
||||
var disconnect = function disconnect() {
|
||||
if (_this11.websocket) {
|
||||
_this11.websocket.close(1000);
|
||||
_this11.websocket = null;
|
||||
if (_this10.websocket) {
|
||||
_this10.websocket.close(1000);
|
||||
_this10.websocket = null;
|
||||
}
|
||||
_this11.token = null;
|
||||
_this11.email = null;
|
||||
_this11.password = null;
|
||||
_this11.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
_this10.token = null;
|
||||
_this10.email = null;
|
||||
_this10.password = null;
|
||||
_this10.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
@@ -723,7 +723,7 @@ var InternalClient = (function () {
|
||||
// def startPM
|
||||
|
||||
InternalClient.prototype.startPM = function startPM(resUser) {
|
||||
var _this12 = this;
|
||||
var _this11 = this;
|
||||
|
||||
var user = this.resolver.resolveUser(resUser);
|
||||
if (!user) {
|
||||
@@ -733,27 +733,27 @@ var InternalClient = (function () {
|
||||
return this.apiRequest("post", _Constants.Endpoints.ME_CHANNELS, true, {
|
||||
recipient_id: user.id
|
||||
}).then(function (res) {
|
||||
return _this12.private_channels.add(new _StructuresPMChannel2["default"](res, _this12.client));
|
||||
return _this11.private_channels.add(new _StructuresPMChannel2["default"](res, _this11.client));
|
||||
});
|
||||
};
|
||||
|
||||
// def getGateway
|
||||
|
||||
InternalClient.prototype.getGateway = function getGateway() {
|
||||
var _this13 = this;
|
||||
var _this12 = this;
|
||||
|
||||
if (this.gatewayURL) {
|
||||
return Promise.resolve(this.gatewayURL);
|
||||
}
|
||||
return this.apiRequest("get", _Constants.Endpoints.GATEWAY, true).then(function (res) {
|
||||
return _this13.gatewayURL = res.url;
|
||||
return _this12.gatewayURL = res.url;
|
||||
});
|
||||
};
|
||||
|
||||
// def sendMessage
|
||||
|
||||
InternalClient.prototype.sendMessage = function sendMessage(where, _content) {
|
||||
var _this14 = this;
|
||||
var _this13 = this;
|
||||
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
|
||||
@@ -776,30 +776,32 @@ var InternalClient = (function () {
|
||||
}
|
||||
|
||||
return this.resolver.resolveChannel(where).then(function (destination) {
|
||||
var content = _this14.resolver.resolveString(_content);
|
||||
var content = _this13.resolver.resolveString(_content);
|
||||
|
||||
if (_this14.client.options.disableEveryone || options.disableEveryone) {
|
||||
if (_this13.client.options.disableEveryone || options.disableEveryone) {
|
||||
content = content.replace(/(@)(everyone|here)/g, "$1$2");
|
||||
}
|
||||
|
||||
if (options.file) {
|
||||
return _this14.resolver.resolveFile(options.file.file).then(function (file) {
|
||||
return _this14.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, {
|
||||
return _this13.resolver.resolveFile(options.file.file).then(function (file) {
|
||||
return _this13.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, {
|
||||
content: content,
|
||||
tts: options.tts
|
||||
tts: options.tts,
|
||||
nonce: options.nonce
|
||||
}, {
|
||||
name: options.file.name,
|
||||
file: file
|
||||
}).then(function (res) {
|
||||
return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this14.client));
|
||||
return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this13.client));
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return _this14.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, {
|
||||
return _this13.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(destination.id), true, {
|
||||
content: content,
|
||||
tts: options.tts
|
||||
tts: options.tts,
|
||||
nonce: options.nonce
|
||||
}).then(function (res) {
|
||||
return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this14.client));
|
||||
return destination.messages.add(new _StructuresMessage2["default"](res, destination, _this13.client));
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -808,7 +810,7 @@ var InternalClient = (function () {
|
||||
// def sendFile
|
||||
|
||||
InternalClient.prototype.sendFile = function sendFile(where, _file, name, content) {
|
||||
var _this15 = this;
|
||||
var _this14 = this;
|
||||
|
||||
if (!name) {
|
||||
if (_file instanceof String || typeof _file === "string") {
|
||||
@@ -831,12 +833,12 @@ var InternalClient = (function () {
|
||||
}
|
||||
|
||||
return this.resolver.resolveChannel(where).then(function (channel) {
|
||||
return _this15.resolver.resolveFile(_file).then(function (file) {
|
||||
return _this15.apiRequest("post", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, content, {
|
||||
return _this14.resolver.resolveFile(_file).then(function (file) {
|
||||
return _this14.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, _this15.client));
|
||||
return channel.messages.add(new _StructuresMessage2["default"](res, channel, _this14.client));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -845,7 +847,7 @@ var InternalClient = (function () {
|
||||
// def deleteMessage
|
||||
|
||||
InternalClient.prototype.deleteMessage = function deleteMessage(_message) {
|
||||
var _this16 = this;
|
||||
var _this15 = this;
|
||||
|
||||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
||||
|
||||
@@ -856,7 +858,7 @@ var InternalClient = (function () {
|
||||
|
||||
var chain = options.wait ? delay(options.wait) : Promise.resolve();
|
||||
return chain.then(function () {
|
||||
return _this16.apiRequest("del", _Constants.Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id), true);
|
||||
return _this15.apiRequest("del", _Constants.Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id), true);
|
||||
}).then(function () {
|
||||
return message.channel.messages.remove(message);
|
||||
});
|
||||
@@ -912,7 +914,7 @@ var InternalClient = (function () {
|
||||
// def updateMessage
|
||||
|
||||
InternalClient.prototype.updateMessage = function updateMessage(msg, _content) {
|
||||
var _this17 = this;
|
||||
var _this16 = this;
|
||||
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
|
||||
@@ -928,14 +930,14 @@ var InternalClient = (function () {
|
||||
content: content,
|
||||
tts: options.tts
|
||||
}).then(function (res) {
|
||||
return message.channel.messages.update(message, new _StructuresMessage2["default"](res, message.channel, _this17.client));
|
||||
return message.channel.messages.update(message, new _StructuresMessage2["default"](res, message.channel, _this16.client));
|
||||
});
|
||||
};
|
||||
|
||||
// def getChannelLogs
|
||||
|
||||
InternalClient.prototype.getChannelLogs = function getChannelLogs(_channel) {
|
||||
var _this18 = this;
|
||||
var _this17 = this;
|
||||
|
||||
var limit = arguments.length <= 1 || arguments[1] === undefined ? 50 : arguments[1];
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
@@ -943,27 +945,27 @@ var InternalClient = (function () {
|
||||
return this.resolver.resolveChannel(_channel).then(function (channel) {
|
||||
var qsObject = { limit: limit };
|
||||
if (options.before) {
|
||||
var res = _this18.resolver.resolveMessage(options.before);
|
||||
var res = _this17.resolver.resolveMessage(options.before);
|
||||
if (res) {
|
||||
qsObject.before = res.id;
|
||||
}
|
||||
}
|
||||
if (options.after) {
|
||||
var res = _this18.resolver.resolveMessage(options.after);
|
||||
var res = _this17.resolver.resolveMessage(options.after);
|
||||
if (res) {
|
||||
qsObject.after = res.id;
|
||||
}
|
||||
}
|
||||
if (options.around) {
|
||||
var res = _this18.resolver.resolveMessage(options.around);
|
||||
var res = _this17.resolver.resolveMessage(options.around);
|
||||
if (res) {
|
||||
qsObject.around = res.id;
|
||||
}
|
||||
}
|
||||
|
||||
return _this18.apiRequest("get", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id) + "?" + _querystring2["default"].stringify(qsObject), true).then(function (res) {
|
||||
return _this17.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, _this18.client));
|
||||
return channel.messages.add(new _StructuresMessage2["default"](msg, channel, _this17.client));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -972,10 +974,10 @@ var InternalClient = (function () {
|
||||
// def getMessage
|
||||
|
||||
InternalClient.prototype.getMessage = function getMessage(_channel, messageID) {
|
||||
var _this19 = this;
|
||||
var _this18 = this;
|
||||
|
||||
return this.resolver.resolveChannel(_channel).then(function (channel) {
|
||||
if (!_this19.user.bot) {
|
||||
if (!_this18.user.bot) {
|
||||
return Promise.reject(new Error("Only OAuth bot accounts can use this function"));
|
||||
}
|
||||
|
||||
@@ -988,8 +990,8 @@ var InternalClient = (function () {
|
||||
return Promise.resolve(msg);
|
||||
}
|
||||
|
||||
return _this19.apiRequest("get", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id) + "/" + messageID, true).then(function (res) {
|
||||
return channel.messages.add(new _StructuresMessage2["default"](res, channel, _this19.client));
|
||||
return _this18.apiRequest("get", _Constants.Endpoints.CHANNEL_MESSAGES(channel.id) + "/" + messageID, true).then(function (res) {
|
||||
return channel.messages.add(new _StructuresMessage2["default"](res, channel, _this18.client));
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1025,12 +1027,12 @@ var InternalClient = (function () {
|
||||
// def getPinnedMessages
|
||||
|
||||
InternalClient.prototype.getPinnedMessages = function getPinnedMessages(_channel) {
|
||||
var _this20 = this;
|
||||
var _this19 = this;
|
||||
|
||||
return this.resolver.resolveChannel(_channel).then(function (channel) {
|
||||
return _this20.apiRequest("get", "" + _Constants.Endpoints.CHANNEL_PINS(channel.id), true).then(function (res) {
|
||||
return _this19.apiRequest("get", "" + _Constants.Endpoints.CHANNEL_PINS(channel.id), true).then(function (res) {
|
||||
return res.map(function (msg) {
|
||||
return channel.messages.add(new _StructuresMessage2["default"](msg, channel, _this20.client));
|
||||
return channel.messages.add(new _StructuresMessage2["default"](msg, channel, _this19.client));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1039,13 +1041,13 @@ var InternalClient = (function () {
|
||||
// def getBans
|
||||
|
||||
InternalClient.prototype.getBans = function getBans(server) {
|
||||
var _this21 = 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 _this21.users.add(new _StructuresUser2["default"](ban.user, _this21.client));
|
||||
return _this20.users.add(new _StructuresUser2["default"](ban.user, _this20.client));
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1053,7 +1055,7 @@ var InternalClient = (function () {
|
||||
// def createChannel
|
||||
|
||||
InternalClient.prototype.createChannel = function createChannel(server, name) {
|
||||
var _this22 = this;
|
||||
var _this21 = this;
|
||||
|
||||
var type = arguments.length <= 2 || arguments[2] === undefined ? "text" : arguments[2];
|
||||
|
||||
@@ -1065,26 +1067,26 @@ var InternalClient = (function () {
|
||||
}).then(function (res) {
|
||||
var channel;
|
||||
if (res.type === "text") {
|
||||
channel = new _StructuresTextChannel2["default"](res, _this22.client, server);
|
||||
channel = new _StructuresTextChannel2["default"](res, _this21.client, server);
|
||||
} else {
|
||||
channel = new _StructuresVoiceChannel2["default"](res, _this22.client, server);
|
||||
channel = new _StructuresVoiceChannel2["default"](res, _this21.client, server);
|
||||
}
|
||||
return server.channels.add(_this22.channels.add(channel));
|
||||
return server.channels.add(_this21.channels.add(channel));
|
||||
});
|
||||
};
|
||||
|
||||
// def deleteChannel
|
||||
|
||||
InternalClient.prototype.deleteChannel = function deleteChannel(_channel) {
|
||||
var _this23 = this;
|
||||
var _this22 = this;
|
||||
|
||||
return this.resolver.resolveChannel(_channel).then(function (channel) {
|
||||
return _this23.apiRequest("del", _Constants.Endpoints.CHANNEL(channel.id), true).then(function () {
|
||||
return _this22.apiRequest("del", _Constants.Endpoints.CHANNEL(channel.id), true).then(function () {
|
||||
if (channel.server) {
|
||||
channel.server.channels.remove(channel);
|
||||
_this23.channels.remove(channel);
|
||||
_this22.channels.remove(channel);
|
||||
} else {
|
||||
_this23.private_channels.remove(channel);
|
||||
_this22.private_channels.remove(channel);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1123,7 +1125,7 @@ var InternalClient = (function () {
|
||||
// def moveMember
|
||||
|
||||
InternalClient.prototype.moveMember = function moveMember(user, channel) {
|
||||
var _this24 = this;
|
||||
var _this23 = this;
|
||||
|
||||
user = this.resolver.resolveUser(user);
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
@@ -1133,7 +1135,7 @@ var InternalClient = (function () {
|
||||
if (channel.type !== "voice") {
|
||||
throw new Error("Can't moveMember into a non-voice channel");
|
||||
} else {
|
||||
return _this24.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;
|
||||
});
|
||||
@@ -1198,15 +1200,15 @@ var InternalClient = (function () {
|
||||
// def createRole
|
||||
|
||||
InternalClient.prototype.createRole = function createRole(server, data) {
|
||||
var _this25 = 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, _this25.client));
|
||||
var role = server.roles.add(new _StructuresRole2["default"](res, server, _this24.client));
|
||||
|
||||
if (data) {
|
||||
return _this25.updateRole(role, data);
|
||||
return _this24.updateRole(role, data);
|
||||
}
|
||||
return role;
|
||||
});
|
||||
@@ -1215,7 +1217,7 @@ var InternalClient = (function () {
|
||||
// def updateRole
|
||||
|
||||
InternalClient.prototype.updateRole = function updateRole(role, data) {
|
||||
var _this26 = this;
|
||||
var _this25 = this;
|
||||
|
||||
role = this.resolver.resolveRole(role);
|
||||
var server = this.resolver.resolveServer(role.server);
|
||||
@@ -1254,7 +1256,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, _this26.client));
|
||||
return server.roles.update(role, new _StructuresRole2["default"](res, server, _this25.client));
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1271,7 +1273,7 @@ var InternalClient = (function () {
|
||||
//def addMemberToRole
|
||||
|
||||
InternalClient.prototype.addMemberToRole = function addMemberToRole(member, roles) {
|
||||
var _this27 = this;
|
||||
var _this26 = this;
|
||||
|
||||
member = this.resolver.resolveUser(member);
|
||||
|
||||
@@ -1288,7 +1290,7 @@ var InternalClient = (function () {
|
||||
}
|
||||
} else {
|
||||
roles = roles.map(function (r) {
|
||||
return _this27.resolver.resolveRole(r);
|
||||
return _this26.resolver.resolveRole(r);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1351,7 +1353,7 @@ var InternalClient = (function () {
|
||||
//def removeMemberFromRole
|
||||
|
||||
InternalClient.prototype.removeMemberFromRole = function removeMemberFromRole(member, roles) {
|
||||
var _this28 = this;
|
||||
var _this27 = this;
|
||||
|
||||
member = this.resolver.resolveUser(member);
|
||||
|
||||
@@ -1368,7 +1370,7 @@ var InternalClient = (function () {
|
||||
}
|
||||
} else {
|
||||
roles = roles.map(function (r) {
|
||||
return _this28.resolver.resolveRole(r);
|
||||
return _this27.resolver.resolveRole(r);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1409,7 +1411,7 @@ var InternalClient = (function () {
|
||||
// def createInvite
|
||||
|
||||
InternalClient.prototype.createInvite = function createInvite(chanServ, options) {
|
||||
var _this29 = this;
|
||||
var _this28 = this;
|
||||
|
||||
return this.resolver.resolveChannel(chanServ).then(function (channel) {
|
||||
if (!options) {
|
||||
@@ -1423,8 +1425,8 @@ var InternalClient = (function () {
|
||||
options.xkcdpass = options.xkcd || false;
|
||||
}
|
||||
|
||||
return _this29.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(channel.id), true, options).then(function (res) {
|
||||
return new _StructuresInvite2["default"](res, _this29.channels.get("id", res.channel.id), _this29.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);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1442,7 +1444,7 @@ var InternalClient = (function () {
|
||||
//def getInvite
|
||||
|
||||
InternalClient.prototype.getInvite = function getInvite(invite) {
|
||||
var _this30 = this;
|
||||
var _this29 = this;
|
||||
|
||||
invite = this.resolver.resolveInviteID(invite);
|
||||
if (!invite) {
|
||||
@@ -1450,11 +1452,11 @@ var InternalClient = (function () {
|
||||
}
|
||||
|
||||
return this.apiRequest("get", _Constants.Endpoints.INVITE(invite), true).then(function (res) {
|
||||
if (!_this30.channels.has("id", res.channel.id)) {
|
||||
return new _StructuresInvite2["default"](res, null, _this30.client);
|
||||
if (!_this29.channels.has("id", res.channel.id)) {
|
||||
return new _StructuresInvite2["default"](res, null, _this29.client);
|
||||
}
|
||||
return _this30.apiRequest("post", _Constants.Endpoints.CHANNEL_INVITES(res.channel.id), true, { validate: invite }).then(function (res2) {
|
||||
return new _StructuresInvite2["default"](res2, _this30.channels.get("id", res.channel.id), _this30.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);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1462,22 +1464,22 @@ var InternalClient = (function () {
|
||||
//def getInvites
|
||||
|
||||
InternalClient.prototype.getInvites = function getInvites(channel) {
|
||||
var _this31 = 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, _this31.channels.get("id", data.channel.id), _this31.client);
|
||||
return new _StructuresInvite2["default"](data, _this30.channels.get("id", data.channel.id), _this30.client);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
return _this31.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, _this31.channels.get("id", data.channel.id), _this31.client);
|
||||
return new _StructuresInvite2["default"](data, _this30.channels.get("id", data.channel.id), _this30.client);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1486,7 +1488,7 @@ var InternalClient = (function () {
|
||||
//def overwritePermissions
|
||||
|
||||
InternalClient.prototype.overwritePermissions = function overwritePermissions(channel, role, updated) {
|
||||
var _this32 = this;
|
||||
var _this31 = this;
|
||||
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
if (!channel instanceof _StructuresServerChannel2["default"]) {
|
||||
@@ -1499,7 +1501,7 @@ var InternalClient = (function () {
|
||||
};
|
||||
|
||||
if (role instanceof String || typeof role === "string") {
|
||||
role = _this32.resolver.resolveUser(role) || _this32.resolver.resolveRole(role);
|
||||
role = _this31.resolver.resolveUser(role) || _this31.resolver.resolveRole(role);
|
||||
}
|
||||
|
||||
if (role instanceof _StructuresUser2["default"]) {
|
||||
@@ -1532,7 +1534,7 @@ var InternalClient = (function () {
|
||||
}
|
||||
}
|
||||
|
||||
return _this32.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);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1572,49 +1574,49 @@ var InternalClient = (function () {
|
||||
//def sendTyping
|
||||
|
||||
InternalClient.prototype.sendTyping = function sendTyping(channel) {
|
||||
var _this33 = this;
|
||||
var _this32 = this;
|
||||
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
return _this33.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 _this34 = this;
|
||||
var _this33 = this;
|
||||
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
|
||||
if (_this34.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");
|
||||
}
|
||||
|
||||
_this34.intervals.typing[channel.id] = setInterval(function () {
|
||||
return _this34.sendTyping(channel)["catch"](function (error) {
|
||||
return _this34.emit("error", error);
|
||||
_this33.intervals.typing[channel.id] = setInterval(function () {
|
||||
return _this33.sendTyping(channel)["catch"](function (error) {
|
||||
return _this33.emit("error", error);
|
||||
});
|
||||
}, 4000);
|
||||
|
||||
return _this34.sendTyping(channel);
|
||||
return _this33.sendTyping(channel);
|
||||
});
|
||||
};
|
||||
|
||||
//def stopTyping
|
||||
|
||||
InternalClient.prototype.stopTyping = function stopTyping(channel) {
|
||||
var _this35 = this;
|
||||
var _this34 = this;
|
||||
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
|
||||
if (!_this35.intervals.typing[channel.id]) {
|
||||
if (!_this34.intervals.typing[channel.id]) {
|
||||
// typing interval doesn"t exist
|
||||
throw new Error("Not typing in that channel");
|
||||
}
|
||||
|
||||
clearInterval(_this35.intervals.typing[channel.id]);
|
||||
_this35.intervals.typing[channel.id] = false;
|
||||
clearInterval(_this34.intervals.typing[channel.id]);
|
||||
_this34.intervals.typing[channel.id] = false;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1696,7 +1698,7 @@ var InternalClient = (function () {
|
||||
//def updateChannel
|
||||
|
||||
InternalClient.prototype.updateChannel = function updateChannel(channel, data) {
|
||||
var _this36 = this;
|
||||
var _this35 = this;
|
||||
|
||||
return this.resolver.resolveChannel(channel).then(function (channel) {
|
||||
if (!channel) {
|
||||
@@ -1727,7 +1729,7 @@ var InternalClient = (function () {
|
||||
data.bitrate *= 1000; // convert to bits before sending
|
||||
}
|
||||
|
||||
return _this36.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;
|
||||
@@ -1791,7 +1793,7 @@ var InternalClient = (function () {
|
||||
};
|
||||
|
||||
InternalClient.prototype.createWS = function createWS(url) {
|
||||
var _this37 = this;
|
||||
var _this36 = this;
|
||||
|
||||
var self = this;
|
||||
var client = self.client;
|
||||
@@ -1846,7 +1848,7 @@ var InternalClient = (function () {
|
||||
}if (event.code === 4006 || event.code === 4009) {
|
||||
err = new Error("Invalid session");
|
||||
} else if (event.code === 4007) {
|
||||
_this37.seq = 0;
|
||||
_this36.seq = 0;
|
||||
err = new Error("Invalid sequence number");
|
||||
} else if (event.code === 4008) {
|
||||
err = new Error("Gateway connection was ratelimited");
|
||||
@@ -1857,14 +1859,14 @@ var InternalClient = (function () {
|
||||
client.emit("error", err);
|
||||
}
|
||||
}
|
||||
self.disconnected(_this37.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(_this37.client.options.autoReconnect);
|
||||
self.disconnected(_this36.client.options.autoReconnect);
|
||||
};
|
||||
|
||||
this.websocket.onmessage = function (e) {
|
||||
@@ -1893,11 +1895,11 @@ var InternalClient = (function () {
|
||||
|
||||
self.user = self.users.add(new _StructuresUser2["default"](data.user, client));
|
||||
|
||||
_this37.forceFetchCount = {};
|
||||
_this37.forceFetchQueue = [];
|
||||
_this37.forceFetchLength = 1;
|
||||
_this37.autoReconnectInterval = 1000;
|
||||
_this37.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) {
|
||||
@@ -2362,7 +2364,7 @@ var InternalClient = (function () {
|
||||
data.id = data.id || user.id;
|
||||
data.avatar = data.avatar || user.avatar;
|
||||
data.discriminator = data.discriminator || user.discriminator;
|
||||
_this37.email = data.email || _this37.email;
|
||||
_this36.email = data.email || _this36.email;
|
||||
|
||||
var presenceUser = new _StructuresUser2["default"](data, client);
|
||||
|
||||
@@ -2420,7 +2422,7 @@ var InternalClient = (function () {
|
||||
}
|
||||
break;
|
||||
case _Constants.PacketType.USER_NOTE_UPDATE:
|
||||
if (_this37.user.bot) {
|
||||
if (_this36.user.bot) {
|
||||
return;
|
||||
}
|
||||
var user = self.users.get("id", data.id);
|
||||
@@ -2524,7 +2526,7 @@ var InternalClient = (function () {
|
||||
|
||||
break;
|
||||
case _Constants.PacketType.FRIEND_ADD:
|
||||
if (_this37.user.bot) {
|
||||
if (_this36.user.bot) {
|
||||
return;
|
||||
}
|
||||
if (data.type === 1) {
|
||||
@@ -2555,7 +2557,7 @@ var InternalClient = (function () {
|
||||
}
|
||||
break;
|
||||
case _Constants.PacketType.FRIEND_REMOVE:
|
||||
if (_this37.user.bot) {
|
||||
if (_this36.user.bot) {
|
||||
return;
|
||||
}
|
||||
var user = self.friends.get("id", data.id);
|
||||
|
||||
@@ -6,23 +6,23 @@ exports.__esModule = true;
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var TokenCacher = (function () {
|
||||
function TokenCacher() {
|
||||
_classCallCheck(this, TokenCacher);
|
||||
}
|
||||
function TokenCacher() {
|
||||
_classCallCheck(this, TokenCacher);
|
||||
}
|
||||
|
||||
TokenCacher.prototype.setToken = function setToken() {};
|
||||
TokenCacher.prototype.setToken = function setToken() {};
|
||||
|
||||
TokenCacher.prototype.save = function save() {};
|
||||
TokenCacher.prototype.save = function save() {};
|
||||
|
||||
TokenCacher.prototype.getToken = function getToken() {
|
||||
return null;
|
||||
};
|
||||
TokenCacher.prototype.getToken = function getToken() {
|
||||
return null;
|
||||
};
|
||||
|
||||
TokenCacher.prototype.init = function init(ind) {
|
||||
this.done = true;
|
||||
};
|
||||
TokenCacher.prototype.init = function init(ind) {
|
||||
this.done = true;
|
||||
};
|
||||
|
||||
return TokenCacher;
|
||||
return TokenCacher;
|
||||
})();
|
||||
|
||||
exports["default"] = TokenCacher;
|
||||
|
||||
@@ -658,7 +658,8 @@ export default class InternalClient {
|
||||
.then(file =>
|
||||
this.apiRequest("post", Endpoints.CHANNEL_MESSAGES(destination.id), true, {
|
||||
content: content,
|
||||
tts: options.tts
|
||||
tts: options.tts,
|
||||
nonce: options.nonce
|
||||
}, {
|
||||
name: options.file.name,
|
||||
file: file
|
||||
@@ -667,7 +668,8 @@ export default class InternalClient {
|
||||
} else {
|
||||
return this.apiRequest("post", Endpoints.CHANNEL_MESSAGES(destination.id), true, {
|
||||
content: content,
|
||||
tts: options.tts
|
||||
tts: options.tts,
|
||||
nonce: options.nonce
|
||||
})
|
||||
.then(res => destination.messages.add(new Message(res, destination, this.client)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user