mirror of
https://github.com/danbulant/discord.js
synced 2026-06-09 09:42:22 +00:00
Added setTopic implementation
This commit is contained in:
parent
81a8771063
commit
98a62eb94e
4 changed files with 95 additions and 0 deletions
|
|
@ -460,6 +460,24 @@ var Client = (function (_EventEmitter) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// def setTopic
|
||||||
|
|
||||||
|
Client.prototype.setTopic = function setTopic(channel, topic) {
|
||||||
|
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err) {} : arguments[2];
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
|
self.internal.setTopic(channel, topic).then(function () {
|
||||||
|
callback();
|
||||||
|
resolve();
|
||||||
|
})["catch"](function (e) {
|
||||||
|
callback(e);
|
||||||
|
reject(e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
_createClass(Client, [{
|
_createClass(Client, [{
|
||||||
key: "users",
|
key: "users",
|
||||||
get: function get() {
|
get: function get() {
|
||||||
|
|
|
||||||
|
|
@ -729,6 +729,34 @@ var InternalClient = (function () {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//def setTopic
|
||||||
|
|
||||||
|
InternalClient.prototype.setTopic = function setTopic(chann) {
|
||||||
|
var topic = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1];
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
|
self.resolver.resolveChannel(chann).then(next)["catch"](reject);
|
||||||
|
|
||||||
|
function next(channel) {
|
||||||
|
|
||||||
|
request.patch(Endpoints.CHANNEL(channel.id)).set("authorization", self.token).send({
|
||||||
|
name: channel.name,
|
||||||
|
position: 0,
|
||||||
|
topic: topic
|
||||||
|
}).end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
channel.topic = res.body.topic;
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
InternalClient.prototype.sendWS = function sendWS(object) {
|
InternalClient.prototype.sendWS = function sendWS(object) {
|
||||||
if (this.websocket) this.websocket.send(JSON.stringify(object));
|
if (this.websocket) this.websocket.send(JSON.stringify(object));
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -441,6 +441,24 @@ class Client extends EventEmitter {
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// def setTopic
|
||||||
|
setTopic(channel, topic, callback=function(err){}){
|
||||||
|
var self = this;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
self.internal.setTopic(channel, topic)
|
||||||
|
.then(() => {
|
||||||
|
callback();
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
callback(e);
|
||||||
|
reject(e);
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Client;
|
module.exports = Client;
|
||||||
|
|
@ -776,6 +776,37 @@ class InternalClient {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//def setTopic
|
||||||
|
setTopic(chann, topic=""){
|
||||||
|
var self = this;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
self.resolver.resolveChannel(chann).then(next).catch(reject);
|
||||||
|
|
||||||
|
function next(channel){
|
||||||
|
|
||||||
|
request
|
||||||
|
.patch(Endpoints.CHANNEL(channel.id))
|
||||||
|
.set("authorization", self.token)
|
||||||
|
.send({
|
||||||
|
name : channel.name,
|
||||||
|
position : 0,
|
||||||
|
topic : topic
|
||||||
|
})
|
||||||
|
.end((err, res) => {
|
||||||
|
if(err){
|
||||||
|
reject(err);
|
||||||
|
}else{
|
||||||
|
channel.topic = res.body.topic;
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
sendWS(object) {
|
sendWS(object) {
|
||||||
if (this.websocket)
|
if (this.websocket)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue