fix(messagementions): fix has method (#7292)

Co-authored-by: Almeida <almeidx@pm.me>
This commit is contained in:
Synbulat Biishev
2022-01-28 23:13:59 +05:00
committed by GitHub
parent 00ce1c56ac
commit 3a5ab2c4e5
2 changed files with 21 additions and 13 deletions

View File

@@ -170,28 +170,35 @@ class MessageMentions {
* @typedef {Object} MessageMentionsHasOptions * @typedef {Object} MessageMentionsHasOptions
* @property {boolean} [ignoreDirect=false] Whether to ignore direct mentions to the item * @property {boolean} [ignoreDirect=false] Whether to ignore direct mentions to the item
* @property {boolean} [ignoreRoles=false] Whether to ignore role mentions to a guild member * @property {boolean} [ignoreRoles=false] Whether to ignore role mentions to a guild member
* @property {boolean} [ignoreEveryone=false] Whether to ignore everyone/here mentions * @property {boolean} [ignoreRepliedUser=false] Whether to ignore replied user mention to an user
* @property {boolean} [ignoreEveryone=false] Whether to ignore `@everyone`/`@here` mentions
*/ */
/** /**
* Checks if a user, guild member, role, or channel is mentioned. * Checks if a user, guild member, thread member, role, or channel is mentioned.
* Takes into account user mentions, role mentions, and `@everyone`/`@here` mentions. * Takes into account user mentions, role mentions, channel mentions,
* replied user mention, and `@everyone`/`@here` mentions.
* @param {UserResolvable|RoleResolvable|ChannelResolvable} data The User/Role/Channel to check for * @param {UserResolvable|RoleResolvable|ChannelResolvable} data The User/Role/Channel to check for
* @param {MessageMentionsHasOptions} [options] The options for the check * @param {MessageMentionsHasOptions} [options] The options for the check
* @returns {boolean} * @returns {boolean}
*/ */
has(data, { ignoreDirect = false, ignoreRoles = false, ignoreEveryone = false } = {}) { has(data, { ignoreDirect = false, ignoreRoles = false, ignoreRepliedUser = false, ignoreEveryone = false } = {}) {
if (!ignoreEveryone && this.everyone) return true; const user = this.client.users.resolve(data);
const { GuildMember } = require('./GuildMember'); const role = this.guild?.roles.resolve(data);
if (!ignoreRoles && data instanceof GuildMember) { const channel = this.client.channels.resolve(data);
for (const role of this.roles.values()) if (data.roles.cache.has(role.id)) return true;
}
if (!ignoreRepliedUser && this.users.has(this.repliedUser?.id) && this.repliedUser?.id === user?.id) return true;
if (!ignoreDirect) { if (!ignoreDirect) {
const id = if (this.users.has(user?.id)) return true;
this.guild?.roles.resolveId(data) ?? this.client.channels.resolveId(data) ?? this.client.users.resolveId(data); if (this.roles.has(role?.id)) return true;
if (this.channels.has(channel?.id)) return true;
return typeof id === 'string' && (this.users.has(id) || this.channels.has(id) || this.roles.has(id)); }
if (user && !ignoreEveryone && this.everyone) return true;
if (!ignoreRoles) {
const member = this.guild?.members.resolve(data);
if (member) {
for (const mentionedRole of this.roles.values()) if (member.roles.cache.has(mentionedRole.id)) return true;
}
} }
return false; return false;

View File

@@ -4623,6 +4623,7 @@ export interface MessageInteraction {
export interface MessageMentionsHasOptions { export interface MessageMentionsHasOptions {
ignoreDirect?: boolean; ignoreDirect?: boolean;
ignoreRoles?: boolean; ignoreRoles?: boolean;
ignoreRepliedUser?: boolean;
ignoreEveryone?: boolean; ignoreEveryone?: boolean;
} }