Fixed config checker bugs & added new flags

This commit is contained in:
DJj123dj
2024-09-01 18:38:08 +02:00
parent adae64bab9
commit 4e030bf95b
7 changed files with 76 additions and 49 deletions
+16 -3
View File
@@ -80,9 +80,22 @@ The team behind Open Ticket!
### ❤️ Sponsors ### ❤️ Sponsors
A big thanks to all our sponsors! Without them, it wouldn't be possible to create this project! A big thanks to all our sponsors! Without them, it wouldn't be possible to create this project!
|<img src="https://github.com/SpyEye2.png" alt="Profile Picture" width="80px"></img>|<img src="https://github.com/DOSEV5.png" alt="Profile Picture" width="80px"></img>|<img src="https://github.com/mods-hd.png" alt="Profile Picture" width="80px"></img>| <table>
|----|-|-| <tr>
|**[SpyEye](https://github.com/SpyEye2)**|**[DOSEV5](https://github.com/DOSEV5)**|**[Mods HD](https://github.com/mods-hd)**| <td><img src="https://github.com/DOSEV5.png" alt="Profile Picture" width="80px"></td>
<td><img src="https://github.com/roppl3r.png" alt="Profile Picture" width="80px"></td>
</tr>
<tr>
<th><a href="https://github.com/DOSEV5">DOSEV5</a></th>
<th><a href="https://github.com/roppl3r">roppl3r</a></th>
</tr>
</table>
**Past Sponsors:**<br>
<a href="https://github.com/sponsors/DJj123dj">
<img src="https://github.com/SpyEye2.png" alt="SpyEye" width="40px">
<img src="https://github.com/mods-hd.png" alt="Mods HD" width="40px">
</a>
### 💬 Translators ### 💬 Translators
|Language |Maintainer (discord name) |Status | |Language |Maintainer (discord name) |Status |
+41 -41
View File
@@ -3,48 +3,48 @@ const fs = require("fs")
const ts = require("typescript") const ts = require("typescript")
const nodepath = require('path') const nodepath = require('path')
//REMOVE EXISTING BUILDS if (!process.argv.includes("--no-compile")){
console.log("OT: Removing Prebuilds...") //REMOVE EXISTING BUILDS
fs.rmSync("./dist",{recursive:true,force:true}) console.log("OT: Removing Prebuilds...")
fs.rmSync("./dist",{recursive:true,force:true})
//COMPILE TYPESCRIPT //COMPILE TYPESCRIPT
console.log("OT: Compiling Typescript...") console.log("OT: Compiling Typescript...")
const configPath = nodepath.resolve('./tsconfig.json') const configPath = nodepath.resolve('./tsconfig.json')
const configFile = ts.readConfigFile(configPath,ts.sys.readFile) const configFile = ts.readConfigFile(configPath,ts.sys.readFile)
//check for tsconfig errors //check for tsconfig errors
if (configFile.error){ if (configFile.error){
const message = ts.formatDiagnosticsWithColorAndContext([configFile.error],ts.createCompilerHost({})) const message = ts.formatDiagnosticsWithColorAndContext([configFile.error],ts.createCompilerHost({}))
console.error(message) console.error(message)
process.exit(1) 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 //START BOT
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config,ts.sys,nodepath.dirname(configPath)) console.log("OT: Compilation Succeeded!")
if (process.argv.includes("--compile-only")) process.exit(0) //exit when only compile is required!
//create program/compiler console.log("OT: Starting Bot!")
const program = ts.createProgram({ require("./dist/src/index.js")
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")
}
+3 -2
View File
@@ -345,6 +345,7 @@ export class ODCheckerTranslationRegister_Default extends ODCheckerTranslationRe
*/ */
export interface ODCheckerFunctionManagerIds_Default { export interface ODCheckerFunctionManagerIds_Default {
"openticket:unused-options":ODCheckerFunction, "openticket:unused-options":ODCheckerFunction,
"openticket:unused-questions":ODCheckerFunction,
"openticket:dropdown-options":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`! * This default class is made for the global variable `openticket.checkers.functions`!
*/ */
export class ODCheckerFunctionManager_Default extends ODCheckerFunctionManager { export class ODCheckerFunctionManager_Default extends ODCheckerFunctionManager {
get<CheckerFunctionId extends keyof ODCheckerManagerIds_Default>(id:CheckerFunctionId): ODCheckerManagerIds_Default[CheckerFunctionId] get<CheckerFunctionId extends keyof ODCheckerFunctionManagerIds_Default>(id:CheckerFunctionId): ODCheckerFunctionManagerIds_Default[CheckerFunctionId]
get(id:ODValidId): ODCheckerFunction|null get(id:ODValidId): ODCheckerFunction|null
get(id:ODValidId): ODCheckerFunction|null { get(id:ODValidId): ODCheckerFunction|null {
return super.get(id) return super.get(id)
} }
remove<CheckerFunctionId extends keyof ODCheckerManagerIds_Default>(id:CheckerFunctionId): ODCheckerManagerIds_Default[CheckerFunctionId] remove<CheckerFunctionId extends keyof ODCheckerFunctionManagerIds_Default>(id:CheckerFunctionId): ODCheckerFunctionManagerIds_Default[CheckerFunctionId]
remove(id:ODValidId): ODCheckerFunction|null remove(id:ODValidId): ODCheckerFunction|null
remove(id:ODValidId): ODCheckerFunction|null { remove(id:ODValidId): ODCheckerFunction|null {
+2
View File
@@ -21,6 +21,8 @@ export interface ODFlagManagerIds_Default {
"openticket:no-plugins":ODFlag, "openticket:no-plugins":ODFlag,
"openticket:soft-plugins":ODFlag, "openticket:soft-plugins":ODFlag,
"openticket:force-slash-update":ODFlag, "openticket:force-slash-update":ODFlag,
"openticket:no-compile":ODFlag,
"openticket:compile-only":ODFlag,
} }
/**## ODFlagManager_Default `default_class` /**## ODFlagManager_Default `default_class`
+11 -3
View File
@@ -1192,12 +1192,20 @@ export class ODCheckerCustomStructure_EmojiString extends ODCheckerStringStructu
const newOptions = options ?? {} const newOptions = options ?? {}
newOptions.custom = (checker,value,locationTrace,locationId,locationDocs) => { newOptions.custom = (checker,value,locationTrace,locationId,locationDocs) => {
const lt = checker.locationTraceDeref(locationTrace) const lt = checker.locationTraceDeref(locationTrace)
if (typeof value != "string") return false 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])|(?:<a?:[^:]*:[0-9]+>))/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)) 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 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)) 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 return false
}else if (!allowCustomDiscordEmoji && /<a?:[^:]*:[0-9]+>/.test(value)){ }else if (!allowCustomDiscordEmoji && /<a?:[^:]*:[0-9]+>/.test(value)){
+1
View File
@@ -12,6 +12,7 @@ export const loadAllConfigCheckers = async () => {
export const loadAllConfigCheckerFunctions = 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-options",defaultUnusedOptionsFunction))
openticket.checkers.functions.add(new api.ODCheckerFunction("openticket:unused-questions",defaultUnusedQuestionsFunction))
openticket.checkers.functions.add(new api.ODCheckerFunction("openticket:dropdown-options",defaultDropdownOptionsFunction)) openticket.checkers.functions.add(new api.ODCheckerFunction("openticket:dropdown-options",defaultDropdownOptionsFunction))
} }
+2
View File
@@ -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: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: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: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",[]))
} }