Added new API comments (part 7)

This commit is contained in:
DJj123dj
2025-01-22 15:13:13 +01:00
parent 09d9b2d265
commit 40bd873a33
4 changed files with 329 additions and 14 deletions
+95
View File
@@ -7,8 +7,17 @@ import { ODFlag } from "./flag"
import { ODPlugin, ODUnknownCrashedPlugin } from "./plugin"
import ansis from "ansis"
/**## ODStartScreenComponentRenderCallback `type`
* This is the render function of a startscreen component. It also sends the location of where the component is rendered.
*/
export type ODStartScreenComponentRenderCallback = (location:number) => string|Promise<string>
/**## ODStartScreenManager `class`
* This is an open ticket startscreen manager.
*
* This class is responsible for managing & rendering the startscreen of the bot.
* The startscreen is the part you see when the bot has started up successfully. (e.g. the Open Ticket logo, logs, livestatus, flags, ...)
*/
export class ODStartScreenManager extends ODManager<ODStartScreenComponent> {
/**Alias to the Open Ticket debugger. */
#debug: ODDebugger
@@ -47,10 +56,22 @@ export class ODStartScreenManager extends ODManager<ODStartScreenComponent> {
}
}
/**## ODStartScreenComponent `class`
* This is an open ticket startscreen component.
*
* This component can be rendered to the start screen of the bot.
* An optional priority can be specified to choose the location of the component.
*
* It's recommended to use pre-built components except if you really need a custom one.
*/
export class ODStartScreenComponent extends ODManagerData {
/**The priority of this component. */
priority: number
/**An optional render function which will be inserted before the default renderer. */
renderBefore: ODStartScreenComponentRenderCallback|null = null
/**The render function which will render the contents of this component. */
render: ODStartScreenComponentRenderCallback
/**An optional render function which will be inserted behind the default renderer. */
renderAfter: ODStartScreenComponentRenderCallback|null = null
constructor(id:ODValidId, priority:number, render:ODStartScreenComponentRenderCallback){
@@ -59,6 +80,7 @@ export class ODStartScreenComponent extends ODManagerData {
this.render = render
}
/**Render this component and combine it with the `renderBefore` & `renderAfter` contents. */
async renderAll(location:number){
const textBefore = (this.renderBefore) ? await this.renderBefore(location) : ""
const text = await this.render(location)
@@ -67,15 +89,30 @@ export class ODStartScreenComponent extends ODManagerData {
}
}
/**## ODStartScreenProperty `type`
* This interface contains properties used in a few default templates of the startscreen component.
*/
export interface ODStartScreenProperty {
/**The key or name of this property. */
key:string,
/**The value or contents of this property. */
value:string
}
/**## ODStartScreenLogoComponent `class`
* This is an open ticket startscreen logo component.
*
* This component will render an ASCII art logo (from an array) to the startscreen. Every property in the array is another row.
* An optional priority can be specified to choose the location of the component.
*/
export class ODStartScreenLogoComponent extends ODStartScreenComponent {
/**The ASCII logo contents. */
logo: string[]
/**When enabled, the component will add a new line above the logo. */
topPadding: boolean
/**When enabled, the component will add a new line below the logo. */
bottomPadding: boolean
/**The color of the logo in hex format. */
logoHexColor: string
constructor(id:ODValidId, priority:number, logo:string[], topPadding?:boolean, bottomPadding?:boolean, logoHexColor?:string){
@@ -92,14 +129,28 @@ export class ODStartScreenLogoComponent extends ODStartScreenComponent {
}
}
/**## ODStartScreenHeaderAlignmentSettings `type`
* This interface contains all settings used in the startscreen header component.
*/
export interface ODStartScreenHeaderAlignmentSettings {
/**The alignment settings for this header. */
align:"center"|"left"|"right",
/**The width or component to use when calculating center & right alignment. */
width:number|ODStartScreenComponent
}
/**## ODStartScreenHeaderComponent `class`
* This is an open ticket startscreen header component.
*
* This component will render a header to the startscreen. Properties can be aligned left, right or centered.
* An optional priority can be specified to choose the location of the component.
*/
export class ODStartScreenHeaderComponent extends ODStartScreenComponent {
/**All properties of this header component. */
properties: ODStartScreenProperty[]
/**The spacer used between properties. */
spacer: string
/**The alignment settings of this header component. */
align: ODStartScreenHeaderAlignmentSettings|null
constructor(id:ODValidId, priority:number, properties:ODStartScreenProperty[], spacer?:string, align?:ODStartScreenHeaderAlignmentSettings){
@@ -140,8 +191,16 @@ export class ODStartScreenHeaderComponent extends ODStartScreenComponent {
}
}
/**## ODStartScreenCategoryComponent `class`
* This is an open ticket startscreen category component.
*
* This component will render a category to the startscreen. This will only render the category name. You'll need to provide your own renderer for the contents.
* An optional priority can be specified to choose the location of the component.
*/
export class ODStartScreenCategoryComponent extends ODStartScreenComponent {
/**The name of this category. */
name: string
/**When enabled, this category will still be rendered when the contents are empty. (enabled by default) */
renderIfEmpty: boolean
constructor(id:ODValidId, priority:number, name:string, render:ODStartScreenComponentRenderCallback, renderIfEmpty?:boolean){
@@ -156,8 +215,16 @@ export class ODStartScreenCategoryComponent extends ODStartScreenComponent {
}
}
/**## ODStartScreenPropertiesCategoryComponent `class`
* This is an open ticket startscreen properties category component.
*
* This component will render a properties category to the startscreen. This will list the properties in the category.
* An optional priority can be specified to choose the location of the component.
*/
export class ODStartScreenPropertiesCategoryComponent extends ODStartScreenCategoryComponent {
/**The properties of this category component. */
properties: ODStartScreenProperty[]
/**The hex color for the key/name of all the properties. */
propertyHexColor: string
constructor(id:ODValidId, priority:number, name:string, properties:ODStartScreenProperty[], propertyHexColor?:string, renderIfEmpty?:boolean){
@@ -170,7 +237,14 @@ export class ODStartScreenPropertiesCategoryComponent extends ODStartScreenCateg
}
}
/**## ODStartScreenFlagsCategoryComponent `class`
* This is an open ticket startscreen flags category component.
*
* This component will render a flags category to the startscreen. This will list the enabled flags in the category.
* An optional priority can be specified to choose the location of the component.
*/
export class ODStartScreenFlagsCategoryComponent extends ODStartScreenCategoryComponent {
/**A list of all flags to render. */
flags: ODFlag[]
constructor(id:ODValidId, priority:number, flags:ODFlag[]){
@@ -181,8 +255,16 @@ export class ODStartScreenFlagsCategoryComponent extends ODStartScreenCategoryCo
}
}
/**## ODStartScreenPluginsCategoryComponent `class`
* This is an open ticket startscreen plugins category component.
*
* This component will render a plugins category to the startscreen. This will list the enabled, disabled & crashed plugins in the category.
* An optional priority can be specified to choose the location of the component.
*/
export class ODStartScreenPluginsCategoryComponent extends ODStartScreenCategoryComponent {
/**A list of all plugins to render. */
plugins: ODPlugin[]
/**A list of all crashed plugins to render. */
unknownCrashedPlugins: ODUnknownCrashedPlugin[]
constructor(id:ODValidId, priority:number, plugins:ODPlugin[], unknownCrashedPlugins:ODUnknownCrashedPlugin[]){
@@ -200,7 +282,14 @@ export class ODStartScreenPluginsCategoryComponent extends ODStartScreenCategory
}
}
/**## ODStartScreenLiveStatusCategoryComponent `class`
* This is an open ticket startscreen livestatus category component.
*
* This component will render a livestatus category to the startscreen. This will list the livestatus messages in the category.
* An optional priority can be specified to choose the location of the component.
*/
export class ODStartScreenLiveStatusCategoryComponent extends ODStartScreenCategoryComponent {
/**A reference to the Open Ticket livestatus manager. */
livestatus: ODLiveStatusManager
constructor(id:ODValidId, priority:number, livestatus:ODLiveStatusManager){
@@ -212,6 +301,12 @@ export class ODStartScreenLiveStatusCategoryComponent extends ODStartScreenCateg
}
}
/**## ODStartScreenLogsCategoryComponent `class`
* This is an open ticket startscreen logs category component.
*
* This component will render a logs category to the startscreen. This will only render the logs category name.
* An optional priority can be specified to choose the location of the component.
*/
export class ODStartScreenLogCategoryComponent extends ODStartScreenCategoryComponent {
constructor(id:ODValidId, priority:number){
super(id,priority,"logs",() => "",true)