-
Notifications
You must be signed in to change notification settings - Fork 0
/
bible-api.coffee
48 lines (43 loc) · 1.28 KB
/
bible-api.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Description:
# Access Tim Morgan's bible-api.com to display Bible passages
# Translations:
# /cherokee Cherokee New Testament
# /kjv King James Version
# /web World English Bible (default)
# /clementine Clementine Latin Vulgate
# /almeida João Ferreira de Almeida - Portuguese
# /rccv Romanian Corrected Cornilescu Version
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot bible <optional /translation> <book chapter:verse>
#
# Author:
# Brendan <[email protected]>
module.exports = (robot) ->
# regex inspired by
# https://github.com/github/hubot-scripts/blob/master/src/scripts/lmgtfy.coffee
robot.respond /bible?\s?(?:\/(\w*))? (.*)/i, (msg) ->
url = "http://bible-api.com/#{msg.match[2]}"
url += "?translation=#{msg.match[1]}" if msg.match[1]
robot.http(url)
.header('Accept', 'application/json')
.get() (err, res, body) ->
# error checking code here
if err
msg.send "Error: #{err}"
return
else
data = JSON.parse body
if data.error
reply = data.error
else
reply = "\n#{data.reference} (#{data.translation_id})\n"
for verse in data.verses
reply += "#{verse.verse} #{verse.text}"
msg.send reply