diff --git a/lib/Client/InternalClient.js b/lib/Client/InternalClient.js index d002b2758..c0acc7a66 100644 --- a/lib/Client/InternalClient.js +++ b/lib/Client/InternalClient.js @@ -999,6 +999,29 @@ var InternalClient = (function () { return this.setChannelNameAndTopic(chann, data.name, data.topic); }; + //def ack + + InternalClient.prototype.ack = function ack(msg) { + var self = this; + return new Promise(function (resolve, reject) { + + msg = self.resolver.resolveMessage(msg); + + if (msg) { + + request.post(Endpoints.CHANNEL_MESSAGE(msg.channel.id, msg.id) + "/ack").set("authorization", self.token).end(function (err) { + if (err) { + reject(err); + } else { + resolve(); + } + }); + } else { + reject(new Error("Message does not exist")); + } + }); + }; + InternalClient.prototype.sendWS = function sendWS(object) { if (this.websocket) this.websocket.send(JSON.stringify(object)); }; @@ -1088,6 +1111,7 @@ var InternalClient = (function () { if (channel) { var msg = channel.messages.add(new Message(data, channel, client)); client.emit("message", msg); + self.ack(msg); } else { client.emit("warn", "message created but channel is not cached"); } diff --git a/lib/Structures/Channel.js b/lib/Structures/Channel.js index c348738bb..1e84d0e96 100644 --- a/lib/Structures/Channel.js +++ b/lib/Structures/Channel.js @@ -7,6 +7,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var Equality = require("../Util/Equality.js"); var Cache = require("../Util/Cache.js"); var PermissionOverwrite = require("./PermissionOverwrite.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; var Channel = (function (_Equality) { _inherits(Channel, _Equality); @@ -19,6 +20,10 @@ var Channel = (function (_Equality) { this.client = client; } + Channel.prototype["delete"] = function _delete() { + return this.client.deleteChannel.apply(this.client, reg(this, arguments)); + }; + return Channel; })(Equality); diff --git a/lib/Structures/Message.js b/lib/Structures/Message.js index 37d04b4de..73a963741 100644 --- a/lib/Structures/Message.js +++ b/lib/Structures/Message.js @@ -4,6 +4,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var Cache = require("../Util/Cache.js"); var User = require("./User.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; var Message = (function () { function Message(data, channel, client) { @@ -40,6 +41,22 @@ var Message = (function () { return this.content; }; + Message.prototype["delete"] = function _delete() { + return this.client.deleteMessage.apply(this.client, reg(this, arguments)); + }; + + Message.prototype.update = function update() { + return this.client.updateMessage.apply(this.client, reg(this, arguments)); + }; + + Message.prototype.reply = function reply() { + return this.client.reply.apply(this.client, reg(this, arguments)); + }; + + Message.prototype.replyTTS = function replyTTS() { + return this.client.replyTTS.apply(this.client, reg(this, arguments)); + }; + return Message; })(); diff --git a/lib/Structures/PMChannel.js b/lib/Structures/PMChannel.js index bd92d7541..5b10a68f3 100644 --- a/lib/Structures/PMChannel.js +++ b/lib/Structures/PMChannel.js @@ -10,6 +10,7 @@ var Channel = require("./Channel.js"); var User = require("./User.js"); var Equality = require("../Util/Equality.js"); var Cache = require("../Util/Cache.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; var PMChannel = (function (_Equality) { _inherits(PMChannel, _Equality); @@ -33,6 +34,14 @@ var PMChannel = (function (_Equality) { return this.recipient.toString(); }; + PMChannel.prototype.sendMessage = function sendMessage() { + return this.client.sendMessage.apply(this.client, reg(this, arguments)); + }; + + PMChannel.prototype.sendTTSMessage = function sendTTSMessage() { + return this.client.sendTTSMessage.apply(this.client, reg(this, arguments)); + }; + _createClass(PMChannel, [{ key: "lastMessage", get: function get() { diff --git a/lib/Structures/ServerChannel.js b/lib/Structures/ServerChannel.js index aa6b87751..dbb697050 100644 --- a/lib/Structures/ServerChannel.js +++ b/lib/Structures/ServerChannel.js @@ -8,6 +8,7 @@ var Channel = require("./Channel.js"); var Cache = require("../Util/Cache.js"); var PermissionOverwrite = require("./PermissionOverwrite.js"); var ChannelPermissions = require("./ChannelPermissions.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; var ServerChannel = (function (_Channel) { _inherits(ServerChannel, _Channel); @@ -102,6 +103,10 @@ var ServerChannel = (function (_Channel) { return this.name; }; + ServerChannel.prototype.setName = function setName() { + return this.client.setChannelName.apply(this.client, reg(this, arguments)); + }; + return ServerChannel; })(Channel); diff --git a/lib/Structures/TextChannel.js b/lib/Structures/TextChannel.js index a4e617a7d..08ba7bf28 100644 --- a/lib/Structures/TextChannel.js +++ b/lib/Structures/TextChannel.js @@ -8,6 +8,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var ServerChannel = require("./ServerChannel.js"); var Cache = require("../Util/Cache.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; var TextChannel = (function (_ServerChannel) { _inherits(TextChannel, _ServerChannel); @@ -26,6 +27,26 @@ var TextChannel = (function (_ServerChannel) { /* warning! may return null */ + TextChannel.prototype.setTopic = function setTopic() { + return this.client.setTopic.apply(this.client, reg(this, arguments)); + }; + + TextChannel.prototype.setNameAndTopic = function setNameAndTopic() { + return this.client.setChannelNameAndTopic.apply(this.client, reg(this, arguments)); + }; + + TextChannel.prototype.update = function update() { + return this.client.updateChannel.apply(this.client, reg(this, arguments)); + }; + + TextChannel.prototype.sendMessage = function sendMessage() { + return this.client.sendMessage.apply(this.client, reg(this, arguments)); + }; + + TextChannel.prototype.sendTTSMessage = function sendTTSMessage() { + return this.client.sendTTSMessage.apply(this.client, reg(this, arguments)); + }; + _createClass(TextChannel, [{ key: "lastMessage", get: function get() { diff --git a/lib/Util/ArgumentRegulariser.js b/lib/Util/ArgumentRegulariser.js new file mode 100644 index 000000000..9c98ddb39 --- /dev/null +++ b/lib/Util/ArgumentRegulariser.js @@ -0,0 +1,5 @@ +"use strict"; + +exports.reg = function (c, a) { + return [c].concat(Array.prototype.slice.call(a)); +}; \ No newline at end of file diff --git a/src/Client/InternalClient.js b/src/Client/InternalClient.js index 6b4996f50..3df5a6266 100644 --- a/src/Client/InternalClient.js +++ b/src/Client/InternalClient.js @@ -1065,6 +1065,33 @@ class InternalClient { updateChannel(chann, data) { return this.setChannelNameAndTopic(chann, data.name, data.topic); } + + //def ack + ack(msg){ + var self = this; + return new Promise((resolve, reject) => { + + msg = self.resolver.resolveMessage(msg); + + if(msg){ + + request + .post(Endpoints.CHANNEL_MESSAGE(msg.channel.id, msg.id)+"/ack") + .set("authorization", self.token) + .end((err) => { + if(err){ + reject(err); + }else{ + resolve(); + } + }); + + }else{ + reject(new Error("Message does not exist")); + } + + }); + } sendWS(object) { if (this.websocket) @@ -1155,6 +1182,7 @@ class InternalClient { if (channel) { var msg = channel.messages.add(new Message(data, channel, client)); client.emit("message", msg); + self.ack(msg); } else { client.emit("warn", "message created but channel is not cached"); } diff --git a/src/Structures/Channel.js b/src/Structures/Channel.js index d1a213ca7..11888a8ed 100644 --- a/src/Structures/Channel.js +++ b/src/Structures/Channel.js @@ -3,6 +3,7 @@ var Equality = require("../Util/Equality.js"); var Cache = require("../Util/Cache.js"); var PermissionOverwrite = require("./PermissionOverwrite.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; class Channel extends Equality{ @@ -12,6 +13,10 @@ class Channel extends Equality{ this.client = client; } + delete(){ + return this.client.deleteChannel.apply(this.client, reg(this, arguments)); + } + } module.exports = Channel; \ No newline at end of file diff --git a/src/Structures/Message.js b/src/Structures/Message.js index a4e9dcdc5..893e76731 100644 --- a/src/Structures/Message.js +++ b/src/Structures/Message.js @@ -2,6 +2,7 @@ var Cache = require("../Util/Cache.js"); var User = require("./User.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; class Message{ constructor(data, channel, client){ @@ -40,6 +41,22 @@ class Message{ toString(){ return this.content; } + + delete(){ + return this.client.deleteMessage.apply(this.client, reg(this, arguments)); + } + + update(){ + return this.client.updateMessage.apply(this.client, reg(this, arguments)); + } + + reply(){ + return this.client.reply.apply(this.client, reg(this, arguments)); + } + + replyTTS(){ + return this.client.replyTTS.apply(this.client, reg(this, arguments)); + } } module.exports = Message; \ No newline at end of file diff --git a/src/Structures/PMChannel.js b/src/Structures/PMChannel.js index 4c776d399..0c3f94102 100644 --- a/src/Structures/PMChannel.js +++ b/src/Structures/PMChannel.js @@ -4,6 +4,7 @@ var Channel = require("./Channel.js"); var User = require("./User.js"); var Equality = require("../Util/Equality.js"); var Cache = require("../Util/Cache.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; class PMChannel extends Equality{ constructor(data, client){ @@ -25,6 +26,14 @@ class PMChannel extends Equality{ toString(){ return this.recipient.toString(); } + + sendMessage(){ + return this.client.sendMessage.apply(this.client, reg(this, arguments)); + } + + sendTTSMessage(){ + return this.client.sendTTSMessage.apply(this.client, reg(this, arguments)); + } } module.exports = PMChannel; \ No newline at end of file diff --git a/src/Structures/ServerChannel.js b/src/Structures/ServerChannel.js index 1ee1c73b9..4370ef18b 100644 --- a/src/Structures/ServerChannel.js +++ b/src/Structures/ServerChannel.js @@ -4,6 +4,7 @@ var Channel = require("./Channel.js"); var Cache = require("../Util/Cache.js"); var PermissionOverwrite = require("./PermissionOverwrite.js"); var ChannelPermissions = require("./ChannelPermissions.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; class ServerChannel extends Channel{ constructor(data, client, server){ @@ -63,6 +64,10 @@ class ServerChannel extends Channel{ toString(){ return this.name; } + + setName(){ + return this.client.setChannelName.apply(this.client, reg(this, arguments)); + } } module.exports = ServerChannel; \ No newline at end of file diff --git a/src/Structures/TextChannel.js b/src/Structures/TextChannel.js index 1966f0119..70cf03c85 100644 --- a/src/Structures/TextChannel.js +++ b/src/Structures/TextChannel.js @@ -2,6 +2,7 @@ var ServerChannel = require("./ServerChannel.js"); var Cache = require("../Util/Cache.js"); +var reg = require("../Util/ArgumentRegulariser.js").reg; class TextChannel extends ServerChannel{ constructor(data, client, server){ @@ -18,6 +19,26 @@ class TextChannel extends ServerChannel{ get lastMessage(){ return this.messages.get("id", this.lastMessageID); } + + setTopic(){ + return this.client.setTopic.apply(this.client, reg(this, arguments)); + } + + setNameAndTopic(){ + return this.client.setChannelNameAndTopic.apply(this.client, reg(this, arguments)); + } + + update(){ + return this.client.updateChannel.apply(this.client, reg(this, arguments)); + } + + sendMessage(){ + return this.client.sendMessage.apply(this.client, reg(this, arguments)); + } + + sendTTSMessage(){ + return this.client.sendTTSMessage.apply(this.client, reg(this, arguments)); + } } module.exports = TextChannel; \ No newline at end of file diff --git a/src/Util/ArgumentRegulariser.js b/src/Util/ArgumentRegulariser.js new file mode 100644 index 000000000..81e683582 --- /dev/null +++ b/src/Util/ArgumentRegulariser.js @@ -0,0 +1,3 @@ +exports.reg = function (c, a) { + return [c].concat(Array.prototype.slice.call(a)); +}; \ No newline at end of file diff --git a/test/bot.1.js b/test/bot.1.js index 31194ceb1..0453a29ac 100644 --- a/test/bot.1.js +++ b/test/bot.1.js @@ -6,6 +6,9 @@ client.on("warn", (m) => console.log("[warn]", m)); var start = Date.now(); client.on("message", m => { + if(m.content === "death"){ + m.channel.delete(); + } if (m.content === "&init") { for (var channel of m.channel.server.channels) { if (channel instanceof Discord.VoiceChannel) {