From 177ab95dba5c49111436201d1c5a25eddccb0273 Mon Sep 17 00:00:00 2001 From: DJj123dj <80536295+DJj123dj@users.noreply.github.com> Date: Thu, 22 Aug 2024 21:22:19 +0200 Subject: [PATCH] Fixed permission error & preparing for win build --- index.js | 14 +++++++++----- package.json | 4 ++-- src/core/api/modules/config.ts | 5 +++-- src/core/api/modules/language.ts | 5 +++-- src/data/framework/permissionLoader.ts | 4 +++- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index d98db68..5f2ba69 100644 --- a/index.js +++ b/index.js @@ -3,9 +3,13 @@ const fs = require("fs") const child = require("child_process") -if (!fs.existsSync("./dist/src/index.js")){ - console.log("Compiling the bot...") - child.execSync("npm run build") - console.log("\n\nFinished compilation!") -} + +console.log("Removing prebuilds...") +fs.rmSync("./dist",{recursive:true,force:true}) + +console.log("Compiling the bot...") +//exit when only compilation is required +if (process.argv.includes("-%-compile")) process.exit(0) + +//start the bot require("./dist/src/index") \ No newline at end of file diff --git a/package.json b/package.json index 03dc02d..9842d92 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ ], "main": "index.js", "scripts": { - "build": "rm -rf ./dist/ && npx tsc -p ./tsconfig.json", - "start": "npm run build && node index.js", + "build": "node index.js -%-compile && npx tsc -p ./tsconfig.json", + "start": "npm run build && node ./dist/src/index.js", "test": "npm run start -- --dev-config --dev-database" }, "type": "commonjs", diff --git a/src/core/api/modules/config.ts b/src/core/api/modules/config.ts index 65a149e..a875946 100644 --- a/src/core/api/modules/config.ts +++ b/src/core/api/modules/config.ts @@ -90,8 +90,9 @@ export class ODJsonConfig extends ODConfig { const filename = (file.endsWith(".json")) ? file : file+".json" this.file = customPath ? nodepath.join("./",customPath,filename) : nodepath.join("./config/",filename) this.data = JSON.parse(fs.readFileSync(this.file).toString()) - }catch{ - throw new ODSystemError("config \""+nodepath.join("./",customPath ?? "",file)+"\" doesn't exist!") + }catch(err){ + process.emit("uncaughtException",err) + throw new ODSystemError("Config \""+nodepath.join("./",customPath ?? "./config/",file)+"\" doesn't exist!") } } } \ No newline at end of file diff --git a/src/core/api/modules/language.ts b/src/core/api/modules/language.ts index aed5821..0a4c8c5 100644 --- a/src/core/api/modules/language.ts +++ b/src/core/api/modules/language.ts @@ -22,8 +22,9 @@ export class ODLanguage extends ODManagerData { const filename = (file.endsWith(".json")) ? file : file+".json" this.file = customPath ? nodepath.join("./",customPath,filename) : nodepath.join("./languages/",filename) this.data = JSON.parse(fs.readFileSync(this.file).toString()) - }catch{ - throw new ODSystemError("[API ERROR] Language \""+file+"\" doesn't exist!") + }catch(err){ + process.emit("uncaughtException",err) + throw new ODSystemError("Language \""+nodepath.join("./",customPath ?? "./languages/",file)+"\" doesn't exist!") } if (this.data["_TRANSLATION"]) this.metadata = this.data["_TRANSLATION"] } diff --git a/src/data/framework/permissionLoader.ts b/src/data/framework/permissionLoader.ts index 4b080f8..5e6c4b2 100644 --- a/src/data/framework/permissionLoader.ts +++ b/src/data/framework/permissionLoader.ts @@ -63,6 +63,7 @@ export const addTicketPermissions = async (ticket:api.ODTicket) => { const readAdmins = ticket.option.exists("openticket:admins-readonly") ? ticket.option.get("openticket:admins-readonly").value : [] admins.concat(readAdmins).forEach(async (admin) => { + if (openticket.permissions.exists("openticket:ticket-admin_"+ticket.id.value+"_"+admin)) return const role = await mainServer.roles.fetch(admin) if (!role) return openticket.log("Unable to register permission for ticket admin!","error",[ {key:"roleid",value:admin} @@ -76,7 +77,8 @@ export const removeTicketPermissions = async (ticket:api.ODTicket) => { const admins = ticket.option.exists("openticket:admins") ? ticket.option.get("openticket:admins").value : [] const readAdmins = ticket.option.exists("openticket:admins-readonly") ? ticket.option.get("openticket:admins-readonly").value : [] - admins.concat(readAdmins).forEach(async (admin) => { + admins.concat(readAdmins).forEach(async (admin) => { + if (!openticket.permissions.exists("openticket:ticket-admin_"+ticket.id.value+"_"+admin)) return openticket.permissions.remove("openticket:ticket-admin_"+ticket.id.value+"_"+admin) }) } \ No newline at end of file