Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable non-mentionable role mentions #3882

Closed
Markus-Rost opened this issue Mar 2, 2020 · 8 comments · Fixed by #3893
Closed

disable non-mentionable role mentions #3882

Markus-Rost opened this issue Mar 2, 2020 · 8 comments · Fixed by #3893

Comments

@Markus-Rost
Copy link
Contributor

Is your feature request related to a problem? Please describe.
The disableMentions function is missing a feature for me. Using all breaks all mentions, but using everyone does still mention roles that can only be mentioned with the MENTION_EVERYONE permission.

Describe the ideal solution
Ideally using disableMentions:'everyone' would also escape mentions of non-mentionable roles.

Describe alternatives you've considered
Adding a fourth option for disableMentions would of course work as well but probably requires more coding.

Additional context
I wrote myself I small function to escape the mentions, maybe that could be used in some way.

function cleanRestrictedMentions(text, message) {
  return text.replace( /@(here|everyone)/g, '@\u200b$1' ).replace( /<@&(\d+)>/g, (mention, id) => {
    if (message.channel.type === 'dm') return mention;
    var role = message.guild.roles.cache.get(id);
    return ( role && !role.mentionable ? `@${role.name}` : mention );
  } );
}
@NotSugden
Copy link
Contributor

Role.mentionable is based on the toggle for the role, not if the bot has mention everyone permissions, so that would yield the same result, and the first regex was removed in the first place as it was unreliable, see #3830

@monbrey
Copy link
Member

monbrey commented Mar 2, 2020

Role.mentionable is based on the toggle for the role, not if the bot has mention everyone permissions

That's exactly the point though. If the role isn't mentionable, you probably want a way to prevent the bot from accidentally mentioning it because it has MENTION_EVERYONE.

@tipakA
Copy link
Contributor

tipakA commented Mar 2, 2020

But in the case of example code provided in opening post, Role.mentionable on itself does not accurately reflect if the bot will actually mention the role, since it is ignored if bot has mention everyone permission.
Eventual check would probably look like if (bot has mention everyone && role is not mentionable), and if that's true escape the role mention.

@Markus-Rost
Copy link
Contributor Author

The current disableMentions:everyone doesn't check if the bot has mention everyone permission either, so I didn't add one. I also don't think a permissions check would really be necessary as users can easily add one themselves when adding the disableMentions option or just always stay on the save side.

@tipakA
Copy link
Contributor

tipakA commented Mar 2, 2020

users can easily add one themselves when adding the disableMentions option

But that defeats the purpose of having disableMentions, if you have to remember to "tighten up" the message content checks by yourself

@Markus-Rost
Copy link
Contributor Author

True, but then a permissions check would need to be added to the current disableMentions:'everyone' as well. And the disableMentions option would return an inconsistent result with sometimes escaping mentions and sometimes not depending on the permission. I think having the same option always return the same text independent from the permission would be better.

Example:
Using message.channel.send(`${role}`,{disableMentions:'everyone'}) on two different channels of the same guild. Channel A has a channel overwrite allowing the bot to mention everyone, channel B does not. Channel B has the role mention highlighted while channel A does not. That would be inconsistent and confusing to debug as the permission check is not obvious.

@SpaceEEC
Copy link
Member

SpaceEEC commented Mar 2, 2020

[...] but using everyone does still mention roles that can only be mentioned with the MENTION_EVERYONE permission.

Bots currently do not have "access" to this new feature where users with the MENTION_EVERYONE permission can actually mention roles that are not marked as "mentionable".
See this Reddit post for more info.

So this is, at least currently, not an issue.

On another note, Discord is "working on exposing a new set of fields you can provide when you create a message or post a webhook that will specify what kinds of mentions will be allowed to be processed in a message. " (from discord/discord-api-docs#1286 (comment))

Making this feature, hopefully soon, obsolete.

@SpaceEEC
Copy link
Member

SpaceEEC commented Mar 8, 2020

The above mentioned feature is live and I linked the relevant PR ^.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants