forked from laravelio/liona
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp.coffee
66 lines (59 loc) · 1.45 KB
/
help.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Description:
# Generates help commands for Hubot.
#
# Commands:
# hubot help - Displays all of the help commands that Hubot knows about.
# hubot help <query> - Displays all help commands that match <query>.
#
# URLS:
# /hubot/help
#
# Notes:
# These commands are grabbed from comment blocks at the top of each file.
helpContents = (name, commands) ->
"""
<html>
<head>
<title>#{name} Help</title>
<style type="text/css">
body {
background: #d3d6d9;
color: #636c75;
text-shadow: 0 1px 1px rgba(255, 255, 255, .5);
font-family: Helvetica, Arial, sans-serif;
}
h1 {
margin: 8px 0;
padding: 0;
}
.commands {
font-size: 13px;
}
p {
border-bottom: 1px solid #eee;
margin: 6px 0 0 0;
padding-bottom: 5px;
}
p:last-child {
border: 0;
}
</style>
</head>
<body>
<h1>#{name} Help</h1>
<div class="commands">
#{commands}
</div>
</body>
</html>
"""
module.exports = (robot) ->
robot.respond /help/i, (msg) ->
msg.send "#{process.env.HEROKU_URL}/#{robot.name}/help"
robot.router.get "/#{robot.name}/help", (req, res) ->
cmds = robot.helpCommands().map (cmd) ->
cmd.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>')
emit = "<p>#{cmds.join '</p><p>'}</p>"
emit = emit.replace /hubot/ig, "<b>#{robot.name}</b>"
res.setHeader 'content-type', 'text/html'
res.end helpContents robot.name, emit