Skip to content

Commit

Permalink
In-order + duplicate mentions, cleanContent in Messages
Browse files Browse the repository at this point in the history
  • Loading branch information
abalabahaha committed Jan 30, 2016
1 parent 8b392f3 commit e3173d1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
9 changes: 6 additions & 3 deletions lib/Client/Resolver/Resolver.js
Expand Up @@ -155,7 +155,7 @@ var Resolver = (function () {
// resource is a string
var _mentions = [];
var changed = resource;
for (var _iterator2 = resource.match(/<@[^>]*>/g) || [], _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
for (var _iterator2 = resource.match(/<@[0-9]+>/g) || [], _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref2;

if (_isArray2) {
Expand All @@ -170,8 +170,11 @@ var Resolver = (function () {
var mention = _ref2;

var 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);
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];
};
Expand Down
5 changes: 4 additions & 1 deletion lib/Structures/Message.js
Expand Up @@ -48,9 +48,12 @@ var Message = (function (_Equality) {
if (data.author instanceof _User2["default"]) this.author = data.author;else this.author = client.internal.users.add(new _User2["default"](data.author, client));

this.content = data.content;

var mentionData = client.internal.resolver.resolveMentions(data.content);
this.cleanContent = mentionData[1];
this.mentions = new _UtilCache2["default"]();

data.mentions.forEach(function (mention) {
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.
Expand Down
11 changes: 7 additions & 4 deletions src/Client/Resolver/Resolver.js
Expand Up @@ -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];
}
Expand Down
5 changes: 4 additions & 1 deletion src/Structures/Message.js
Expand Up @@ -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.
Expand Down

0 comments on commit e3173d1

Please sign in to comment.