forked from joeyguerra/hubot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (44 loc) · 1.41 KB
/
index.js
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
'use strict'
const User = require('./src/user')
const Brain = require('./src/brain')
const Robot = require('./src/robot')
const Adapter = require('./src/adapter')
const Response = require('./src/response')
const Listener = require('./src/listener')
const Message = require('./src/message')
const DataStore = require('./src/datastore')
module.exports = {
User,
Brain,
Robot,
Adapter: Adapter,
Response,
Listener: Listener.Listener,
TextListener: Listener.TextListener,
Message: Message.Message,
TextMessage: Message.TextMessage,
EnterMessage: Message.EnterMessage,
LeaveMessage: Message.LeaveMessage,
TopicMessage: Message.TopicMessage,
CatchAllMessage: Message.CatchAllMessage,
DataStore: DataStore.DataStore,
DataStoreUnavailable: DataStore.DataStoreUnavailable,
async loadBot (adapterPath, adapterName, enableHttpd, botName, botAlias) {
const bot = new module.exports.Robot(adapterPath, adapterName, enableHttpd, botName, botAlias)
try {
await bot.loadAdapter(`${adapterName}.mjs`)
bot.errorHandlers = []
bot.on('error', (err, res) => {
return bot.invokeErrorHandlers(err, res)
})
bot.onUncaughtException = err => {
return bot.emit('error', err)
}
process.on('uncaughtException', bot.onUncaughtException)
} catch (err) {
bot.logger.error(`Cannot load adapter ${adapterName} - ${err}`)
process.exit(1)
}
return bot
}
}