Updated deleted and update message listeners

This commit is contained in:
hydrabolt
2015-10-31 23:31:18 +00:00
parent 4b4b7d6a47
commit 6d6dcf533a
4 changed files with 50 additions and 2 deletions

View File

@@ -336,6 +336,39 @@ var InternalClient = (function () {
client.emit("warn", "message created but channel is not cached");
}
break;
case PacketType.MESSAGE_DELETE:
// format https://discordapi.readthedocs.org/en/latest/reference/channels/messages.html#message-delete
var channel = self.channels.get("id", data.channel_id);
if (channel) {
// potentially blank
var msg = channel.messages.get("id", data.id);
client.emit("messageDeleted", msg);
if(msg){
channel.messages.remove(msg);
}
} else {
client.emit("warn", "message was deleted but channel is not cached");
}
break;
case PacketType.MESSAGE_UPDATE:
// format https://discordapi.readthedocs.org/en/latest/reference/channels/messages.html#message-format
var channel = self.channels.get("id", data.channel_id);
if (channel) {
// potentially blank
var msg = channel.messages.get("id", data.id);
if(msg){
// old message exists
var nmsg = channel.messages.update(msg, new Message(data, channel, client));
client.emit("messageUpdated", nmsg, msg);
}else{
var nmsg = channel.messages.add(new Message(data, channel, client));
client.emit("messageUpdated", nmsg);
}
} else {
client.emit("warn", "message was updated but channel is not cached");
}
break;
}
};

View File

@@ -100,7 +100,9 @@ var Permissions = {
var PacketType = {
READY: "READY",
MESSAGE_CREATE: "MESSAGE_CREATE"
MESSAGE_CREATE: "MESSAGE_CREATE",
MESSAGE_UPDATE: "MESSAGE_UPDATE",
MESSAGE_DELETE: "MESSAGE_DELETE"
};
exports.API_ENDPOINT = API;

View File

@@ -17,6 +17,17 @@ a.on("message", function (m) {
});
});
a.on("messageUpdated", function(newm, oldm){
if(oldm){
a.sendMessage(oldm, `woah! ${newm.author} changed their message! how rude`)
}
})
a.on("messageDeleted", function(oldm){
if(oldm){
a.sendMessage(oldm, `woah! ${oldm.author} deleted their message! how rude`)
}
})
a.login(process.env["discordEmail"], process.env["discordPass"])["catch"](function (e) {
return console.log(e);
});

View File

@@ -62,7 +62,9 @@ var Permissions = {
var PacketType = {
READY : "READY",
MESSAGE_CREATE : "MESSAGE_CREATE"
MESSAGE_CREATE : "MESSAGE_CREATE",
MESSAGE_UPDATE : "MESSAGE_UPDATE",
MESSAGE_DELETE : "MESSAGE_DELETE",
}
exports.API_ENDPOINT = API;