diff --git a/index.js b/index.js index cf0b652..f554119 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ import { readdirSync } from "node:fs"; const bots = []; +const plugins = []; const bpl = readdirSync('plugins') for (const plugin of bpl) { if (!plugin.endsWith('.js')) { @@ -16,6 +17,7 @@ for (const plugin of bpl) { for(const bot of bots){ pluginItem.load(bot) } + plugins.push(pluginItem) // For rejoining }) } catch (e) { console.log(e) } } @@ -35,6 +37,9 @@ const createBot = function createBot (host, oldId) { delete bots[oldId] bot.id = oldId bots[oldId] = bot + for(const pluginItem of plugins){ + pluginItem.load(bot) + } } else { bot.id = bots.length bots.push(bot) @@ -43,6 +48,18 @@ const createBot = function createBot (host, oldId) { bot.host = host bot.interval = {} + bot.info = (msg) => { + console.log(`[${bot.id}] [info] ${msg}`) + } + + bot.displayChat = (type, subtype, msg) => { + if (settings.displaySubtypesToConsole) { + console.log(`[${bot.id}] [${type}] [${subtype}] ${msg}`) + } else { + console.log(`[${bot.id}] [${type}] ${msg}`) + } + } + bot._client.on('error', (err) => { console.log(err) }) diff --git a/plugins/rejoin.js b/plugins/rejoin.js new file mode 100644 index 0000000..8723d2c --- /dev/null +++ b/plugins/rejoin.js @@ -0,0 +1,14 @@ +import { createBot } from "../index.js" +const load = (b) => { + b._client.on('end', () => { + b.info(`Bot ${b.id} disconnected`) + for (const i in b.interval) { + clearInterval(b.interval[i]) + } + setTimeout(() => { + b.info(`Re-connecting bot ${b.id}`) + createBot(b.host, b.id) + }, 5000) + }) +} +export { load } \ No newline at end of file