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

Handle IRC style mentions #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/gitter-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ Adapter.prototype.sendMessage = function(target, message) {
var uri = target.replace('#','');
var isStatus = /^\u0001ACTION/.test(message);

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

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

// This are /me IRC messages.
if (isStatus) {
message = message
Expand All @@ -157,6 +165,21 @@ Adapter.prototype.sendMessage = function(target, message) {

this.gitterClient.rooms.join(uri)
.then(function(room) {
return [room, (room.oneToOne ? [] : room.users())];
})
.spread(function (room, users) {
if (regResult !== null) {
for (var i = 0; i < users.length; i++) {
var user = users[i];

if (user.username.toLowerCase() === mentioned.toLowerCase()) {
// Mentioned user is in room.
message = message.replace(mention, "@" + mentioned + " ");
break;
}
}
}

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