Add more options to MessageMentions#has (#2131)

* Add more options to MessageMentions#has

* Rename ignoreSelf to ignoreDirect
This commit is contained in:
1Computer1
2017-11-26 04:58:17 -05:00
committed by Crawl
parent 950e65c7f1
commit 2f84d95077

View File

@@ -117,19 +117,27 @@ class MessageMentions {
}
/**
* Check if a user is mentioned.
* Checks if a user, guild member, role, or channel is mentioned.
* Takes into account user mentions, role mentions, and @everyone/@here mentions.
* @param {UserResolvable|GuildMember|Role|GuildChannel} data User/GuildMember/Role/Channel to check
* @param {boolean} [strict=true] If role mentions and everyone/here mentions should be included
* @param {Object} [options] Options
* @param {boolean} [options.ignoreDirect=false] - Whether to ignore direct mentions to the item
* @param {boolean} [options.ignoreRoles=false] - Whether to ignore role mentions to a guild member
* @param {boolean} [options.ignoreEveryone=false] - Whether to ignore everyone/here mentions
* @returns {boolean}
*/
has(data, strict = true) {
if (strict && this.everyone) return true;
if (strict && data instanceof GuildMember) {
has(data, { ignoreDirect = false, ignoreRoles = false, ignoreEveryone = false } = {}) {
if (!ignoreEveryone && this.everyone) return true;
if (!ignoreRoles && data instanceof GuildMember) {
for (const role of this.roles.values()) if (data.roles.has(role.id)) return true;
}
const id = data.id || data;
return this.users.has(id) || this.channels.has(id) || this.roles.has(id);
if (!ignoreDirect) {
const id = data.id || data;
return this.users.has(id) || this.channels.has(id) || this.roles.has(id);
}
return false;
}
}