kulmapaikka-ircbot/appTest.js
2019-11-20 20:28:11 +02:00

59 lines
1.3 KiB
JavaScript

// Start without app
function prompt (question, callback) {
var stdin = process.stdin
var stdout = process.stdout
stdin.resume()
stdout.write(question)
stdin.once('data', function (data) {
callback(data.toString().trim())
})
}
// Load config
const config = require('./config')
// Load new plugins
const PluginManager = require('./plugins/pluginManager.js')
const pluginManager = new PluginManager(config)
pluginManager.loadAllPlugins()
// Configure logger
// create a write stream (in append mode)
// ensure log directory exists
const logger = require('./logger')
const isPm = false
function query () {
prompt('> ', function (message) {
if (!isPm) {
pluginManager.testPlugins(message).then(function (results) {
for (var i = 0; i < results.length; i++) {
let result = results[i]
console.log('[' + result.to + ']', result.message)
}
query()
}, function (error) {
logger.error('Plugin error: ', error)
query()
})
} else {
// PM
pluginManager.testPlugins(message, false).then(function (results) {
for (var i = 0; i < results.length; i++) {
console.log(results[i])
}
query()
}, function (error) {
logger.error('Plugin error: ', error)
query()
})
}
})
}
query()