kulmapaikka-ircbot/appTest.js

59 lines
1.3 KiB
JavaScript
Raw Normal View History

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