mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
@@ -148,7 +148,7 @@ var Client = (function () {
|
|||||||
self.state = 2; //set state to logged in (not yet ready)
|
self.state = 2; //set state to logged in (not yet ready)
|
||||||
self.token = res.body.token; //set our token
|
self.token = res.body.token; //set our token
|
||||||
|
|
||||||
getGateway().then(function (url) {
|
self.getGateway().then(function (url) {
|
||||||
self.createws(url);
|
self.createws(url);
|
||||||
callback(null, self.token);
|
callback(null, self.token);
|
||||||
resolve(self.token);
|
resolve(self.token);
|
||||||
@@ -337,7 +337,7 @@ var Client = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var user = destination.sender;
|
var user = destination.sender;
|
||||||
self.sendMessage(destination, message, callback, user + ", ").then(response)["catch"](reject);
|
self.sendMessage(destination, message, tts, callback, user + ", ").then(response)["catch"](reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
@@ -1600,6 +1600,20 @@ var Client = (function () {
|
|||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
key: "getGateway",
|
||||||
|
value: function getGateway() {
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
request.get(Endpoints.API + "/gateway").set("authorization", self.token).end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve(res.body.url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "uptime",
|
key: "uptime",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
@@ -1668,19 +1682,4 @@ var Client = (function () {
|
|||||||
return Client;
|
return Client;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
function getGateway() {
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
|
||||||
request.get(Endpoints.API + "/gateway").end(function (err, res) {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve(res.body.url);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Client;
|
module.exports = Client;
|
||||||
@@ -64,7 +64,7 @@ var Channel = (function () {
|
|||||||
}, {
|
}, {
|
||||||
key: "toString",
|
key: "toString",
|
||||||
value: function toString() {
|
value: function toString() {
|
||||||
return "#" + this.name;
|
return "<#" + this.id + ">";
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "client",
|
key: "client",
|
||||||
|
|||||||
@@ -165,6 +165,11 @@ var Server = (function () {
|
|||||||
get: function get() {
|
get: function get() {
|
||||||
return this.client.getUser("id", this.ownerID);
|
return this.client.getUser("id", this.ownerID);
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
key: "users",
|
||||||
|
get: function get() {
|
||||||
|
return this.members;
|
||||||
|
}
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
return Server;
|
return Server;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord.js",
|
"name": "discord.js",
|
||||||
"version": "3.3.2",
|
"version": "3.3.3",
|
||||||
"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": {
|
||||||
|
|||||||
192
src/Client.js
192
src/Client.js
@@ -153,7 +153,7 @@ class Client {
|
|||||||
if (err) {
|
if (err) {
|
||||||
self.state = 4; //set state to disconnected
|
self.state = 4; //set state to disconnected
|
||||||
self.trigger("disconnected");
|
self.trigger("disconnected");
|
||||||
if(self.websocket){
|
if (self.websocket) {
|
||||||
self.websocket.close();
|
self.websocket.close();
|
||||||
}
|
}
|
||||||
callback(err);
|
callback(err);
|
||||||
@@ -162,7 +162,7 @@ class Client {
|
|||||||
self.state = 2; //set state to logged in (not yet ready)
|
self.state = 2; //set state to logged in (not yet ready)
|
||||||
self.token = res.body.token; //set our token
|
self.token = res.body.token; //set our token
|
||||||
|
|
||||||
getGateway().then(function (url) {
|
self.getGateway().then(function (url) {
|
||||||
self.createws(url);
|
self.createws(url);
|
||||||
callback(null, self.token);
|
callback(null, self.token);
|
||||||
resolve(self.token);
|
resolve(self.token);
|
||||||
@@ -367,14 +367,14 @@ class Client {
|
|||||||
|
|
||||||
return new Promise(function (response, reject) {
|
return new Promise(function (response, reject) {
|
||||||
|
|
||||||
if(typeof tts === "function"){
|
if (typeof tts === "function") {
|
||||||
// tts is a function, which means the developer wants this to be the callback
|
// tts is a function, which means the developer wants this to be the callback
|
||||||
callback = tts;
|
callback = tts;
|
||||||
tts = false;
|
tts = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = destination.sender;
|
var user = destination.sender;
|
||||||
self.sendMessage(destination, message, callback, user + ", ").then(response).catch(reject);
|
self.sendMessage(destination, message, tts, callback, user + ", ").then(response).catch(reject);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -392,7 +392,7 @@ class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function remove() {
|
function remove() {
|
||||||
if(self.options.queue){
|
if (self.options.queue) {
|
||||||
if (!self.queue[message.channel.id]) {
|
if (!self.queue[message.channel.id]) {
|
||||||
self.queue[message.channel.id] = [];
|
self.queue[message.channel.id] = [];
|
||||||
}
|
}
|
||||||
@@ -404,18 +404,18 @@ class Client {
|
|||||||
});
|
});
|
||||||
|
|
||||||
self.checkQueue(message.channel.id);
|
self.checkQueue(message.channel.id);
|
||||||
}else{
|
} else {
|
||||||
self._deleteMessage(message).then(good).catch(bad);
|
self._deleteMessage(message).then(good).catch(bad);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function good(){
|
function good() {
|
||||||
prom.success = true;
|
prom.success = true;
|
||||||
callback(null);
|
callback(null);
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
function bad(err){
|
function bad(err) {
|
||||||
prom.error = err;
|
prom.error = err;
|
||||||
callback(err);
|
callback(err);
|
||||||
reject(err);
|
reject(err);
|
||||||
@@ -433,7 +433,7 @@ class Client {
|
|||||||
|
|
||||||
content = (content instanceof Array ? content.join("\n") : content);
|
content = (content instanceof Array ? content.join("\n") : content);
|
||||||
|
|
||||||
if(self.options.queue){
|
if (self.options.queue) {
|
||||||
if (!self.queue[message.channel.id]) {
|
if (!self.queue[message.channel.id]) {
|
||||||
self.queue[message.channel.id] = [];
|
self.queue[message.channel.id] = [];
|
||||||
}
|
}
|
||||||
@@ -446,21 +446,21 @@ class Client {
|
|||||||
});
|
});
|
||||||
|
|
||||||
self.checkQueue(message.channel.id);
|
self.checkQueue(message.channel.id);
|
||||||
}else{
|
} else {
|
||||||
self._updateMessage(message, content).then(good).catch(bad);
|
self._updateMessage(message, content).then(good).catch(bad);
|
||||||
}
|
}
|
||||||
|
|
||||||
function good(msg){
|
function good(msg) {
|
||||||
prom.message = msg;
|
prom.message = msg;
|
||||||
callback(null, msg);
|
callback(null, msg);
|
||||||
resolve(msg);
|
resolve(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function bad(error){
|
function bad(error) {
|
||||||
prom.error = error;
|
prom.error = error;
|
||||||
callback(error);
|
callback(error);
|
||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -611,7 +611,7 @@ class Client {
|
|||||||
self.resolveDestination(destination).then(send).catch(bad);
|
self.resolveDestination(destination).then(send).catch(bad);
|
||||||
|
|
||||||
function send(destination) {
|
function send(destination) {
|
||||||
if(self.options.queue){
|
if (self.options.queue) {
|
||||||
//queue send file too
|
//queue send file too
|
||||||
if (!self.queue[destination]) {
|
if (!self.queue[destination]) {
|
||||||
self.queue[destination] = [];
|
self.queue[destination] = [];
|
||||||
@@ -619,14 +619,14 @@ class Client {
|
|||||||
|
|
||||||
self.queue[destination].push({
|
self.queue[destination].push({
|
||||||
action: "sendFile",
|
action: "sendFile",
|
||||||
attachment : fstream,
|
attachment: fstream,
|
||||||
attachmentName : fileName,
|
attachmentName: fileName,
|
||||||
then: good,
|
then: good,
|
||||||
error: bad
|
error: bad
|
||||||
});
|
});
|
||||||
|
|
||||||
self.checkQueue(destination);
|
self.checkQueue(destination);
|
||||||
}else{
|
} else {
|
||||||
//not queue
|
//not queue
|
||||||
self._sendFile(destination, fstream, fileName).then(good).catch(bad);
|
self._sendFile(destination, fstream, fileName).then(good).catch(bad);
|
||||||
}
|
}
|
||||||
@@ -656,7 +656,7 @@ class Client {
|
|||||||
|
|
||||||
var prom = new Promise(function (resolve, reject) {
|
var prom = new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
if(typeof tts === "function"){
|
if (typeof tts === "function") {
|
||||||
// tts is a function, which means the developer wants this to be the callback
|
// tts is a function, which means the developer wants this to be the callback
|
||||||
callback = tts;
|
callback = tts;
|
||||||
tts = false;
|
tts = false;
|
||||||
@@ -682,7 +682,7 @@ class Client {
|
|||||||
action: "sendMessage",
|
action: "sendMessage",
|
||||||
content: message,
|
content: message,
|
||||||
mentions: mentions,
|
mentions: mentions,
|
||||||
tts : !!tts, //incase it's not a boolean
|
tts: !!tts, //incase it's not a boolean
|
||||||
then: mgood,
|
then: mgood,
|
||||||
error: mbad
|
error: mbad
|
||||||
});
|
});
|
||||||
@@ -1179,7 +1179,7 @@ class Client {
|
|||||||
.send({
|
.send({
|
||||||
content: content,
|
content: content,
|
||||||
mentions: mentions,
|
mentions: mentions,
|
||||||
tts : tts
|
tts: tts
|
||||||
})
|
})
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
|
|
||||||
@@ -1208,38 +1208,38 @@ class Client {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendFile(destination, attachment, attachmentName = "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png"){
|
_sendFile(destination, attachment, attachmentName = "DEFAULT BECAUSE YOU DIDN'T SPECIFY WHY.png") {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function (resolve, reject) {
|
||||||
request
|
request
|
||||||
.post(`${Endpoints.CHANNELS}/${destination}/messages`)
|
.post(`${Endpoints.CHANNELS}/${destination}/messages`)
|
||||||
.set("authorization", self.token)
|
.set("authorization", self.token)
|
||||||
.attach("file", attachment, attachmentName)
|
.attach("file", attachment, attachmentName)
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
var chann = self.getChannel("id", destination);
|
|
||||||
if (chann) {
|
|
||||||
var msg = chann.addMessage(new Message(res.body, chann, [], self.user));
|
|
||||||
resolve(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
var chann = self.getChannel("id", destination);
|
||||||
|
if (chann) {
|
||||||
|
var msg = chann.addMessage(new Message(res.body, chann, [], self.user));
|
||||||
|
resolve(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateMessage(message, content){
|
_updateMessage(message, content) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function (resolve, reject) {
|
||||||
request
|
request
|
||||||
.patch(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`)
|
.patch(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`)
|
||||||
.set("authorization", self.token)
|
.set("authorization", self.token)
|
||||||
@@ -1259,20 +1259,20 @@ class Client {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_deleteMessage(message){
|
_deleteMessage(message) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
request
|
request
|
||||||
.del(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`)
|
.del(`${Endpoints.CHANNELS}/${message.channel.id}/messages/${message.id}`)
|
||||||
.set("authorization", self.token)
|
.set("authorization", self.token)
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1309,12 +1309,12 @@ class Client {
|
|||||||
case "sendFile":
|
case "sendFile":
|
||||||
var fileToSend = queuedEvent;
|
var fileToSend = queuedEvent;
|
||||||
self._sendFile(channelID, fileToSend.attachment, fileToSend.attachmentName)
|
self._sendFile(channelID, fileToSend.attachment, fileToSend.attachmentName)
|
||||||
.then(function (msg){
|
.then(function (msg) {
|
||||||
fileToSend.then(msg);
|
fileToSend.then(msg);
|
||||||
self.queue[channelID].shift();
|
self.queue[channelID].shift();
|
||||||
doNext();
|
doNext();
|
||||||
})
|
})
|
||||||
.catch(function(err){
|
.catch(function (err) {
|
||||||
fileToSend.error(err);
|
fileToSend.error(err);
|
||||||
self.queue[channelID].shift();
|
self.queue[channelID].shift();
|
||||||
doNext();
|
doNext();
|
||||||
@@ -1323,30 +1323,30 @@ class Client {
|
|||||||
case "updateMessage":
|
case "updateMessage":
|
||||||
var msgToUpd = queuedEvent;
|
var msgToUpd = queuedEvent;
|
||||||
self._updateMessage(msgToUpd.message, msgToUpd.content)
|
self._updateMessage(msgToUpd.message, msgToUpd.content)
|
||||||
.then(function(msg){
|
.then(function (msg) {
|
||||||
msgToUpd.then(msg);
|
msgToUpd.then(msg);
|
||||||
self.queue[channelID].shift();
|
self.queue[channelID].shift();
|
||||||
doNext();
|
doNext();
|
||||||
})
|
})
|
||||||
.catch(function(err){
|
.catch(function (err) {
|
||||||
msgToUpd.error(err);
|
msgToUpd.error(err);
|
||||||
self.queue[channelID].shift();
|
self.queue[channelID].shift();
|
||||||
doNext();
|
doNext();
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "deleteMessage":
|
case "deleteMessage":
|
||||||
var msgToDel = queuedEvent;
|
var msgToDel = queuedEvent;
|
||||||
self._deleteMessage(msgToDel.message)
|
self._deleteMessage(msgToDel.message)
|
||||||
.then(function(msg){
|
.then(function (msg) {
|
||||||
msgToDel.then(msg);
|
msgToDel.then(msg);
|
||||||
self.queue[channelID].shift();
|
self.queue[channelID].shift();
|
||||||
doNext();
|
doNext();
|
||||||
})
|
})
|
||||||
.catch(function(err){
|
.catch(function (err) {
|
||||||
msgToDel.error(err);
|
msgToDel.error(err);
|
||||||
self.queue[channelID].shift();
|
self.queue[channelID].shift();
|
||||||
doNext();
|
doNext();
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
done();
|
done();
|
||||||
@@ -1360,24 +1360,22 @@ class Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function getGateway() {
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
|
||||||
request
|
|
||||||
.get(`${Endpoints.API}/gateway`)
|
|
||||||
.end(function (err, res) {
|
|
||||||
if (err) {
|
|
||||||
reject(err);
|
|
||||||
} else {
|
|
||||||
resolve(res.body.url);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
getGateway() {
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
request
|
||||||
|
.get(`${Endpoints.API}/gateway`)
|
||||||
|
.set("authorization", self.token)
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve(res.body.url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Client;
|
module.exports = Client;
|
||||||
@@ -34,7 +34,7 @@ class Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toString(){
|
toString(){
|
||||||
return "#" + this.name;
|
return "<#" + this.id + ">";
|
||||||
}
|
}
|
||||||
|
|
||||||
get isPrivate(){
|
get isPrivate(){
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ class Server {
|
|||||||
return this.client.getUser("id", this.ownerID);
|
return this.client.getUser("id", this.ownerID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get users() {
|
||||||
|
return this.members;
|
||||||
|
}
|
||||||
|
|
||||||
// get/set
|
// get/set
|
||||||
getChannel(key, value) {
|
getChannel(key, value) {
|
||||||
for (var channel of this.channels) {
|
for (var channel of this.channels) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ mybot.on("message", function (message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// we can go ahead :)
|
// we can go ahead :)
|
||||||
mybot.sendMessage(message.author, message.sender.username);
|
mybot.reply(message, message.channel);
|
||||||
});
|
});
|
||||||
|
|
||||||
mybot.on("ready", function () {
|
mybot.on("ready", function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user