Small improvements
This commit is contained in:
@@ -32,6 +32,7 @@ export * from "./defaults/base"
|
||||
export * from "./defaults/event"
|
||||
export * from "./defaults/config"
|
||||
export * from "./defaults/database"
|
||||
export * from "./defaults/plugin"
|
||||
export * from "./defaults/checker"
|
||||
export * from "./defaults/client"
|
||||
export * from "./defaults/language"
|
||||
|
||||
@@ -65,6 +65,7 @@ export class ODCheckerRenderer_Default extends ODCheckerRenderer {
|
||||
horizontalFiller: string = "="
|
||||
verticalFiller: string = "|"
|
||||
descriptionSeparator: string = " => "
|
||||
headerSeparator: string = " => "
|
||||
footerTipPrefix: string = "=> "
|
||||
|
||||
disableHeader: boolean = false
|
||||
@@ -93,7 +94,7 @@ export class ODCheckerRenderer_Default extends ODCheckerRenderer {
|
||||
|
||||
if (!renderEmpty && !hasErrors && !hasWarnings && (!hasInfo || compact)) return []
|
||||
|
||||
const headerText = ansis.bold.hex("#f8ba00")(t.headerOpenticket)+" "+t.headerConfigchecker+" => "+ansis.hex("#f8ba00")(t.headerDescription)
|
||||
const headerText = ansis.bold.hex("#f8ba00")(t.headerOpenticket)+" "+t.headerConfigchecker+this.headerSeparator+ansis.hex("#f8ba00")(t.headerDescription)
|
||||
const footerErrorText = (hasErrors) ? this.footerTipPrefix+ansis.gray(tm.insertTranslationParams(t.footerError,[ansis.bold.red(t.error)])) : ""
|
||||
const footerWarningText = (hasWarnings) ? this.footerTipPrefix+ansis.gray(tm.insertTranslationParams(t.footerWarning,[ansis.bold.yellow(t.warning)])) : ""
|
||||
const footerSupportText = tm.insertTranslationParams(t.footerSupport,[ansis.green("https://discord.dj-dj.be"),ansis.green("https://otdocs.dj-dj.be")])
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
///////////////////////////////////////
|
||||
//BASE MODULES
|
||||
import { ODPromiseVoid, ODValidId } from "../modules/base"
|
||||
import { ODPluginClassManager, ODPluginEventManager, ODPluginManager } from "../modules/plugin"
|
||||
import { ODConsoleManager, ODError } from "../modules/console"
|
||||
import { ODCheckerResult, ODCheckerStorage } from "../modules/checker"
|
||||
import { ODDefaultsManager } from "../modules/defaults"
|
||||
@@ -13,7 +12,7 @@ import { ODEvent, ODEventManager } from "../modules/event"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
//DEFAULT MODULES
|
||||
import { ODVersionManager_Default } from "./base"
|
||||
import { ODPluginClassManager_Default, ODPluginManager_Default } from "./plugin"
|
||||
import { ODConfigManager_Default} from "./config"
|
||||
import { ODDatabaseManager_Default } from "./database"
|
||||
import { ODFlagManager_Default } from "./flag"
|
||||
@@ -53,12 +52,9 @@ export interface ODEventIds_Default {
|
||||
"afterErrorHandling": ODEvent_Default<(error:Error, origin:NodeJS.UncaughtExceptionOrigin, message:ODError) => ODPromiseVoid>
|
||||
|
||||
//plugins
|
||||
"afterPluginsLoaded": ODEvent_Default<(plugins:ODPluginManager) => ODPromiseVoid>
|
||||
"onPluginClassLoad": ODEvent_Default<(classes:ODPluginClassManager, plugins:ODPluginManager) => ODPromiseVoid>
|
||||
"afterPluginClassesLoaded": ODEvent_Default<(classes:ODPluginClassManager, plugins:ODPluginManager) => ODPromiseVoid>
|
||||
"onPluginEventLoad": ODEvent_Default<(classes:ODPluginEventManager, plugins:ODPluginManager) => ODPromiseVoid>
|
||||
"afterPluginEventsLoaded": ODEvent_Default<(classes:ODPluginEventManager, plugins:ODPluginManager) => ODPromiseVoid>
|
||||
|
||||
"afterPluginsLoaded": ODEvent_Default<(plugins:ODPluginManager_Default) => ODPromiseVoid>
|
||||
"onPluginClassLoad": ODEvent_Default<(classes:ODPluginClassManager_Default, plugins:ODPluginManager_Default) => ODPromiseVoid>
|
||||
"afterPluginClassesLoaded": ODEvent_Default<(classes:ODPluginClassManager_Default, plugins:ODPluginManager_Default) => ODPromiseVoid>
|
||||
|
||||
"onFlagLoad": ODEvent_Default<(flags:ODFlagManager_Default) => ODPromiseVoid>
|
||||
"afterFlagsLoaded": ODEvent_Default<(flags:ODFlagManager_Default) => ODPromiseVoid>
|
||||
@@ -277,6 +273,9 @@ export interface ODEventIds_Default {
|
||||
"afterStartScreensLoaded": ODEvent_Default<(startscreen:ODStartScreenManager_Default) => ODPromiseVoid>
|
||||
"onStartScreenRender": ODEvent_Default<(startscreen:ODStartScreenManager_Default) => ODPromiseVoid>
|
||||
"afterStartScreensRendered": ODEvent_Default<(startscreen:ODStartScreenManager_Default) => ODPromiseVoid>
|
||||
|
||||
//ready
|
||||
"onReadyForUsage": ODEvent_Default<() => ODPromiseVoid>
|
||||
}
|
||||
|
||||
/**## ODEventManager_Default `default_class`
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
///////////////////////////////////////
|
||||
//DEFAULT POST MODULE
|
||||
///////////////////////////////////////
|
||||
import { ODValidId, ODManagerData } from "../modules/base"
|
||||
import { ODPlugin, ODPluginClassManager, ODPluginManager } from "../modules/plugin"
|
||||
|
||||
/**## ODPluginManagerIds_Default `type`
|
||||
* This type is an array of ids available in the `ODPluginManager_Default` class.
|
||||
* It's used to generate typescript declarations for this class.
|
||||
*/
|
||||
export interface ODPluginManagerIds_Default {}
|
||||
|
||||
/**## ODPluginManager_Default `default_class`
|
||||
* This is a special class that adds type definitions & typescript to the ODPluginManager class.
|
||||
* It doesn't add any extra features!
|
||||
*
|
||||
* This default class is made for the global variable `openticket.plugins`!
|
||||
*/
|
||||
export class ODPluginManager_Default extends ODPluginManager {
|
||||
declare classes: ODPluginClassManager_Default
|
||||
|
||||
get<PluginId extends keyof ODPluginManagerIds_Default>(id:PluginId): ODPluginManagerIds_Default[PluginId]
|
||||
get(id:ODValidId): ODPlugin|null
|
||||
|
||||
get(id:ODValidId): ODPlugin|null {
|
||||
return super.get(id)
|
||||
}
|
||||
|
||||
remove<PluginId extends keyof ODPluginManagerIds_Default>(id:PluginId): ODPluginManagerIds_Default[PluginId]
|
||||
remove(id:ODValidId): ODPlugin|null
|
||||
|
||||
remove(id:ODValidId): ODPlugin|null {
|
||||
return super.remove(id)
|
||||
}
|
||||
|
||||
exists(id:keyof ODPluginManagerIds_Default): boolean
|
||||
exists(id:ODValidId): boolean
|
||||
|
||||
exists(id:ODValidId): boolean {
|
||||
return super.exists(id)
|
||||
}
|
||||
}
|
||||
|
||||
/**## ODPluginClassManagerIds_Default `type`
|
||||
* This type is an array of ids available in the `ODPluginClassManager_Default` class.
|
||||
* It's used to generate typescript declarations for this class.
|
||||
*/
|
||||
export interface ODPluginClassManagerIds_Default {}
|
||||
|
||||
/**## ODPluginClassManager_Default `default_class`
|
||||
* This is a special class that adds type definitions & typescript to the ODPluginClassManager class.
|
||||
* It doesn't add any extra features!
|
||||
*
|
||||
* This default class is made for the global variable `openticket.plugins.classes`!
|
||||
*/
|
||||
export class ODPluginClassManager_Default extends ODPluginClassManager {
|
||||
get<PluginClassId extends keyof ODPluginClassManagerIds_Default>(id:PluginClassId): ODPluginClassManagerIds_Default[PluginClassId]
|
||||
get(id:ODValidId): ODManagerData|null
|
||||
|
||||
get(id:ODValidId): ODManagerData|null {
|
||||
return super.get(id)
|
||||
}
|
||||
|
||||
remove<PluginClassId extends keyof ODPluginClassManagerIds_Default>(id:PluginClassId): ODPluginClassManagerIds_Default[PluginClassId]
|
||||
remove(id:ODValidId): ODManagerData|null
|
||||
|
||||
remove(id:ODValidId): ODManagerData|null {
|
||||
return super.remove(id)
|
||||
}
|
||||
|
||||
exists(id:keyof ODPluginClassManagerIds_Default): boolean
|
||||
exists(id:ODValidId): boolean
|
||||
|
||||
exists(id:ODValidId): boolean {
|
||||
return super.exists(id)
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
//BASE MODULES
|
||||
import { ODEnvHelper, ODVersion } from "./modules/base"
|
||||
import { ODPluginManager } from "./modules/plugin"
|
||||
import { ODConsoleManager, ODConsoleMessage, ODConsoleMessageParam, ODConsoleMessageTypes, ODDebugFileManager, ODDebugger, ODError } from "./modules/console"
|
||||
import { ODCheckerStorage } from "./modules/checker"
|
||||
import { ODDefaultsManager } from "./modules/defaults"
|
||||
|
||||
//DEFAULT MODULES
|
||||
import { ODVersionManager_Default } from "./defaults/base"
|
||||
import { ODPluginManager_Default } from "./defaults/plugin"
|
||||
import { ODEventManager_Default } from "./defaults/event"
|
||||
import { ODConfigManager_Default} from "./defaults/config"
|
||||
import { ODDatabaseManager_Default } from "./defaults/database"
|
||||
@@ -57,7 +57,7 @@ export class ODMain {
|
||||
events: ODEventManager_Default
|
||||
|
||||
/**The manager that handles & executes all plugins in the bot. */
|
||||
plugins: ODPluginManager
|
||||
plugins: ODPluginManager_Default
|
||||
/**The manager that manages & checks all the console flags of the bot. (like `--debug`) */
|
||||
flags: ODFlagManager_Default
|
||||
/**The manager that manages & contains all the config files of the bot. (like `config/general.json`) */
|
||||
@@ -132,7 +132,7 @@ export class ODMain {
|
||||
this.debug = new ODDebugger(this.console)
|
||||
this.events = new ODEventManager_Default(this.debug)
|
||||
|
||||
this.plugins = new ODPluginManager(this.debug)
|
||||
this.plugins = new ODPluginManager_Default(this.debug)
|
||||
this.flags = new ODFlagManager_Default(this.debug)
|
||||
this.configs = new ODConfigManager_Default(this.debug)
|
||||
this.databases = new ODDatabaseManager_Default(this.debug)
|
||||
|
||||
@@ -367,7 +367,7 @@ export class ODChecker extends ODManagerData {
|
||||
|
||||
type,message,
|
||||
path:this.locationTraceToString(locationTrace),
|
||||
filepath:this.config.file,
|
||||
filepath:this.config.path,
|
||||
translationParams,
|
||||
|
||||
messageDocs:docs,
|
||||
|
||||
@@ -67,8 +67,10 @@ export class ODConfigManager extends ODManager<ODConfig> {
|
||||
* You will only use this class if you want to create your own config implementation (e.g. `yml`, `xml`,...)!
|
||||
*/
|
||||
export class ODConfig extends ODManagerData {
|
||||
/**The full path to this config with extension */
|
||||
/**The name of the file with extension. */
|
||||
file: string = ""
|
||||
/**The path to the file relative to the main directory. */
|
||||
path: string = ""
|
||||
/**An object/array of the entire config file! Variables inside it can be edited while the bot is running! */
|
||||
data: any = undefined
|
||||
}
|
||||
@@ -87,9 +89,9 @@ export class ODJsonConfig extends ODConfig {
|
||||
constructor(id:ODValidId, file:string, customPath?:string){
|
||||
super(id)
|
||||
try {
|
||||
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())
|
||||
this.file = (file.endsWith(".json")) ? file : file+".json"
|
||||
this.path = customPath ? nodepath.join("./",customPath,this.file) : nodepath.join("./config/",this.file)
|
||||
this.data = JSON.parse(fs.readFileSync(this.path).toString())
|
||||
}catch(err){
|
||||
process.emit("uncaughtException",err)
|
||||
throw new ODSystemError("Config \""+nodepath.join("./",customPath ?? "./config/",file)+"\" doesn't exist!")
|
||||
|
||||
@@ -20,8 +20,6 @@ export interface ODDefaults {
|
||||
|
||||
/**Load the default open ticket plugin classes. */
|
||||
pluginClassLoading:boolean,
|
||||
/**Load the default open ticket plugin events. */
|
||||
pluginEventLoading:boolean,
|
||||
|
||||
/**Load the default open ticket flags. */
|
||||
flagLoading:boolean,
|
||||
@@ -225,7 +223,6 @@ export class ODDefaultsManager {
|
||||
softPluginLoading:false,
|
||||
|
||||
pluginClassLoading:true,
|
||||
pluginEventLoading:true,
|
||||
|
||||
flagLoading:true,
|
||||
flagInitiating:true,
|
||||
|
||||
@@ -7,7 +7,10 @@ import { ODDebugger } from "./console"
|
||||
import fs from "fs"
|
||||
|
||||
export class ODLanguage extends ODManagerData {
|
||||
/**The name of the file with `.json` extension. */
|
||||
file: string
|
||||
/**The path to the file relative to the main directory. */
|
||||
path: string
|
||||
data: any
|
||||
metadata: {
|
||||
otversion:string,
|
||||
@@ -19,9 +22,9 @@ export class ODLanguage extends ODManagerData {
|
||||
constructor(id:ODValidId, file:string, customPath?:string){
|
||||
super(id)
|
||||
try{
|
||||
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())
|
||||
this.file = (file.endsWith(".json")) ? file : file+".json"
|
||||
this.path = customPath ? nodepath.join("./",customPath,this.file) : nodepath.join("./languages/",this.file)
|
||||
this.data = JSON.parse(fs.readFileSync(this.path).toString())
|
||||
}catch(err){
|
||||
process.emit("uncaughtException",err)
|
||||
throw new ODSystemError("Language \""+nodepath.join("./",customPath ?? "./languages/",file)+"\" doesn't exist!")
|
||||
|
||||
@@ -11,13 +11,11 @@ export interface ODUnknownCrashedPlugin {
|
||||
}
|
||||
|
||||
export class ODPluginManager extends ODManager<ODPlugin> {
|
||||
events: ODPluginEventManager
|
||||
classes: ODPluginClassManager
|
||||
unknownCrashedPlugins: ODUnknownCrashedPlugin[] = []
|
||||
|
||||
constructor(debug:ODDebugger){
|
||||
super(debug,"plugin")
|
||||
this.events = new ODPluginEventManager(debug)
|
||||
this.classes = new ODPluginClassManager(debug)
|
||||
}
|
||||
|
||||
@@ -147,91 +145,6 @@ export class ODPlugin extends ODManagerData {
|
||||
}
|
||||
}
|
||||
|
||||
export class ODPluginEvent extends ODManagerData {
|
||||
listeners: Function[] = []
|
||||
oncelisteners: Function[] = []
|
||||
|
||||
getCurrentListeners(){
|
||||
const final: Function[] = []
|
||||
this.oncelisteners.forEach((l) => final.push(l))
|
||||
this.listeners.forEach((l) => final.push(l))
|
||||
|
||||
this.oncelisteners = []
|
||||
return final
|
||||
}
|
||||
}
|
||||
|
||||
export class ODPluginEventManager extends ODManager<ODPluginEvent> {
|
||||
#debug: ODDebugger
|
||||
listenerLimit: number = 25
|
||||
|
||||
constructor(debug:ODDebugger){
|
||||
super(debug,"plugin event")
|
||||
this.#debug = debug
|
||||
}
|
||||
|
||||
setListenerLimit(limit:number){
|
||||
this.listenerLimit = limit
|
||||
}
|
||||
|
||||
on(event:string, callback:Function){
|
||||
const eventdata = this.get(event)
|
||||
if (eventdata){
|
||||
eventdata.listeners.push(callback)
|
||||
|
||||
if (eventdata.listeners.length > this.listenerLimit){
|
||||
this.#debug.console.log(new ODConsoleWarningMessage("Possible plugin event memory leak detected!",[
|
||||
{key:"event",value:event},
|
||||
{key:"listeners",value:eventdata.listeners.length.toString()}
|
||||
]))
|
||||
}
|
||||
}else{
|
||||
throw new ODSystemError("unknown plugin event \""+event+"\"")
|
||||
}
|
||||
}
|
||||
|
||||
once(event:string, callback:Function){
|
||||
const eventdata = this.get(event)
|
||||
if (eventdata){
|
||||
eventdata.oncelisteners.push(callback)
|
||||
|
||||
}else{
|
||||
throw new ODSystemError("unknown plugin event \""+event+"\"")
|
||||
}
|
||||
}
|
||||
|
||||
wait(event:string): Promise<any[]> {
|
||||
return new Promise((resolve,reject) => {
|
||||
const eventdata = this.get(event)
|
||||
if (eventdata){
|
||||
eventdata.oncelisteners.push((...args:any) => {resolve(args)})
|
||||
}else{
|
||||
reject("unknown plugin event \""+event+"\"")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
emit(event:string, params:any[]): Promise<void> {
|
||||
return new Promise(async (resolve,reject) => {
|
||||
const eventdata = this.get(event)
|
||||
if (eventdata){
|
||||
const listeners = eventdata.getCurrentListeners()
|
||||
|
||||
for (const listener of listeners){
|
||||
try {
|
||||
await listener(...params)
|
||||
}catch(err){
|
||||
process.emit("uncaughtException",err)
|
||||
}
|
||||
}
|
||||
resolve()
|
||||
}else{
|
||||
reject("unknown plugin event \""+event+"\"")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export class ODPluginClassManager extends ODManager<ODManagerData> {
|
||||
constructor(debug:ODDebugger){
|
||||
super(debug,"plugin class")
|
||||
|
||||
Reference in New Issue
Block a user