mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
3.3.0 - added TTS capability
This commit is contained in:
@@ -323,13 +323,19 @@ var Client = (function () {
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "reply",
|
key: "reply",
|
||||||
value: function reply(destination, message) {
|
value: function reply(destination, message, tts) {
|
||||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2];
|
var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3];
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return new Promise(function (response, reject) {
|
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;
|
var user = destination.sender;
|
||||||
self.sendMessage(destination, message, callback, user + ", ").then(response)["catch"](reject);
|
self.sendMessage(destination, message, callback, user + ", ").then(response)["catch"](reject);
|
||||||
});
|
});
|
||||||
@@ -638,14 +644,20 @@ var Client = (function () {
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "sendMessage",
|
key: "sendMessage",
|
||||||
value: function sendMessage(destination, message) {
|
value: function sendMessage(destination, message, tts) {
|
||||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, msg) {} : arguments[2];
|
var callback = arguments.length <= 3 || arguments[3] === undefined ? function (err, msg) {} : arguments[3];
|
||||||
var premessage = arguments.length <= 3 || arguments[3] === undefined ? "" : arguments[3];
|
var premessage = arguments.length <= 4 || arguments[4] === undefined ? "" : arguments[4];
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var prom = new Promise(function (resolve, reject) {
|
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);
|
message = premessage + resolveMessage(message);
|
||||||
var mentions = resolveMentions();
|
var mentions = resolveMentions();
|
||||||
self.resolveDestination(destination).then(send)["catch"](error);
|
self.resolveDestination(destination).then(send)["catch"](error);
|
||||||
@@ -666,13 +678,14 @@ var Client = (function () {
|
|||||||
action: "sendMessage",
|
action: "sendMessage",
|
||||||
content: message,
|
content: message,
|
||||||
mentions: mentions,
|
mentions: mentions,
|
||||||
|
tts: !!tts, //incase it's not a boolean
|
||||||
then: mgood,
|
then: mgood,
|
||||||
error: mbad
|
error: mbad
|
||||||
});
|
});
|
||||||
|
|
||||||
self.checkQueue(destination);
|
self.checkQueue(destination);
|
||||||
} else {
|
} 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",
|
key: "_sendMessage",
|
||||||
value: function _sendMessage(destination, content, mentions) {
|
value: function _sendMessage(destination, content, tts, mentions) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({
|
request.post(Endpoints.CHANNELS + "/" + destination + "/messages").set("authorization", self.token).send({
|
||||||
content: content,
|
content: content,
|
||||||
mentions: mentions
|
mentions: mentions,
|
||||||
|
tts: tts
|
||||||
}).end(function (err, res) {
|
}).end(function (err, res) {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -1520,7 +1534,7 @@ var Client = (function () {
|
|||||||
switch (queuedEvent.action) {
|
switch (queuedEvent.action) {
|
||||||
case "sendMessage":
|
case "sendMessage":
|
||||||
var msgToSend = queuedEvent;
|
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);
|
msgToSend.then(msg);
|
||||||
self.queue[channelID].shift();
|
self.queue[channelID].shift();
|
||||||
doNext();
|
doNext();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord.js",
|
"name": "discord.js",
|
||||||
"version": "3.2.2",
|
"version": "3.3.0",
|
||||||
"description": "A way to interface with the Discord API",
|
"description": "A way to interface with the Discord API",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -361,12 +361,18 @@ class Client {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reply(destination, message, callback = function (err, msg) { }) {
|
reply(destination, message, tts, callback = function (err, msg) { }) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return new Promise(function (response, reject) {
|
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;
|
var user = destination.sender;
|
||||||
self.sendMessage(destination, message, callback, user + ", ").then(response).catch(reject);
|
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 self = this;
|
||||||
|
|
||||||
var prom = new Promise(function (resolve, reject) {
|
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);
|
message = premessage + resolveMessage(message);
|
||||||
var mentions = resolveMentions();
|
var mentions = resolveMentions();
|
||||||
self.resolveDestination(destination).then(send).catch(error);
|
self.resolveDestination(destination).then(send).catch(error);
|
||||||
@@ -670,13 +682,14 @@ class Client {
|
|||||||
action: "sendMessage",
|
action: "sendMessage",
|
||||||
content: message,
|
content: message,
|
||||||
mentions: mentions,
|
mentions: mentions,
|
||||||
|
tts : !!tts, //incase it's not a boolean
|
||||||
then: mgood,
|
then: mgood,
|
||||||
error: mbad
|
error: mbad
|
||||||
});
|
});
|
||||||
|
|
||||||
self.checkQueue(destination);
|
self.checkQueue(destination);
|
||||||
} else {
|
} 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;
|
var self = this;
|
||||||
|
|
||||||
@@ -1163,7 +1176,8 @@ class Client {
|
|||||||
.set("authorization", self.token)
|
.set("authorization", self.token)
|
||||||
.send({
|
.send({
|
||||||
content: content,
|
content: content,
|
||||||
mentions: mentions
|
mentions: mentions,
|
||||||
|
tts : tts
|
||||||
})
|
})
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
|
|
||||||
@@ -1277,7 +1291,7 @@ class Client {
|
|||||||
switch (queuedEvent.action) {
|
switch (queuedEvent.action) {
|
||||||
case "sendMessage":
|
case "sendMessage":
|
||||||
var msgToSend = queuedEvent;
|
var msgToSend = queuedEvent;
|
||||||
self._sendMessage(channelID, msgToSend.content, msgToSend.mentions)
|
self._sendMessage(channelID, msgToSend.content, msgToSend.tts, msgToSend.mentions)
|
||||||
.then(function (msg) {
|
.then(function (msg) {
|
||||||
msgToSend.then(msg);
|
msgToSend.then(msg);
|
||||||
self.queue[channelID].shift();
|
self.queue[channelID].shift();
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ mybot.on("message", function (message) {
|
|||||||
return;
|
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);
|
var action2 = mybot.sendMessage(message.channel, "this is message " + 2).then(log);
|
||||||
|
|
||||||
function log() {
|
function log() {
|
||||||
@@ -29,9 +29,6 @@ mybot.on("message", function (message) {
|
|||||||
|
|
||||||
mybot.on("ready", function(){
|
mybot.on("ready", function(){
|
||||||
console.log("im ready");
|
console.log("im ready");
|
||||||
setInterval(function(){
|
|
||||||
console.log(mybot.websocket.state, "state");
|
|
||||||
}, 2000);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function dump(msg) {
|
function dump(msg) {
|
||||||
|
|||||||
Reference in New Issue
Block a user