mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
In-order + duplicate mentions, cleanContent in Messages
This commit is contained in:
@@ -98,10 +98,13 @@ export default class Resolver {
|
||||
// resource is a string
|
||||
var _mentions = [];
|
||||
var changed = resource;
|
||||
for (var mention of (resource.match(/<@[^>]*>/g) || [])) {
|
||||
let userID = mention.substring(2, mention.length - 1);
|
||||
_mentions.push(userID);
|
||||
changed = changed.replace(new RegExp(mention, "g"), `@${this.internal.client.users.get("id", userID).username}`);
|
||||
for (var mention of (resource.match(/<@[0-9]+>/g) || [])) {
|
||||
var userID = mention.substring(2, mention.length - 1);
|
||||
var user = this.internal.client.users.get("id", userID);
|
||||
if (user) {
|
||||
_mentions.push(user);
|
||||
changed = changed.replace(new RegExp(mention, "g"), `@${user.username}`);
|
||||
}
|
||||
}
|
||||
return [_mentions, changed];
|
||||
}
|
||||
|
||||
@@ -27,9 +27,12 @@ export default class Message extends Equality{
|
||||
this.author = client.internal.users.add(new User(data.author, client));
|
||||
|
||||
this.content = data.content;
|
||||
|
||||
var mentionData = client.internal.resolver.resolveMentions(data.content);
|
||||
this.cleanContent = mentionData[1];
|
||||
this.mentions = new Cache();
|
||||
|
||||
data.mentions.forEach((mention) => {
|
||||
mentionData[0].forEach((mention) => {
|
||||
// this is .add and not .get because it allows the bot to cache
|
||||
// users from messages from logs who may have left the server and were
|
||||
// not previously cached.
|
||||
|
||||
Reference in New Issue
Block a user