mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
Added message sending
This commit is contained in:
@@ -23,9 +23,7 @@ var Client = (function (_EventEmitter) {
|
||||
this.internal = new InternalClient(this);
|
||||
}
|
||||
|
||||
/*
|
||||
def login
|
||||
*/
|
||||
// def login
|
||||
|
||||
Client.prototype.login = function login(email, password) {
|
||||
var cb = arguments.length <= 2 || arguments[2] === undefined ? function (err, token) {} : arguments[2];
|
||||
@@ -43,9 +41,104 @@ var Client = (function (_EventEmitter) {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
def logout
|
||||
*/
|
||||
// def logout
|
||||
|
||||
Client.prototype.logout = function logout() {
|
||||
var cb = arguments.length <= 0 || arguments[0] === undefined ? function (err) {} : arguments[0];
|
||||
|
||||
var self = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
self.internal.logout().then(function () {
|
||||
cb();
|
||||
resolve();
|
||||
})["catch"](function (e) {
|
||||
cb(e);
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.sendMessage = function sendMessage(where, content) {
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
var callback = arguments.length <= 3 || arguments[3] === undefined ? function (e, m) {} : arguments[3];
|
||||
|
||||
var self = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
}
|
||||
|
||||
self.internal.sendMessage(where, content, options).then(function (m) {
|
||||
callback(null, m);
|
||||
resolve(m);
|
||||
})["catch"](function (e) {
|
||||
callback(e);
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.sendTTSMessage = function sendTTSMessage(where, content) {
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (e, m) {} : arguments[2];
|
||||
|
||||
var self = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
self.sendMessage(where, content, { tts: true }).then(function (m) {
|
||||
callback(null, m);
|
||||
resolve(m);
|
||||
})["catch"](function (e) {
|
||||
callback(e);
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.reply = function reply(where, content) {
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
var callback = arguments.length <= 3 || arguments[3] === undefined ? function (e, m) {} : arguments[3];
|
||||
|
||||
var self = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
}
|
||||
|
||||
var msg = self.internal.resolver.resolveMessage(where);
|
||||
if (msg) {
|
||||
content = msg.author + ", " + content;
|
||||
self.internal.sendMessage(msg, content, options).then(function (m) {
|
||||
callback(null, m);
|
||||
resolve(m);
|
||||
})["catch"](function (e) {
|
||||
callback(e);
|
||||
reject(e);
|
||||
});
|
||||
} else {
|
||||
var err = new Error("Destination not resolvable to a message!");
|
||||
callback(err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.replyTTS = function replyTTS(where, content) {
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function () {} : arguments[2];
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
self.reply(where, content, { tts: true }).then(function (m) {
|
||||
callback(null, m);
|
||||
resolve(m);
|
||||
})["catch"](function (e) {
|
||||
callback(e);
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return Client;
|
||||
})(EventEmitter);
|
||||
|
||||
Reference in New Issue
Block a user