Added new API comments (part 10)

This commit is contained in:
JasperAtSchool
2025-01-28 14:16:43 +01:00
parent 5e1cfe7942
commit 58fb7b7512
9 changed files with 266 additions and 38 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ export const registerActions = async () => {
}
//update roles of user
const result: api.OTRoleUpdateResult[] = []
const result: api.ODRoleUpdateResult[] = []
for (const r of roles){
try{
if (r.members.has(user.id) && (mode == "add&remove" || mode == "remove")){
+3 -3
View File
@@ -9,7 +9,7 @@ import { ODRoleOption, ODTicketOption } from "../openticket/option"
import { ODTicket, ODTicketClearFilter } from "../openticket/ticket"
import { ODTranscriptCompiler, ODTranscriptCompilerCompileResult } from "../openticket/transcript"
import { ODMessageBuildSentResult } from "../modules/builder"
import { ODRole, OTRoleUpdateMode, OTRoleUpdateResult } from "../openticket/role"
import { ODRole, ODRoleUpdateMode, ODRoleUpdateResult } from "../openticket/role"
/**## ODActionManagerIds_Default `interface`
* This interface is a list of ids available in the `ODActionManager_Default` class.
@@ -102,8 +102,8 @@ export interface ODActionManagerIds_Default {
},
"openticket:reaction-role":{
source:"panel-button"|"other",
params:{guild:discord.Guild,user:discord.User,option:ODRoleOption,overwriteMode:OTRoleUpdateMode|null},
result:{result:OTRoleUpdateResult[],role:ODRole},
params:{guild:discord.Guild,user:discord.User,option:ODRoleOption,overwriteMode:ODRoleUpdateMode|null},
result:{result:ODRoleUpdateResult[],role:ODRole},
workers:"openticket:reaction-role"|"openticket:logs"
},
"openticket:clear-tickets":{
+3 -3
View File
@@ -12,7 +12,7 @@ import { ODRoleOption, ODTicketOption, ODWebsiteOption } from "../openticket/opt
import { ODVerifyBar } from "../modules/verifybar"
import * as discord from "discord.js"
import { ODTranscriptCompiler, ODTranscriptCompilerCompileResult } from "../openticket/transcript"
import { ODRole, OTRoleUpdateResult } from "../openticket/role"
import { ODRole, ODRoleUpdateResult } from "../openticket/role"
/**## ODBuilderManager_Default `default_class`
* This is a special class that adds type definitions & typescript to the ODBuilderManager class.
@@ -280,7 +280,7 @@ export interface ODEmbedManagerIds_Default {
"openticket:transcript-html-progress":{source:"channel"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,compiler:ODTranscriptCompiler<{url:string}>,remaining:number},workers:"openticket:transcript-html-progress"},
"openticket:transcript-error":{source:"slash"|"text"|"ticket-message"|"reopen-message"|"close-message"|"autoclose-message"|"autodelete"|"clear"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,compiler:ODTranscriptCompiler<any>,reason:string|null},workers:"openticket:transcript-error"},
"openticket:reaction-role":{source:"panel-button"|"other",params:{guild:discord.Guild,user:discord.User,role:ODRole,result:OTRoleUpdateResult[]},workers:"openticket:reaction-role"},
"openticket:reaction-role":{source:"panel-button"|"other",params:{guild:discord.Guild,user:discord.User,role:ODRole,result:ODRoleUpdateResult[]},workers:"openticket:reaction-role"},
"openticket:clear-verify-message":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,filter:ODTicketClearFilter,list:string[]},workers:"openticket:clear-verify-message"},
"openticket:clear-message":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,filter:ODTicketClearFilter,list:string[]},workers:"openticket:clear-message"},
"openticket:clear-logs":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,filter:ODTicketClearFilter,list:string[]},workers:"openticket:clear-logs"},
@@ -411,7 +411,7 @@ export interface ODMessageManagerIds_Default {
"openticket:transcript-html-progress":{source:"channel"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,compiler:ODTranscriptCompiler<{url:string}>,remaining:number},workers:"openticket:transcript-html-progress"},
"openticket:transcript-error":{source:"slash"|"text"|"ticket-message"|"reopen-message"|"close-message"|"autoclose-message"|"autodelete"|"clear"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,compiler:ODTranscriptCompiler<any>,reason:string|null},workers:"openticket:transcript-error"},
"openticket:reaction-role":{source:"panel-button"|"other",params:{guild:discord.Guild,user:discord.User,role:ODRole,result:OTRoleUpdateResult[]},workers:"openticket:reaction-role"},
"openticket:reaction-role":{source:"panel-button"|"other",params:{guild:discord.Guild,user:discord.User,role:ODRole,result:ODRoleUpdateResult[]},workers:"openticket:reaction-role"},
"openticket:clear-verify-message":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,filter:ODTicketClearFilter,list:string[]},workers:"openticket:clear-verify-message"},
"openticket:clear-message":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,filter:ODTicketClearFilter,list:string[]},workers:"openticket:clear-message"},
"openticket:clear-logs":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,filter:ODTicketClearFilter,list:string[]},workers:"openticket:clear-logs"},
+2 -2
View File
@@ -5,7 +5,7 @@ import { ODValidButtonColor, ODValidId } from "../modules/base"
import * as discord from "discord.js"
import { ODConfigManager, ODConfig, ODJsonConfig } from "../modules/config"
import { ODClientActivityStatus, ODClientActivityType } from "../modules/client"
import { OTRoleUpdateMode } from "../openticket/role"
import { ODRoleUpdateMode } from "../openticket/role"
/**## ODConfigManagerIds_Default `interface`
* This interface is a list of ids available in the `ODConfigManager_Default` class.
@@ -405,7 +405,7 @@ export interface ODJsonConfig_DefaultOptionRoleType extends ODJsonConfig_Default
/**All roles which will be affected by this button. */
roles:string[],
/**The mode determines what will happen with the affected roles on the user. */
mode:OTRoleUpdateMode,
mode:ODRoleUpdateMode,
/**A list of roles to remove from the user when given at least one of the affected roles. */
removeRolesOnAdd:string[],
/**Automatically add these roles when the user joins the server. */
+51 -4
View File
@@ -7,7 +7,7 @@ import { ODId, ODManager, ODValidJsonType, ODValidId, ODVersion, ODValidButtonCo
import { ODDebugger } from "../modules/console"
import * as discord from "discord.js"
import * as crypto from "crypto"
import { OTRoleUpdateMode } from "./role"
import { ODRoleUpdateMode } from "./role"
/**## ODOptionManager `class`
* This is an open ticket option manager.
@@ -106,7 +106,7 @@ export class ODOption extends ODManager<ODOptionData<ODValidJsonType>> {
/**## ODOptionData `class`
* This is open ticket option data.
*
* This class contains a single property for a ticket option. (string, number, boolean, object, array, null)
* This class contains a single property for an option. (string, number, boolean, object, array, null)
*
* When this property is edited, the database will be updated automatically.
*/
@@ -292,7 +292,7 @@ export interface ODRoleOptionIds {
"openticket:button-color":ODOptionData<ODValidButtonColor>,
"openticket:roles":ODOptionData<string[]>,
"openticket:mode":ODOptionData<OTRoleUpdateMode>,
"openticket:mode":ODOptionData<ODRoleUpdateMode>,
"openticket:remove-roles-on-add":ODOptionData<string[]>,
"openticket:add-on-join":ODOptionData<boolean>
}
@@ -379,18 +379,39 @@ export class ODOptionSuffix extends ODManagerData {
}
}
/**## ODOptionUserNameSuffix `class`
* This is an open ticket user-name option suffix.
*
* This class can generate a user-name suffix for a discord channel name from a specific option.
*
* Use `getSuffix()` to get the new suffix!
*/
export class ODOptionUserNameSuffix extends ODOptionSuffix {
getSuffix(user:discord.User): string {
return user.username
}
}
/**## ODOptionUserIdSuffix `class`
* This is an open ticket user-id option suffix.
*
* This class can generate a user-id suffix for a discord channel name from a specific option.
*
* Use `getSuffix()` to get the new suffix!
*/
export class ODOptionUserIdSuffix extends ODOptionSuffix {
getSuffix(user:discord.User): string {
return user.id
}
}
/**## ODOptionCounterDynamicSuffix `class`
* This is an open ticket counter-dynamic option suffix.
*
* This class can generate a counter-dynamic suffix for a discord channel name from a specific option.
*
* Use `getSuffix()` to get the new suffix!
*/
export class ODOptionCounterDynamicSuffix extends ODOptionSuffix {
/**The database where the value of this counter is stored. */
database: ODDatabase
@@ -401,6 +422,7 @@ export class ODOptionCounterDynamicSuffix extends ODOptionSuffix {
this.#init()
}
/**Initialize the database for this suffix. */
async #init(){
if (!await this.database.exists("openticket:option-suffix-counter",this.option.id.value)) await this.database.set("openticket:option-suffix-counter",this.option.id.value,0)
}
@@ -413,6 +435,13 @@ export class ODOptionCounterDynamicSuffix extends ODOptionSuffix {
}
}
/**## ODOptionCounterFixedSuffix `class`
* This is an open ticket counter-fixed option suffix.
*
* This class can generate a counter-fixed suffix for a discord channel name from a specific option.
*
* Use `getSuffix()` to get the new suffix!
*/
export class ODOptionCounterFixedSuffix extends ODOptionSuffix {
/**The database where the value of this counter is stored. */
database: ODDatabase
@@ -423,6 +452,7 @@ export class ODOptionCounterFixedSuffix extends ODOptionSuffix {
this.#init()
}
/**Initialize the database for this suffix. */
async #init(){
if (!await this.database.exists("openticket:option-suffix-counter",this.option.id.value)) await this.database.set("openticket:option-suffix-counter",this.option.id.value,0)
}
@@ -439,6 +469,13 @@ export class ODOptionCounterFixedSuffix extends ODOptionSuffix {
}
}
/**## ODOptionRandomNumberSuffix `class`
* This is an open ticket random-number option suffix.
*
* This class can generate a random-number suffix for a discord channel name from a specific option.
*
* Use `getSuffix()` to get the new suffix!
*/
export class ODOptionRandomNumberSuffix extends ODOptionSuffix {
/**The database where previous random numbers are stored. */
database: ODDatabase
@@ -449,9 +486,11 @@ export class ODOptionRandomNumberSuffix extends ODOptionSuffix {
this.#init()
}
/**Initialize the database for this suffix. */
async #init(){
if (!await this.database.exists("openticket:option-suffix-history",this.option.id.value)) await this.database.set("openticket:option-suffix-history",this.option.id.value,[])
}
/**Get a unique number for this suffix. */
#generateUniqueValue(history:string[]): string {
const rawNumber = Math.round(Math.random()*1000).toString()
let number = rawNumber
@@ -473,6 +512,13 @@ export class ODOptionRandomNumberSuffix extends ODOptionSuffix {
}
}
/**## ODOptionRandomHexSuffix `class`
* This is an open ticket random-hex option suffix.
*
* This class can generate a random-hex suffix for a discord channel name from a specific option.
*
* Use `getSuffix()` to get the new suffix!
*/
export class ODOptionRandomHexSuffix extends ODOptionSuffix {
/**The database where previous random hexes are stored. */
database: ODDatabase
@@ -483,10 +529,11 @@ export class ODOptionRandomHexSuffix extends ODOptionSuffix {
this.#init()
}
/**Initialize the database for this suffix. */
async #init(){
if (!await this.database.exists("openticket:option-suffix-history",this.option.id.value)) await this.database.set("openticket:option-suffix-history",this.option.id.value,[])
}
/**Get a unique hex-string for this suffix. */
#generateUniqueValue(history:string[]): string {
const hex = crypto.randomBytes(2).toString("hex")
if (history.includes(hex)) return this.#generateUniqueValue(history)
+36
View File
@@ -5,7 +5,15 @@ import { ODJsonConfig_DefaultPanelEmbedSettingsType } from "../defaults/config"
import { ODId, ODManager, ODValidJsonType, ODValidId, ODVersion, ODValidButtonColor, ODManagerData } from "../modules/base"
import { ODDebugger } from "../modules/console"
/**## ODPanelManager `class`
* This is an open ticket panel manager.
*
* This class manages all registered panels in the bot. Only panels which are available in this manager can be auto-updated.
*
* Panels are not stored in the database and will be parsed from the config every startup.
*/
export class ODPanelManager extends ODManager<ODPanel> {
/**A reference to the Open Ticket debugger. */
#debug: ODDebugger
constructor(debug:ODDebugger){
@@ -19,14 +27,25 @@ export class ODPanelManager extends ODManager<ODPanel> {
}
}
/**## ODPanelDataJson `interface`
* The JSON representatation from a single panel property.
*/
export interface ODPanelDataJson {
/**The id of this property. */
id:string,
/**The value of this property. */
value:ODValidJsonType
}
/**## ODPanelDataJson `interface`
* The JSON representatation from a single panel.
*/
export interface ODPanelJson {
/**The id of this panel. */
id:string,
/**The version of Open Ticket used to create this panel. */
version:string,
/**The full list of properties/variables related to this panel. */
data:ODPanelDataJson[]
}
@@ -54,7 +73,13 @@ export interface ODPanelIds {
"openticket:describe-options-in-embed-description":ODPanelData<boolean>
}
/**## ODPanel `class`
* This is an open ticket panel.
*
* This class contains all data related to this panel (parsed from the config).
*/
export class ODPanel extends ODManager<ODPanelData<ODValidJsonType>> {
/**The id of this panel. (from the config) */
id:ODId
constructor(id:ODValidId, data:ODPanelData<ODValidJsonType>[]){
@@ -65,6 +90,7 @@ export class ODPanel extends ODManager<ODPanelData<ODValidJsonType>> {
})
}
/**Convert this panel to a JSON object for storing this panel in the database. */
toJson(version:ODVersion): ODPanelJson {
const data = this.getAll().map((data) => {
return {
@@ -80,6 +106,7 @@ export class ODPanel extends ODManager<ODPanelData<ODValidJsonType>> {
}
}
/**Create a panel from a JSON object in the database. */
static fromJson(json:ODPanelJson): ODPanel {
return new ODPanel(json.id,json.data.map((data) => new ODPanelData(data.id,data.value)))
}
@@ -106,7 +133,15 @@ export class ODPanel extends ODManager<ODPanelData<ODValidJsonType>> {
}
}
/**## ODPanelData `class`
* This is open ticket panel data.
*
* This class contains a single property for a panel. (string, number, boolean, object, array, null)
*
* When this property is edited, the database will be updated automatically.
*/
export class ODPanelData<DataType extends ODValidJsonType> extends ODManagerData {
/**The value of this property. */
#value: DataType
constructor(id:ODValidId, value:DataType){
@@ -114,6 +149,7 @@ export class ODPanelData<DataType extends ODValidJsonType> extends ODManagerData
this.#value = value
}
/**The value of this property. */
set value(value:DataType){
this.#value = value
this._change()
+54
View File
@@ -4,7 +4,15 @@
import { ODId, ODManager, ODValidJsonType, ODValidId, ODVersion, ODManagerData } from "../modules/base"
import { ODDebugger } from "../modules/console"
/**## ODQuestionManager `class`
* This is an open ticket question manager.
*
* This class manages all registered questions in the bot. Only questions which are available in this manager can be used in options.
*
* Questions are not stored in the database and will be parsed from the config every startup.
*/
export class ODQuestionManager extends ODManager<ODQuestion> {
/**A reference to the Open Ticket debugger. */
#debug: ODDebugger
constructor(debug:ODDebugger){
@@ -18,20 +26,41 @@ export class ODQuestionManager extends ODManager<ODQuestion> {
}
}
/**## ODQuestionDataJson `interface`
* The JSON representatation from a single question property.
*/
export interface ODQuestionDataJson {
/**The id of this property. */
id:string,
/**The value of this property. */
value:ODValidJsonType
}
/**## ODQuestionDataJson `interface`
* The JSON representatation from a single question.
*/
export interface ODQuestionJson {
/**The id of this question. */
id:string,
/**The type of this question. */
type:string,
/**The version of Open Ticket used to create this question. */
version:string,
/**The full list of properties/variables related to this question. */
data:ODQuestionDataJson[]
}
/**## ODQuestion `class`
* This is an open ticket question.
*
* This class contains all data related to this question (parsed from the config).
*
* Use `ODShortQuestion` or `ODParagraphQuestion` instead!
*/
export class ODQuestion extends ODManager<ODQuestionData<ODValidJsonType>> {
/**The id of this question. (from the config) */
id:ODId
/**The type of this question (e.g. `openticket:short` or `openticket:paragraph`) */
type: string
constructor(id:ODValidId, type:string, data:ODQuestionData<ODValidJsonType>[]){
@@ -43,6 +72,7 @@ export class ODQuestion extends ODManager<ODQuestionData<ODValidJsonType>> {
})
}
/**Convert this question to a JSON object for storing this question in the database. */
toJson(version:ODVersion): ODQuestionJson {
const data = this.getAll().map((data) => {
return {
@@ -59,12 +89,21 @@ export class ODQuestion extends ODManager<ODQuestionData<ODValidJsonType>> {
}
}
/**Create a question from a JSON object in the database. */
static fromJson(json:ODQuestionJson): ODQuestion {
return new ODQuestion(json.id,json.type,json.data.map((data) => new ODQuestionData(data.id,data.value)))
}
}
/**## ODQuestionData `class`
* This is open ticket question data.
*
* This class contains a single property for a question. (string, number, boolean, object, array, null)
*
* When this property is edited, the database will be updated automatically.
*/
export class ODQuestionData<DataType extends ODValidJsonType> extends ODManagerData {
/**The value of this property. */
#value: DataType
constructor(id:ODValidId, value:DataType){
@@ -72,6 +111,7 @@ export class ODQuestionData<DataType extends ODValidJsonType> extends ODManagerD
this.#value = value
}
/**The value of this property. */
set value(value:DataType){
this.#value = value
this._change()
@@ -99,6 +139,13 @@ export interface ODShortQuestionIds {
"openticket:length-max":ODQuestionData<number>
}
/**## ODShortQuestion `class`
* This is an open ticket short question.
*
* This class contains all data related to an Open Ticket short question (parsed from the config).
*
* Use this question in an option to add a short text field to the modal!
*/
export class ODShortQuestion extends ODQuestion {
type: "openticket:short" = "openticket:short"
@@ -146,6 +193,13 @@ export interface ODParagraphQuestionIds {
"openticket:length-max":ODQuestionData<number>
}
/**## ODParagraphQuestion `class`
* This is an open ticket paragraph question.
*
* This class contains all data related to an Open Ticket paragraph question (parsed from the config).
*
* Use this question in an option to add a paragraph text field to the modal!
*/
export class ODParagraphQuestion extends ODQuestion {
type: "openticket:paragraph" = "openticket:paragraph"
+70 -24
View File
@@ -5,7 +5,15 @@ import { ODId, ODManager, ODValidJsonType, ODValidId, ODVersion, ODManagerData }
import { ODDebugger } from "../modules/console"
import * as discord from "discord.js"
/**## ODRoleManager `class`
* This is an open ticket role manager.
*
* This class manages all registered reaction roles in the bot.
*
* Roles are not stored in the database and will be parsed from the config every startup.
*/
export class ODRoleManager extends ODManager<ODRole> {
/**A reference to the Open Ticket debugger. */
#debug: ODDebugger
constructor(debug:ODDebugger){
@@ -19,50 +27,48 @@ export class ODRoleManager extends ODManager<ODRole> {
}
}
/**## ODRoleDataJson `interface`
* The JSON representatation from a single role property.
*/
export interface ODRoleDataJson {
/**The id of this property. */
id:string,
/**The value of this property. */
value:ODValidJsonType
}
/**## ODRoleDataJson `interface`
* The JSON representatation from a single role.
*/
export interface ODRoleJson {
/**The id of this role. */
id:string,
/**The version of Open Ticket used to create this role. */
version:string,
/**The full list of properties/variables related to this role. */
data:ODRoleDataJson[]
}
export class ODRoleData<DataType extends ODValidJsonType> extends ODManagerData {
#value: DataType
constructor(id:ODValidId, value:DataType){
super(id)
this.#value = value
}
set value(value:DataType){
this.#value = value
this._change()
}
get value(): DataType {
return this.#value
}
/**Refresh the database. Is only required to be used when updating `ODRoleData` with an object/array as value. */
refreshDatabase(){
this._change()
}
}
/**## ODRoleIds `type`
* This interface is a list of ids available in the `ODRole` class.
* It's used to generate typescript declarations for this class.
*/
export interface ODRoleIds {
"openticket:roles":ODRoleData<string[]>,
"openticket:mode":ODRoleData<OTRoleUpdateMode>,
"openticket:mode":ODRoleData<ODRoleUpdateMode>,
"openticket:remove-roles-on-add":ODRoleData<string[]>,
"openticket:add-on-join":ODRoleData<boolean>
}
/**## ODRole `class`
* This is an open ticket role.
*
* This class contains all data related to this role (parsed from the config).
*
* These properties will be used to handle reaction role options.
*/
export class ODRole extends ODManager<ODRoleData<ODValidJsonType>> {
/**The id of this role. (from the config) */
id:ODId
constructor(id:ODValidId, data:ODRoleData<ODValidJsonType>[]){
@@ -73,6 +79,7 @@ export class ODRole extends ODManager<ODRoleData<ODValidJsonType>> {
})
}
/**Convert this role to a JSON object for storing this role in the database. */
toJson(version:ODVersion): ODRoleJson {
const data = this.getAll().map((data) => {
return {
@@ -88,6 +95,7 @@ export class ODRole extends ODManager<ODRoleData<ODValidJsonType>> {
}
}
/**Create a role from a JSON object in the database. */
static fromJson(json:ODRoleJson): ODRole {
return new ODRole(json.id,json.data.map((data) => new ODRoleData(data.id,data.value)))
}
@@ -114,9 +122,47 @@ export class ODRole extends ODManager<ODRoleData<ODValidJsonType>> {
}
}
export interface OTRoleUpdateResult {
/**## ODRoleData `class`
* This is open ticket role data.
*
* This class contains a single property for a role. (string, number, boolean, object, array, null)
*
* When this property is edited, the database will be updated automatically.
*/
export class ODRoleData<DataType extends ODValidJsonType> extends ODManagerData {
/**The value of this property. */
#value: DataType
constructor(id:ODValidId, value:DataType){
super(id)
this.#value = value
}
/**The value of this property. */
set value(value:DataType){
this.#value = value
this._change()
}
get value(): DataType {
return this.#value
}
/**Refresh the database. Is only required to be used when updating `ODRoleData` with an object/array as value. */
refreshDatabase(){
this._change()
}
}
/**## ODRoleUpdateResult `interface`
* This interface represents the result of a single role when the roles of users are updated.
*/
export interface ODRoleUpdateResult {
/**The role which was affected. */
role:discord.Role,
/**The action which was done. `null` when nothing happend. */
action:"added"|"removed"|null
}
export type OTRoleUpdateMode = "add&remove"|"add"|"remove"
/**## ODRoleUpdateMode `type`
* This is the mode of the reaction role option in the config.
*/
export type ODRoleUpdateMode = "add&remove"|"add"|"remove"
+46 -1
View File
@@ -4,13 +4,22 @@
import { ODId, ODManager, ODValidJsonType, ODValidId, ODVersion, ODManagerData } from "../modules/base"
import { ODDebugger } from "../modules/console"
import { ODClientManager_Default } from "../defaults/client"
import { ODOption, ODOptionJson, ODTicketOption } from "./option"
import { ODTicketOption } from "./option"
import * as discord from "discord.js"
/**## ODTicketManager `class`
* This is an open ticket ticket manager.
*
* This class manages all currently created tickets in the bot.
*
* All tickets which are added, removed or modified in this manager will be updated automatically in the database.
*/
export class ODTicketManager extends ODManager<ODTicket> {
/**A reference to the main server of the bot */
#guild: discord.Guild|null = null
/**A reference to the Open Ticket client manager. */
#client: ODClientManager_Default
/**A reference to the Open Ticket debugger. */
#debug: ODDebugger
constructor(debug:ODDebugger, client:ODClientManager_Default){
@@ -116,15 +125,27 @@ export class ODTicketManager extends ODManager<ODTicket> {
}
}
/**## ODTicketDataJson `interface`
* The JSON representatation from a single ticket property.
*/
export interface ODTicketDataJson {
/**The id of this property. */
id:string,
/**The value of this property. */
value:ODValidJsonType
}
/**## ODTicketDataJson `interface`
* The JSON representatation from a single ticket.
*/
export interface ODTicketJson {
/**The id of this ticket. */
id:string,
/**The option id related to this ticket. */
option:string,
/**The version of Open Ticket used to create this ticket. */
version:string,
/**The full list of properties/variables related to this ticket. */
data:ODTicketDataJson[]
}
@@ -164,8 +185,17 @@ export interface ODTicketIds {
"openticket:answers":ODTicketData<{id:string,name:string,type:"short"|"paragraph",value:string|null}[]>,
}
/**## ODTicket `class`
* This is an Open Ticket ticket.
*
* This class contains all data related to this ticket (parsed from the database).
*
* These properties contain the current state of the ticket & are used by actions like claiming, pinning, closing, ...
*/
export class ODTicket extends ODManager<ODTicketData<ODValidJsonType>> {
/**The id of this ticket. (discord channel id) */
id:ODId
/**The option related to this ticket. */
#option: ODTicketOption
constructor(id:ODValidId, option:ODTicketOption, data:ODTicketData<ODValidJsonType>[]){
@@ -177,6 +207,7 @@ export class ODTicket extends ODManager<ODTicketData<ODValidJsonType>> {
})
}
/**The option related to this ticket. */
set option(option:ODTicketOption){
this.#option = option
this._change()
@@ -185,6 +216,7 @@ export class ODTicket extends ODManager<ODTicketData<ODValidJsonType>> {
return this.#option
}
/**Convert this ticket to a JSON object for storing this ticket in the database. */
toJson(version:ODVersion): ODTicketJson {
const data = this.getAll().map((data) => {
return {
@@ -201,6 +233,7 @@ export class ODTicket extends ODManager<ODTicketData<ODValidJsonType>> {
}
}
/**Create a ticket from a JSON object in the database. */
static fromJson(json:ODTicketJson, option:ODTicketOption): ODTicket {
return new ODTicket(json.id,option,json.data.map((data) => new ODTicketData(data.id,data.value)))
}
@@ -227,7 +260,15 @@ export class ODTicket extends ODManager<ODTicketData<ODValidJsonType>> {
}
}
/**## ODTicketData `class`
* This is open ticket ticket data.
*
* This class contains a single property for a ticket. (string, number, boolean, object, array, null)
*
* When this property is edited, the database will be updated automatically.
*/
export class ODTicketData<DataType extends ODValidJsonType> extends ODManagerData {
/**The value of this property. */
#value: DataType
constructor(id:ODValidId, value:DataType){
@@ -235,6 +276,7 @@ export class ODTicketData<DataType extends ODValidJsonType> extends ODManagerDat
this.#value = value
}
/**The value of this property. */
set value(value:DataType){
this.#value = value
this._change()
@@ -248,4 +290,7 @@ export class ODTicketData<DataType extends ODValidJsonType> extends ODManagerDat
}
}
/**## ODTicketClearFilter `type`
* This type contains all possible "clear filters" for the `/clear` command.
*/
export type ODTicketClearFilter = "all"|"open"|"closed"|"claimed"|"unclaimed"|"pinned"|"unpinned"|"autoclosed"