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 2 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
18 changes: 18 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 !== undefined) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be !== null. .exec that produces no match returns a null.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn you're right, I had trouble running the server locally, I even checked the result of .exec when it doesn't find a match, woops 😅

mention = regResult[1];
mentioned = regResult[2];
}

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

this.gitterClient.rooms.join(uri)
.then(function(room) {
return [room, (room.oneToOne ? [] : room.users())];
})
.spread(function (room, users) {
users.forEach(function (user) {
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