-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
hubot
executable file
·104 lines (79 loc) · 2.66 KB
/
hubot
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env coffee
##
# hubot [options]
#
# Launch an interactive hubot
#
Hubot = require '..'
Fs = require 'fs'
Path = require 'path'
HTTP = require 'http'
Creator = require '../src/creator'
OptParse = require 'optparse'
PortNumber = parseInt(process.env.PORT) || 8080
Switches = [
[ "-h", "--help", "Display the help information" ],
[ "-a", "--adapter ADAPTER", "The Adapter to use" ],
[ "-c", "--create PATH", "Create a deployable hubot" ],
[ "-s", "--enable-slash", "Enable replacing the robot's name with '/' (deprecated)" ],
[ "-l", "--alias ALIAS", "Enable replacing the robot's name with alias" ],
[ "-n", "--name NAME", "The name of the robot in chat" ],
[ "-v", "--version", "Displays the version of hubot installed" ]
]
Options =
path: "."
name: "Hubot"
create: false
adapter: "shell"
alias: false
Parser = new OptParse.OptionParser(Switches)
Parser.banner = "Usage hubot [options]"
Parser.on "adapter", (opt, value) ->
Options.adapter = value
Parser.on "name", (opt, value) ->
Options.name = value
Parser.on "create", (opt, value) ->
Options.path = value
Options.create = true
Parser.on "enable-slash", (opt) ->
console.log "WARNING: -s and --enable-slash are deprecated please use -l or --alias '/'"
Options.alias = '/'
Parser.on "alias", (opt, value) ->
Options.alias = value
Parser.on "help", (opt, value) ->
console.log Parser.toString()
process.exit 0
Parser.on "version", (opt, value) ->
Options.version = true
Parser.parse process.argv
process.on 'SIGTERM', -> process.exit(0)
if Options.create
creator = new Creator.Creator(Options.path)
creator.run()
else if Options.version
package_path = __dirname + "/../package.json"
Fs.readFile package_path, (err,data) ->
if err
console.error "Could not open package file : %s", err
process.exit 1
content = JSON.parse(data.toString('ascii'))
console.log content['version']
process.exit 0
else
adapterPath = Path.resolve "src", "adapters"
robot = Hubot.loadBot adapterPath, Options.adapter, Options.name
robot.enableSlash = Options.enableSlash
robot.alias = Options.alias
scriptsPath = Path.resolve ".", "scripts"
robot.load scriptsPath
scriptsPath = Path.resolve "src", "scripts"
robot.load scriptsPath
scriptsFile = Path.resolve "hubot-scripts.json"
Path.exists scriptsFile, (exists) =>
if exists
Fs.readFile scriptsFile, (err, data) ->
scripts = JSON.parse data
scriptsPath = Path.resolve "node_modules", "hubot-scripts", "src", "scripts"
robot.loadHubotScripts scriptsPath, scripts
robot.run()
# vim:ft=coffee ts=2 sw=2 et :