2023-12-17 14:55:27 -05:00
|
|
|
const util = require('util')
|
|
|
|
const createBot = require('./bot.js')
|
|
|
|
//const chomensjs = require('./ChomensJS')
|
|
|
|
// TODO: Load a default config
|
2023-12-26 18:45:18 -05:00
|
|
|
const fs = require('fs/promises')
|
|
|
|
const fileExist = require('./util/file-exists')
|
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
function load () {
|
|
|
|
//const config = require('./config.js')
|
2023-12-17 14:55:27 -05:00
|
|
|
const readline = require('readline')
|
|
|
|
|
|
|
|
const rl = readline.createInterface({
|
|
|
|
input: process.stdin,
|
|
|
|
output: process.stdout,
|
|
|
|
})
|
|
|
|
require('dotenv').config()
|
|
|
|
const bots = []
|
|
|
|
for (const options of config.bots) {
|
|
|
|
const bot = createBot(options)
|
|
|
|
bots.push(bot)
|
|
|
|
bot.bots = bots
|
|
|
|
bot.options.username
|
|
|
|
bot.console.useReadlineInterface(rl)
|
|
|
|
|
|
|
|
// bot.on('error', (error), util.inspect(error))
|
2023-12-26 18:45:18 -05:00
|
|
|
|
2023-12-24 12:11:42 -05:00
|
|
|
try{
|
2023-12-20 11:54:03 -05:00
|
|
|
bot.on('error', console.error)
|
2023-12-24 12:11:42 -05:00
|
|
|
}catch(error){
|
|
|
|
console.log(error.stack)
|
|
|
|
}
|
2023-12-17 14:55:27 -05:00
|
|
|
}
|
2023-12-26 18:45:18 -05:00
|
|
|
}
|
|
|
|
async function checkConfig () {
|
|
|
|
if (!await fileExist(path.join(__dirname, 'config.js'))) {
|
|
|
|
console.error('Config not found! Creating a new Config from ')
|
|
|
|
await fs.copyFile(path.join(__dirname, 'default.js'), path.join(__dirname, 'config.js'))
|
|
|
|
} if (await fileExist(path.join(__dirname, 'config.js'))){
|
|
|
|
console.log('Config found! loading config please wait,......')
|
|
|
|
}
|
|
|
|
|
|
|
|
config = require('./config.js')
|
|
|
|
load()
|
|
|
|
}
|
2023-12-17 14:55:27 -05:00
|
|
|
|
2023-12-26 18:45:18 -05:00
|
|
|
checkConfig()
|
2023-12-17 14:55:27 -05:00
|
|
|
|
2023-12-26 18:45:18 -05:00
|
|
|
process.on('uncaughtException', (e) => {
|
|
|
|
console.log('uncaught ' + e.stack)
|
|
|
|
})
|
2023-12-17 14:55:27 -05:00
|
|
|
|