Skip to content

Instantly share code, notes, and snippets.

@sfujiwara
Last active March 8, 2016 17:56
Show Gist options
  • Save sfujiwara/29796cc2d94c263018c7 to your computer and use it in GitHub Desktop.
Save sfujiwara/29796cc2d94c263018c7 to your computer and use it in GitHub Desktop.
# 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