Fix unduplicated mentions

This commit is contained in:
abalabahaha
2016-01-30 13:16:18 -08:00
parent 89e3396af6
commit 46807bf1c1
2 changed files with 9 additions and 7 deletions

View File

@@ -51,19 +51,21 @@ var Message = (function (_Equality) {
var mentionData = client.internal.resolver.resolveMentions(data.content);
this.cleanContent = mentionData[1];
this.mentions = new _UtilCache2["default"]();
this.mentions = [];
mentionData[0].forEach(function (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.
if (mention instanceof _User2["default"]) _this.mentions.add(mention);else _this.mentions.add(client.internal.users.add(new _User2["default"](mention, client)));
if (mention instanceof _User2["default"]) _this.mentions.push(mention);else _this.mentions.push(client.internal.users.add(new _User2["default"](mention, client)));
});
}
Message.prototype.isMentioned = function isMentioned(user) {
user = this.client.internal.resolver.resolveUser(user);
return !!(user && this.mentions.has(user));
return !!(user && this.mentions.find(function (m) {
return m.id == user.id;
}));
};
Message.prototype.toString = function toString() {

View File

@@ -30,16 +30,16 @@ export default class Message extends Equality{
var mentionData = client.internal.resolver.resolveMentions(data.content);
this.cleanContent = mentionData[1];
this.mentions = new Cache();
this.mentions = [];
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.
if(mention instanceof User)
this.mentions.add(mention);
this.mentions.push(mention);
else
this.mentions.add(client.internal.users.add(new User(mention, client)));
this.mentions.push(client.internal.users.add(new User(mention, client)));
});
}
@@ -49,7 +49,7 @@ export default class Message extends Equality{
isMentioned(user){
user = this.client.internal.resolver.resolveUser(user);
return !!(user && this.mentions.has(user));
return !!(user && this.mentions.find(m => m.id == user.id));
}
toString(){