-
Notifications
You must be signed in to change notification settings - Fork 1
/
help.coffee
77 lines (66 loc) · 1.66 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
67
68
69
70
71
72
73
74
75
76
77
# 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\s*(.*)?$/i, (msg) ->
cmds = robot.helpCommands()
if msg.match[1]
cmds = cmds.filter (cmd) ->
cmd.match new RegExp(msg.match[1], 'i')
emit = cmds.join "\n"
unless robot.name.toLowerCase() is 'hubot'
emit = emit.replace /hubot/ig, robot.name
msg.send emit
robot.router.get '/hubot/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