Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added emoji convertion for irc. #26

Merged
merged 3 commits into from
Apr 17, 2015
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var logger = require('winston');
var Slack = require('slack-client');
var errors = require('./errors');
var validateChannelMapping = require('./validators').validateChannelMapping;
var emojis = require('./emoji');

var REQUIRED_FIELDS = ['server', 'nickname', 'channelMapping', 'token'];

Expand Down Expand Up @@ -118,6 +119,12 @@ Bot.prototype.parseText = function(text) {
return '<' + label + '>';
}
return '<' + command + '>';
})
.replace(/\:(\w+)\:/g, function(match, emoji) {
if (emoji in emojis) {
return emojis[emoji];
}
return match;
});
};

Expand Down
20 changes: 20 additions & 0 deletions lib/emoji.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"smile": ":)",
"simple_smile": ":)",
"smiley": ":-)",
"grin": ":D",
"wink": ";)",
"smirk": ";)",
"blush": ":$",
"stuck_out_tongue": ":P",
"stuck_out_tongue_winking_eye": ";P",
"stuck_out_tongue_closed_eyes": "",
"disappointed": ":(",
"astonished": ":O",
"open_mouth": ":O",
"heart": "<3",
"broken_heart": "</3",
"thumb": "*thumbs-up*",
"thumbsup": "*thumbs-up*",
"confused": ":S"
}
5 changes: 5 additions & 0 deletions test/bot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,9 @@ describe('Bot', function() {
this.bot.parseText('<!somecommand> <!somecommand|readable>')
.should.equal('<somecommand> <readable>');
});

it('should parse emojis correctly', function() {
this.bot.parseText(':smile:').should.equal(':)');
this.bot.parseText(':train:').should.equal(':train:');
});
});