From 4e030bf95b60d846d95185eb8bcc7ef2b23cc5ac Mon Sep 17 00:00:00 2001 From: DJj123dj <80536295+DJj123dj@users.noreply.github.com> Date: Sun, 1 Sep 2024 18:38:08 +0200 Subject: [PATCH] Fixed config checker bugs & added new flags --- README.md | 19 +++++-- index.js | 82 ++++++++++++++--------------- src/core/api/defaults/checker.ts | 5 +- src/core/api/defaults/flag.ts | 2 + src/core/api/modules/checker.ts | 14 +++-- src/data/framework/checkerLoader.ts | 1 + src/data/framework/flagLoader.ts | 2 + 7 files changed, 76 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index a6252d3..67d34c6 100644 --- a/README.md +++ b/README.md @@ -80,9 +80,22 @@ The team behind Open Ticket! ### ❤️ Sponsors A big thanks to all our sponsors! Without them, it wouldn't be possible to create this project! -|Profile Picture|Profile Picture|Profile Picture| -|----|-|-| -|**[SpyEye](https://github.com/SpyEye2)**|**[DOSEV5](https://github.com/DOSEV5)**|**[Mods HD](https://github.com/mods-hd)**| + + + + + + + + + +
Profile PictureProfile Picture
DOSEV5roppl3r
+ +**Past Sponsors:**
+ +SpyEye +Mods HD + ### 💬 Translators |Language |Maintainer (discord name) |Status | diff --git a/index.js b/index.js index a947651..fd4d6a3 100644 --- a/index.js +++ b/index.js @@ -3,48 +3,48 @@ const fs = require("fs") const ts = require("typescript") const nodepath = require('path') -//REMOVE EXISTING BUILDS -console.log("OT: Removing Prebuilds...") -fs.rmSync("./dist",{recursive:true,force:true}) +if (!process.argv.includes("--no-compile")){ + //REMOVE EXISTING BUILDS + console.log("OT: Removing Prebuilds...") + fs.rmSync("./dist",{recursive:true,force:true}) -//COMPILE TYPESCRIPT -console.log("OT: Compiling Typescript...") -const configPath = nodepath.resolve('./tsconfig.json') -const configFile = ts.readConfigFile(configPath,ts.sys.readFile) + //COMPILE TYPESCRIPT + console.log("OT: Compiling Typescript...") + const configPath = nodepath.resolve('./tsconfig.json') + const configFile = ts.readConfigFile(configPath,ts.sys.readFile) -//check for tsconfig errors -if (configFile.error){ - const message = ts.formatDiagnosticsWithColorAndContext([configFile.error],ts.createCompilerHost({})) - console.error(message) - process.exit(1) + //check for tsconfig errors + if (configFile.error){ + const message = ts.formatDiagnosticsWithColorAndContext([configFile.error],ts.createCompilerHost({})) + console.error(message) + process.exit(1) + } + + //parse tsconfig file + const parsedConfig = ts.parseJsonConfigFileContent(configFile.config,ts.sys,nodepath.dirname(configPath)) + + //create program/compiler + const program = ts.createProgram({ + rootNames:parsedConfig.fileNames, + options:parsedConfig.options + }) + + //emit all compiled files + const emitResult = program.emit() + + //print emit errors/warnings (type errors) + const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics) + const formattedDiagnostics = ts.formatDiagnosticsWithColorAndContext(allDiagnostics, ts.createCompilerHost(parsedConfig.options)) + console.log(formattedDiagnostics) + + if (emitResult.emitSkipped || allDiagnostics.find((d) => d.category == ts.DiagnosticCategory.Error || d.category == ts.DiagnosticCategory.Warning)){ + console.log("OT: Compilation Failed!") + process.exit(1) + } } -//parse tsconfig file -const parsedConfig = ts.parseJsonConfigFileContent(configFile.config,ts.sys,nodepath.dirname(configPath)) - -//create program/compiler -const program = ts.createProgram({ - rootNames:parsedConfig.fileNames, - options:parsedConfig.options -}) - -//emit all compiled files -const emitResult = program.emit() - -//print emit errors/warnings (type errors) -const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics) -const formattedDiagnostics = ts.formatDiagnosticsWithColorAndContext(allDiagnostics, ts.createCompilerHost(parsedConfig.options)) -console.log(formattedDiagnostics) - -//run with code -if (emitResult.emitSkipped){ - console.log("OT: Compilation Failed!") - process.exit(1) -}else{ - console.log("OT: Compilation Succeeded!") - if (process.argv.includes("-%-compile")) process.exit(0) //exit when only compile is required! - - //START THE BOT - console.log("OT: Starting Bot!") - require("./dist/src/index.js") -} \ No newline at end of file +//START BOT +console.log("OT: Compilation Succeeded!") +if (process.argv.includes("--compile-only")) process.exit(0) //exit when only compile is required! +console.log("OT: Starting Bot!") +require("./dist/src/index.js") \ No newline at end of file diff --git a/src/core/api/defaults/checker.ts b/src/core/api/defaults/checker.ts index 69e6d53..e12773d 100644 --- a/src/core/api/defaults/checker.ts +++ b/src/core/api/defaults/checker.ts @@ -345,6 +345,7 @@ export class ODCheckerTranslationRegister_Default extends ODCheckerTranslationRe */ export interface ODCheckerFunctionManagerIds_Default { "openticket:unused-options":ODCheckerFunction, + "openticket:unused-questions":ODCheckerFunction, "openticket:dropdown-options":ODCheckerFunction } @@ -355,14 +356,14 @@ export interface ODCheckerFunctionManagerIds_Default { * This default class is made for the global variable `openticket.checkers.functions`! */ export class ODCheckerFunctionManager_Default extends ODCheckerFunctionManager { - get(id:CheckerFunctionId): ODCheckerManagerIds_Default[CheckerFunctionId] + get(id:CheckerFunctionId): ODCheckerFunctionManagerIds_Default[CheckerFunctionId] get(id:ODValidId): ODCheckerFunction|null get(id:ODValidId): ODCheckerFunction|null { return super.get(id) } - remove(id:CheckerFunctionId): ODCheckerManagerIds_Default[CheckerFunctionId] + remove(id:CheckerFunctionId): ODCheckerFunctionManagerIds_Default[CheckerFunctionId] remove(id:ODValidId): ODCheckerFunction|null remove(id:ODValidId): ODCheckerFunction|null { diff --git a/src/core/api/defaults/flag.ts b/src/core/api/defaults/flag.ts index 0d4b835..7c9a459 100644 --- a/src/core/api/defaults/flag.ts +++ b/src/core/api/defaults/flag.ts @@ -21,6 +21,8 @@ export interface ODFlagManagerIds_Default { "openticket:no-plugins":ODFlag, "openticket:soft-plugins":ODFlag, "openticket:force-slash-update":ODFlag, + "openticket:no-compile":ODFlag, + "openticket:compile-only":ODFlag, } /**## ODFlagManager_Default `default_class` diff --git a/src/core/api/modules/checker.ts b/src/core/api/modules/checker.ts index 3b0138e..90d0249 100644 --- a/src/core/api/modules/checker.ts +++ b/src/core/api/modules/checker.ts @@ -1192,12 +1192,20 @@ export class ODCheckerCustomStructure_EmojiString extends ODCheckerStringStructu const newOptions = options ?? {} newOptions.custom = (checker,value,locationTrace,locationId,locationDocs) => { const lt = checker.locationTraceDeref(locationTrace) - if (typeof value != "string") return false - else if ([...value].length < minLength){ + + const emojis: string[] = [] + const emojiSplitRegex = /(?:(?:\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])|(?:))/g + let emoji = emojiSplitRegex.exec(value) + while (emoji != null){ + emojis.push(emoji[0]) + emoji = emojiSplitRegex.exec(value) + } + + if (emojis.length < minLength){ checker.createMessage("openticket:emoji-too-short","error",`This string needs to have at least ${minLength} emoji's!`,lt,null,[maxLength.toString()],this.id,(this.options.docs ?? null)) return false - }else if ([...value].length > maxLength){ + }else if (emojis.length > maxLength){ checker.createMessage("openticket:emoji-too-long","error",`This string needs to have at most ${maxLength} emoji's!`,lt,null,[maxLength.toString()],this.id,(this.options.docs ?? null)) return false }else if (!allowCustomDiscordEmoji && //.test(value)){ diff --git a/src/data/framework/checkerLoader.ts b/src/data/framework/checkerLoader.ts index 667fa1b..76d5963 100644 --- a/src/data/framework/checkerLoader.ts +++ b/src/data/framework/checkerLoader.ts @@ -12,6 +12,7 @@ export const loadAllConfigCheckers = async () => { export const loadAllConfigCheckerFunctions = async () => { openticket.checkers.functions.add(new api.ODCheckerFunction("openticket:unused-options",defaultUnusedOptionsFunction)) + openticket.checkers.functions.add(new api.ODCheckerFunction("openticket:unused-questions",defaultUnusedQuestionsFunction)) openticket.checkers.functions.add(new api.ODCheckerFunction("openticket:dropdown-options",defaultDropdownOptionsFunction)) } diff --git a/src/data/framework/flagLoader.ts b/src/data/framework/flagLoader.ts index 7552019..5964046 100644 --- a/src/data/framework/flagLoader.ts +++ b/src/data/framework/flagLoader.ts @@ -13,4 +13,6 @@ export const loadAllFlags = async () => { openticket.flags.add(new api.ODFlag("openticket:no-plugins","No Plugins","Disable all Open Ticket plugins!","--no-plugins",["-np"])) openticket.flags.add(new api.ODFlag("openticket:soft-plugins","Soft Plugins","Don't crash the bot when a plugin crashes!","--soft-plugins",["-sp"])) openticket.flags.add(new api.ODFlag("openticket:force-slash-update","Force Slash Update","Force update all slash commands.","--force-slash",["-fs"])) + openticket.flags.add(new api.ODFlag("openticket:no-compile","No Compile","Disable compilation of plugins & bot before starting.","--no-compile",[])) + openticket.flags.add(new api.ODFlag("openticket:compile-only","Compile Only","This description will never be shown because the bot wouldn't run when this flag is enabled :)","--compile-only",[])) } \ No newline at end of file