Skip to content
This repository has been archived by the owner on Feb 5, 2020. It is now read-only.

Commit

Permalink
Handle IRC style mentions
Browse files Browse the repository at this point in the history
This replaces irc mentions like 'john: ' and 'john, ' to '@john '.
Closes #2
  • Loading branch information
lieuwex committed Jun 8, 2015
1 parent e5e82ca commit 44d6690
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/gitter-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,34 @@ Adapter.prototype.sendMessage = function(target, message) {
var uri = target.replace('#','');
var isStatus = /^\u0001ACTION/.test(message);

var regResult = /^((\w+)[:,]\s*).+/.exec(message);
var mention = undefined;
var mentioned = undefined;

// This are /me IRC messages.
if (isStatus) {
message = message
.replace(/^\u0001ACTION /, '@' + c.nick + ' ')
.replace(/\u0001$/, '');
}

if (regResult !== undefined) {
var mention = regResult[1];
var mentioned = regResult[2];
}

this.gitterClient.rooms.join(uri)
.then(function(room) {
return [room, (room.oneToOne ? [] : room.users())];
})
.spread(function (room, users) {
users.forEach(function (userFound) {
if(user.username.toLowerCase() === mentioned.toLowerCase()) {
// Mentioned user is in room.
message = message.replace(mention, "@" + mentioned + " ");
}
});

return isStatus ? room.sendStatus(message) : room.send(message);
})
.catch(function(err){
Expand Down

0 comments on commit 44d6690

Please sign in to comment.