This commit is contained in:
7cc5c4f330d47060 2024-10-21 17:47:49 -04:00
parent e4ec458e6e
commit 0aacd8e7f7
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
2 changed files with 31 additions and 0 deletions

View file

@ -6,6 +6,7 @@ import { readdirSync } from "node:fs";
const bots = []; const bots = [];
const plugins = [];
const bpl = readdirSync('plugins') const bpl = readdirSync('plugins')
for (const plugin of bpl) { for (const plugin of bpl) {
if (!plugin.endsWith('.js')) { if (!plugin.endsWith('.js')) {
@ -16,6 +17,7 @@ for (const plugin of bpl) {
for(const bot of bots){ for(const bot of bots){
pluginItem.load(bot) pluginItem.load(bot)
} }
plugins.push(pluginItem) // For rejoining
}) })
} catch (e) { console.log(e) } } catch (e) { console.log(e) }
} }
@ -35,6 +37,9 @@ const createBot = function createBot (host, oldId) {
delete bots[oldId] delete bots[oldId]
bot.id = oldId bot.id = oldId
bots[oldId] = bot bots[oldId] = bot
for(const pluginItem of plugins){
pluginItem.load(bot)
}
} else { } else {
bot.id = bots.length bot.id = bots.length
bots.push(bot) bots.push(bot)
@ -43,6 +48,18 @@ const createBot = function createBot (host, oldId) {
bot.host = host bot.host = host
bot.interval = {} 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) => { bot._client.on('error', (err) => {
console.log(err) console.log(err)
}) })

14
plugins/rejoin.js Normal file
View file

@ -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 }