Add Message.editable/deletable/pinnable

This commit is contained in:
Schuyler Cebulskie
2016-09-19 00:42:58 -04:00
parent 5f9204f57c
commit 8603759b5e
2 changed files with 29 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,7 @@
const Attachment = require('./MessageAttachment');
const Embed = require('./MessageEmbed');
const Collection = require('../util/Collection');
const Constants = require('../util/Constants');
/**
* Represents a Message on Discord
@@ -246,6 +247,33 @@ class Message {
return this._edits.slice().unshift(this);
}
/**
* Whether the message is editable by the client user.
* @type {boolean}
*/
get editable() {
return this.author.id === this.client.user.id;
}
/**
* Whether the message is deletable by the client user.
* @type {boolean}
*/
get deletable() {
return this.author.id === this.client.user.id || (this.guild &&
this.channel.permissionsFor(this.client.user).hasPermission(Constants.PermissionFlags.MANAGE_MESSAGES)
);
}
/**
* Whether the message is pinnable by the client user.
* @type {boolean}
*/
get pinnable() {
return !this.guild ||
this.channel.permissionsFor(this.client.user).hasPermission(Constants.PermissionFlags.MANAGE_MESSAGES);
}
/**
* Whether or not a user, channel or role is mentioned in this message.
* @param {GuildChannel|User|Role|string} data either a guild channel, user or a role object, or a string representing