mirror of
https://github.com/nioc/xmpp-bot.git
synced 2024-09-20 02:50:15 +02:00
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
|
/**
|
||
|
* Configuration
|
||
|
*
|
||
|
* Handle configuration file
|
||
|
*
|
||
|
* @file This files defines the configuration
|
||
|
* @author nioc
|
||
|
* @since 1.0.0
|
||
|
* @license AGPL-3.0+
|
||
|
*/
|
||
|
|
||
|
module.exports = function Configuration (logger) {
|
||
|
let config
|
||
|
try {
|
||
|
let data = require('fs').readFileSync('./config.json')
|
||
|
config = JSON.parse(data)
|
||
|
} catch (error) {
|
||
|
logger.fatal(`Invalid configuration file: ${error.message}`)
|
||
|
process.exit(99)
|
||
|
}
|
||
|
return {
|
||
|
listener: {
|
||
|
path: config.webhooksListener.path,
|
||
|
port: config.webhooksListener.port,
|
||
|
ssl: config.webhooksListener.ssl,
|
||
|
log: config.webhooksListener.accessLog,
|
||
|
users: config.webhooksListener.users.reduce((acc, user) => {
|
||
|
acc[user.login] = user.password
|
||
|
return acc
|
||
|
}, {})
|
||
|
},
|
||
|
xmpp: config.xmppServer,
|
||
|
logger: config.logger,
|
||
|
getWebhookAction: (path) => {
|
||
|
return config.incomingWebhooks.find((webhook) => {
|
||
|
return (webhook.path === path)
|
||
|
})
|
||
|
},
|
||
|
getOutgoingWebhook: (code) => {
|
||
|
return config.outgoingWebhooks.find((webhook) => {
|
||
|
return (webhook.code === code)
|
||
|
})
|
||
|
},
|
||
|
getXmppHookAction: (room) => {
|
||
|
return config.xmppHooks.find((xmppHook) => {
|
||
|
return (xmppHook.room === room)
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
}
|