3.3.0 - added TTS capability

This commit is contained in:
hydrabolt
2015-09-05 13:57:15 +01:00
parent 064bbb169c
commit 012c706ab9
4 changed files with 46 additions and 21 deletions

View File

@@ -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();

View File

@@ -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": {

View File

@@ -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();

View File

@@ -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) {