Files
open-ticket/core/api/pluginlauncher.js
T
2022-11-24 21:51:13 +01:00

37 lines
1.3 KiB
JavaScript

const fs = require("fs")
const bot = require("../../index")
const log = bot.errorLog.log
module.exports = () => {
const files = fs.readdirSync("./plugins")
const api = require("./api.json")
var totalcount = 0
var successcount = 0
var failcount = 0
files.forEach((file) => {
if (file.endsWith(".plugin.js")){
try {
require("../../plugins/"+file)()
successcount++
totalcount++
}catch(err){
/**@type {Error} */
const theError = err
if (api.enableAPIdebug){
try {
const data = fs.readFileSync("./apiDebug.txt")
const newData = data ? data.toString() : ""
fs.writeFileSync("./apiDebug.txt",newData+"ERROR: "+theError.name+": "+theError.message+"\n"+theError.stack+"\n\n")
}catch{
fs.writeFileSync("./apiDebug.txt","ERROR: "+theError.name+": "+theError.message+"\n"+theError.stack+"\n\n")
}
}
failcount++
totalcount++
}
}
})
log("info","loaded plugins",[{key:"success",value:successcount},{key:"error",value:failcount},{key:"total",value:totalcount}])
}