diff --git a/lib/Client.js b/lib/Client.js index 313e21686..85119d53a 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -323,13 +323,19 @@ var Client = (function () { } }, { key: "reply", - value: function reply(destination, message) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; + value: function reply(destination, message, tts) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; var self = this; return new Promise(function (response, reject) { + if (typeof tts === "function") { + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } + var user = destination.sender; self.sendMessage(destination, message, callback, user + ", ").then(response)["catch"](reject); }); @@ -638,14 +644,20 @@ var Client = (function () { } }, { key: "sendMessage", - value: function sendMessage(destination, message) { - var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2]; - var premessage = arguments.length <= 3 || arguments[3] === undefined ? "" : arguments[3]; + value: function sendMessage(destination, message, tts) { + var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3]; + var premessage = arguments.length <= 4 || arguments[4] === undefined ? "" : arguments[4]; var self = this; var prom = new Promise(function (resolve, reject) { + if (typeof tts === "function") { + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } + message = premessage + resolveMessage(message); var mentions = resolveMentions(); self.resolveDestination(destination).then(send)["catch"](error); @@ -666,13 +678,14 @@ var Client = (function () { action: "sendMessage", content: message, mentions: mentions, + tts: !!tts, //incase it's not a boolean then: mgood, error: mbad }); self.checkQueue(destination); } else { - self._sendMessage(destination, message, mentions).then(mgood)["catch"](mbad); + self._sendMessage(destination, message, tts, mentions).then(mgood)["catch"](mbad); } } @@ -1393,14 +1406,15 @@ var Client = (function () { } }, { key: "_sendMessage", - value: function _sendMessage(destination, content, mentions) { + value: function _sendMessage(destination, content, tts, mentions) { var self = this; return new Promise(function (resolve, reject) { request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({ content: content, - mentions: mentions + mentions: mentions, + tts: tts }).end(function (err, res) { if (err) { @@ -1520,7 +1534,7 @@ var Client = (function () { switch (queuedEvent.action) { case "sendMessage": var msgToSend = queuedEvent; - self._sendMessage(channelID, msgToSend.content, msgToSend.mentions).then(function (msg) { + self._sendMessage(channelID, msgToSend.content, msgToSend.tts, msgToSend.mentions).then(function (msg) { msgToSend.then(msg); self.queue[channelID].shift(); doNext(); diff --git a/package.json b/package.json index a83a52a24..e1c2cc82f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "3.2.2", + "version": "3.3.0", "description": "A way to interface with the Discord API", "main": "./lib/index.js", "scripts": { diff --git a/src/Client.js b/src/Client.js index 582c6cb70..03cb6a577 100644 --- a/src/Client.js +++ b/src/Client.js @@ -361,12 +361,18 @@ class Client { } - reply(destination, message, callback = function (err, msg) { }) { + reply(destination, message, tts, callback = function (err, msg) { }) { var self = this; return new Promise(function (response, reject) { + if(typeof tts === "function"){ + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } + var user = destination.sender; self.sendMessage(destination, message, callback, user + ", ").then(response).catch(reject); @@ -644,12 +650,18 @@ class Client { } - sendMessage(destination, message, callback = function (err, msg) { }, premessage = "") { + sendMessage(destination, message, tts, callback = function (err, msg) { }, premessage = "") { var self = this; var prom = new Promise(function (resolve, reject) { - + + if(typeof tts === "function"){ + // tts is a function, which means the developer wants this to be the callback + callback = tts; + tts = false; + } + message = premessage + resolveMessage(message); var mentions = resolveMentions(); self.resolveDestination(destination).then(send).catch(error); @@ -670,13 +682,14 @@ class Client { action: "sendMessage", content: message, mentions: mentions, + tts : !!tts, //incase it's not a boolean then: mgood, error: mbad }); self.checkQueue(destination); } else { - self._sendMessage(destination, message, mentions).then(mgood).catch(mbad); + self._sendMessage(destination, message, tts, mentions).then(mgood).catch(mbad); } } @@ -1153,7 +1166,7 @@ class Client { }); } - _sendMessage(destination, content, mentions) { + _sendMessage(destination, content, tts, mentions) { var self = this; @@ -1163,7 +1176,8 @@ class Client { .set("authorization", self.token) .send({ content: content, - mentions: mentions + mentions: mentions, + tts : tts }) .end(function (err, res) { @@ -1277,7 +1291,7 @@ class Client { switch (queuedEvent.action) { case "sendMessage": var msgToSend = queuedEvent; - self._sendMessage(channelID, msgToSend.content, msgToSend.mentions) + self._sendMessage(channelID, msgToSend.content, msgToSend.tts, msgToSend.mentions) .then(function (msg) { msgToSend.then(msg); self.queue[channelID].shift(); diff --git a/test/bot.1.js b/test/bot.1.js index 9293b401d..eb99418bf 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -16,7 +16,7 @@ mybot.on("message", function (message) { return; } - var action1 = mybot.sendMessage(message.channel, "this is message " + 1); + var action1 = mybot.sendMessage(message.channel, "this is message " + 1, true); var action2 = mybot.sendMessage(message.channel, "this is message " + 2).then(log); function log() { @@ -29,9 +29,6 @@ mybot.on("message", function (message) { mybot.on("ready", function(){ console.log("im ready"); - setInterval(function(){ - console.log(mybot.websocket.state, "state"); - }, 2000); }) function dump(msg) {