add channel.sendMessage and channel.sendTTSMessage

This commit is contained in:
hydrabolt
2016-04-21 17:42:52 +01:00
parent b8283a8f29
commit f3e1760538
7 changed files with 61 additions and 11 deletions

View File

@@ -1,6 +1,9 @@
'use strict';
const Constants = require('../../util/Constants');
const Structure = name => require('../../structures/' + name);
const Message = Structure('Message');
class RESTMethods{
constructor(restManager) {
@@ -32,6 +35,21 @@ class RESTMethods{
.catch(reject);
});
}
SendMessage(channel, content, tts, nonce) {
return new Promise((resolve, reject) => {
this.rest.makeRequest('post', Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, {
content, tts, nonce,
})
.then(data => {
let message = new Message(channel, data, this.rest.client);
channel._cacheMessage(message);
resolve(message);
this.rest.client.emit(Constants.Events.MESSAGE_CREATE, message);
})
.catch(reject);
});
}
}
module.exports = RESTMethods;