feat: replace disableEveryone with disableMentions (#3830)

* add ClientOptions#disableMentions and MessageOptions#disableMentions

* provide tests

* don't sanitize controlled mentions

* add @here mentions to tests

* fix indents (6 spaces instead of 8)

* add Util#cleanContent tests

* add typings for removeMentions

* replace @ with @\u200b AFTER cleaning content as suggested instead of using removeMentions

* better explanation of this option

* no newline in Util.removeMentions

* fix long line

* remove double space

* remove comments (change has been reverted)

* Use Util.removeMentions to remove mentions

* use Util.removeMentions in Util.cleanContent
This commit is contained in:
Timo
2020-02-26 12:13:23 +01:00
committed by GitHub
parent c4bda746c8
commit 9cb306c823
8 changed files with 77 additions and 21 deletions

47
test/disableMentions.js Normal file
View File

@@ -0,0 +1,47 @@
const Discord = require('../src');
const { Util } = Discord;
const { token, prefix } = require('./auth');
const client = new Discord.Client({
// To see a difference, comment out disableMentions and run the same tests using disableEveryone
// You will notice that all messages will mention @everyone
//disableEveryone: true
disableMentions: true
});
const tests = [
// Test 1
// See https://github.com/discordapp/discord-api-docs/issues/1189
'@\u202eeveryone @\u202ehere',
// Test 2
// See https://github.com/discordapp/discord-api-docs/issues/1241
// TL;DR: Characters like \u0300 will only be stripped if more than 299 are present
'\u0300@'.repeat(150) + '@\u0300everyone @\u0300here',
// Test 3
// Normal @everyone/@here mention
'@everyone @here',
];
client.on('ready', () => console.log('Ready!'));
client.on('message', message => {
// Check if message starts with prefix
if (!message.content.startsWith(prefix)) return;
const [command, ...args] = message.content.substr(prefix.length).split(' ');
// Clean content and log each character
console.log(Util.cleanContent(args.join(' '), message).split(''));
if (command === 'test1')
message.reply(tests[0]);
else if (command === 'test2')
message.reply(tests[1]);
else if (command === 'test3')
message.reply(tests[2]);
});
client.login(token).catch(console.error);