Skip to content

Instantly share code, notes, and snippets.

@petitviolet
Created June 24, 2014 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petitviolet/55a70990f59fd7019f93 to your computer and use it in GitHub Desktop.
Save petitviolet/55a70990f59fd7019f93 to your computer and use it in GitHub Desktop.
show vim help from hubot!
# Description:
# Show vim help anywhere!
#
# Commands:
# :help <keyword> - Show <keyword> vim help
require 'util'
module.exports = (robot) ->
robot.hear /:help\s*(.*)$/i, (msg) ->
keyword = msg.match[1]
if !keyword
msg.send "Please input a keyword to show vimhelp"
return
# apiを叩く
request = robot.http("http://vim-help-jp.herokuapp.com/api/search/json/")
.query(query: keyword)
.header('Accept', 'application/json')
.get()
request (err, res, body) ->
if err || res.statusCode != 200
msg.send "Error in fetch json response from vim-help-jp"
return
try
data = JSON.parse(body)
if !data.text
msg.send 'Not Found...'
return
# 全角スペースを削除
msg.send [data.text.replace(/[\u0020\u3000]/g, ""),
data.vimdoc_url].join('')
catch _err
msg.send "Error in parsing JSON from vim-help-jp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment