sendFile and fix deleteMessage

This commit is contained in:
hydrabolt
2015-11-01 00:16:58 +00:00
parent 53ef5df10d
commit b8aaa590b4
8 changed files with 123 additions and 36 deletions

View File

@@ -251,6 +251,33 @@ var InternalClient = (function () {
});
};
InternalClient.prototype.sendFile = function sendFile(where, _file) {
var name = arguments.length <= 2 || arguments[2] === undefined ? "image.png" : arguments[2];
var self = this;
return new Promise(function (resolve, reject) {
self.resolver.resolveChannel(where).then(next)["catch"](function (e) {
return reject(new Error("couldn't resolve to channel - " + e));
});
function next(channel) {
var file = self.resolver.resolveFile(_file);
request.post(Endpoints.CHANNEL_MESSAGES(channel.id)).set("authorization", self.token).attach("file", file, name).end(function (err, res) {
if (err) {
reject(new Error(err.response.text));
} else {
resolve(channel.messages.add(new Message(res.body, channel, self.client)));
}
});
}
});
};
// def getChannelLogs
InternalClient.prototype.getChannelLogs = function getChannelLogs(_channel) {
var limit = arguments.length <= 1 || arguments[1] === undefined ? 500 : arguments[1];
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];