Last active
March 8, 2016 17:56
-
-
Save sfujiwara/29796cc2d94c263018c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description | |
# Hubot find palindrome. | |
# | |
# Dependencies: | |
# "kuromoji": "0.0.5" | |
# | |
# Configuration: | |
# None | |
# | |
# Author: | |
# Shuhei Fujiwara | |
module.exports = (robot) -> | |
kuromoji = require 'kuromoji' | |
kb = kuromoji.builder({dicPath: 'node_modules/kuromoji/dist/dict/'}) | |
tokenizer = null | |
kb.build (err, _tokenizer) -> tokenizer = _tokenizer | |
robot.hear /(\S+)/i, (msg) -> | |
tokens = tokenizer.tokenize(msg.match[1]) | |
yomi = (i['reading'] for i in tokens).join '' | |
imoy = (yomi.split '').reverse().join('') | |
if (yomi.length >= 5) and (yomi is imoy) | |
msg.reply "#{yomi}!nice palindrome." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment