Open Ticket v4.1.0 Improvements + Minor Additions
Open Ticket v4.1.0 Improvements + Minor Additions
This commit is contained in:
@@ -63,16 +63,6 @@ export class ODId {
|
|||||||
get value(){
|
get value(){
|
||||||
return this.#value
|
return this.#value
|
||||||
}
|
}
|
||||||
/**The source of the id (text before `:`). (e.g. `openticket` for all built-in ids)
|
|
||||||
*
|
|
||||||
* @deprecated Replaced with `getNamespace()` and will be removed in `v4.1.0`.
|
|
||||||
*/
|
|
||||||
source: string
|
|
||||||
/**The identifier of the id (text after `:`).
|
|
||||||
*
|
|
||||||
* @deprecated Replaced with `getIdentifier()` and will be removed in `v4.1.0`.
|
|
||||||
*/
|
|
||||||
identifier: string
|
|
||||||
/**The change listener for the parent `ODManager` of this `ODId`. */
|
/**The change listener for the parent `ODManager` of this `ODId`. */
|
||||||
#change: ((oldId:string,newId:string) => void)|null = null
|
#change: ((oldId:string,newId:string) => void)|null = null
|
||||||
|
|
||||||
@@ -92,21 +82,9 @@ export class ODId {
|
|||||||
|
|
||||||
if (result.length > 0) this.#value = result.join("")
|
if (result.length > 0) this.#value = result.join("")
|
||||||
else throw new ODSystemError("invalid ID at 'new ODID(id: "+id+")'")
|
else throw new ODSystemError("invalid ID at 'new ODID(id: "+id+")'")
|
||||||
|
|
||||||
const splitted = this.#value.split(":")
|
|
||||||
if (splitted.length > 1){
|
|
||||||
this.source = splitted[0]
|
|
||||||
splitted.shift()
|
|
||||||
this.identifier = splitted.join(":")
|
|
||||||
}else{
|
|
||||||
this.identifier = splitted.join(":")
|
|
||||||
this.source = ""
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
//id is ODId
|
//id is ODId
|
||||||
this.#value = id.#value
|
this.#value = id.#value
|
||||||
this.source = id.source
|
|
||||||
this.identifier = id.identifier
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,47 +149,6 @@ export class ODManagerChangeHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**## ODManagerRedirectHelper `class`
|
|
||||||
* @deprecated ### Will be removed in Open Ticket `v4.1.0`!
|
|
||||||
*
|
|
||||||
* This is Open Ticket ticket manager redirect helper.
|
|
||||||
*
|
|
||||||
* It is used to redirect a source to another source when the id isn't found.
|
|
||||||
*
|
|
||||||
* It will be used in **Open Discord** to allow plugins from all projects to work seamlessly!
|
|
||||||
* ## **(❌ SYSTEM ONLY!!)**
|
|
||||||
*/
|
|
||||||
export class ODManagerRedirectHelper {
|
|
||||||
#data: {fromSource:string,toSource:string}[] = []
|
|
||||||
|
|
||||||
/****(❌ SYSTEM ONLY!!)** Add a redirect to this manager. Returns `true` when overwritten. */
|
|
||||||
add(fromSource:string, toSource:string){
|
|
||||||
const index = this.#data.findIndex((data) => data.fromSource === fromSource)
|
|
||||||
if (index > -1){
|
|
||||||
//already exists
|
|
||||||
this.#data[index] = {fromSource,toSource}
|
|
||||||
return true
|
|
||||||
}else{
|
|
||||||
//doesn't exist
|
|
||||||
this.#data.push({fromSource,toSource})
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/****(❌ SYSTEM ONLY!!)** Remove a redirect from this manager. Returns `true` when it existed. */
|
|
||||||
remove(fromSource:string, toSource:string){
|
|
||||||
const index = this.#data.findIndex((data) => data.fromSource === fromSource && data.toSource == toSource)
|
|
||||||
if (index > -1){
|
|
||||||
//already exists
|
|
||||||
this.#data.splice(index,1)
|
|
||||||
return true
|
|
||||||
}else return false
|
|
||||||
}
|
|
||||||
/**List all redirects from this manager. */
|
|
||||||
list(){
|
|
||||||
return [...this.#data]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**## ODManagerData `class`
|
/**## ODManagerData `class`
|
||||||
* This is Open Ticket manager data.
|
* This is Open Ticket manager data.
|
||||||
*
|
*
|
||||||
@@ -261,11 +198,9 @@ export class ODManager<DataType extends ODManagerData> extends ODManagerChangeHe
|
|||||||
#changeListeners: ODManagerCallback<DataType>[] = []
|
#changeListeners: ODManagerCallback<DataType>[] = []
|
||||||
/**An array storing all listeners when data is removed. */
|
/**An array storing all listeners when data is removed. */
|
||||||
#removeListeners: ODManagerCallback<DataType>[] = []
|
#removeListeners: ODManagerCallback<DataType>[] = []
|
||||||
/**Handle all redirects in this `ODManager` */
|
|
||||||
redirects: ODManagerRedirectHelper = new ODManagerRedirectHelper()
|
|
||||||
|
|
||||||
constructor(debug?:ODDebugger, debugname?:string){
|
constructor(debug?:ODDebugger, debugname?:string){
|
||||||
super()
|
super()
|
||||||
this.#debug = debug
|
this.#debug = debug
|
||||||
this.#debugname = debugname
|
this.#debugname = debugname
|
||||||
}
|
}
|
||||||
@@ -333,15 +268,7 @@ export class ODManager<DataType extends ODManagerData> extends ODManagerChangeHe
|
|||||||
const newId = new ODId(id)
|
const newId = new ODId(id)
|
||||||
const data = this.#data.get(newId.value)
|
const data = this.#data.get(newId.value)
|
||||||
if (data) return data
|
if (data) return data
|
||||||
else{
|
else return null
|
||||||
//DEPRECATED!!!
|
|
||||||
const redirect = this.redirects.list().find((redirect) => redirect.fromSource === newId.getNamespace())
|
|
||||||
if (!redirect) return null
|
|
||||||
else{
|
|
||||||
const redirectId = new ODId(redirect.toSource+":"+newId.getIdentifier())
|
|
||||||
return this.get(redirectId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**Remove data that matches the `ODId`. Returns the removed data. */
|
/**Remove data that matches the `ODId`. Returns the removed data. */
|
||||||
remove(id:ODValidId): DataType|null {
|
remove(id:ODValidId): DataType|null {
|
||||||
@@ -349,15 +276,8 @@ export class ODManager<DataType extends ODManagerData> extends ODManagerChangeHe
|
|||||||
const data = this.#data.get(newId.value)
|
const data = this.#data.get(newId.value)
|
||||||
|
|
||||||
if (!data){
|
if (!data){
|
||||||
//DEPRECATED!!!
|
if (this.#debug) this.#debug.debug("Removed "+this.#debugname+" from manager",[{key:"id",value:newId.value},{key:"found",value:"false"}])
|
||||||
const redirect = this.redirects.list().find((redirect) => redirect.fromSource === newId.getNamespace())
|
return null
|
||||||
if (!redirect){
|
|
||||||
if (this.#debug) this.#debug.debug("Removed "+this.#debugname+" from manager",[{key:"id",value:newId.value},{key:"found",value:"false"}])
|
|
||||||
return null
|
|
||||||
}else{
|
|
||||||
const redirectId = new ODId(redirect.toSource+":"+newId.getIdentifier())
|
|
||||||
return this.remove(redirectId)
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
this.#data.delete(newId.value)
|
this.#data.delete(newId.value)
|
||||||
if (this.#debug) this.#debug.debug("Removed "+this.#debugname+" from manager",[{key:"id",value:newId.value},{key:"found",value:"true"}])
|
if (this.#debug) this.#debug.debug("Removed "+this.#debugname+" from manager",[{key:"id",value:newId.value},{key:"found",value:"true"}])
|
||||||
@@ -385,15 +305,7 @@ export class ODManager<DataType extends ODManagerData> extends ODManagerChangeHe
|
|||||||
exists(id:ODValidId): boolean {
|
exists(id:ODValidId): boolean {
|
||||||
const newId = new ODId(id)
|
const newId = new ODId(id)
|
||||||
if (this.#data.has(newId.value)) return true
|
if (this.#data.has(newId.value)) return true
|
||||||
else{
|
else return false
|
||||||
//DEPRECATED!!!
|
|
||||||
const redirect = this.redirects.list().find((redirect) => redirect.fromSource === newId.getNamespace())
|
|
||||||
if (!redirect) return false
|
|
||||||
else{
|
|
||||||
const redirectId = new ODId(redirect.toSource+":"+newId.getIdentifier())
|
|
||||||
return this.exists(redirectId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**Get all data inside this manager*/
|
/**Get all data inside this manager*/
|
||||||
getAll(): DataType[] {
|
getAll(): DataType[] {
|
||||||
|
|||||||
@@ -332,6 +332,17 @@ export class ODChecker extends ODManagerData {
|
|||||||
this.options = options ?? {}
|
this.options = options ?? {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**Get a human-readable number string. */
|
||||||
|
#ordinalNumber(num:number){
|
||||||
|
const i = Math.abs(Math.round(num))
|
||||||
|
const cent = i % 100
|
||||||
|
if (cent >= 10 && cent <= 20) return i+'th'
|
||||||
|
const dec = i % 10
|
||||||
|
if (dec === 1) return i+'st'
|
||||||
|
if (dec === 2) return i+'nd'
|
||||||
|
if (dec === 3) return i+'rd'
|
||||||
|
return i+'th'
|
||||||
|
}
|
||||||
/**Run this checker. Returns all errors*/
|
/**Run this checker. Returns all errors*/
|
||||||
check(): ODCheckerResult {
|
check(): ODCheckerResult {
|
||||||
this.messages = []
|
this.messages = []
|
||||||
@@ -343,12 +354,12 @@ export class ODChecker extends ODManagerData {
|
|||||||
messages:this.messages
|
messages:this.messages
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**Create a string from the location trace (path)*/
|
/**Create a string from the location trace/path in a human readable format. */
|
||||||
locationTraceToString(trace:ODCheckerLocationTrace){
|
locationTraceToString(trace:ODCheckerLocationTrace){
|
||||||
const final: ODCheckerLocationTrace = []
|
const final: ODCheckerLocationTrace = []
|
||||||
trace.forEach((t) => {
|
trace.forEach((t) => {
|
||||||
if (typeof t == "number"){
|
if (typeof t == "number"){
|
||||||
final.push(`:${t}`)
|
final.push(`:(${this.#ordinalNumber(t+1)})`)
|
||||||
}else{
|
}else{
|
||||||
final.push(`."${t}"`)
|
final.push(`."${t}"`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -516,8 +516,6 @@ export interface ODSlashCommandUniversalCommand {
|
|||||||
* The builder for slash commands. Here you can add options to the command.
|
* The builder for slash commands. Here you can add options to the command.
|
||||||
*/
|
*/
|
||||||
export interface ODSlashCommandBuilder extends discord.ChatInputApplicationCommandData {
|
export interface ODSlashCommandBuilder extends discord.ChatInputApplicationCommandData {
|
||||||
/**@deprecated `dmPermission` is deprecated. Use `context` instead! (Not using contexts might result in the slash command being re-registered on every startup!) */
|
|
||||||
dmPermission?:boolean
|
|
||||||
/**This field is required in Open Ticket for future compatibility. */
|
/**This field is required in Open Ticket for future compatibility. */
|
||||||
integrationTypes:discord.ApplicationIntegrationType[],
|
integrationTypes:discord.ApplicationIntegrationType[],
|
||||||
/**This field is required in Open Ticket for future compatibility. */
|
/**This field is required in Open Ticket for future compatibility. */
|
||||||
|
|||||||
@@ -7,30 +7,6 @@ import nodepath from "path"
|
|||||||
import { ODDebugger } from "./console"
|
import { ODDebugger } from "./console"
|
||||||
import * as fjs from "formatted-json-stringify"
|
import * as fjs from "formatted-json-stringify"
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////
|
|
||||||
//TEMPORARY OPENTICKET => OPENDISCORD MIGRATION UTILITIES
|
|
||||||
/////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
/** ## ❌ Temporary function. Will be removed on full OTv4 release! */
|
|
||||||
export function TEMP_migrateDatabaseIdPrefix(id:string): string {
|
|
||||||
if (!id.startsWith("openticket:")) return id
|
|
||||||
return id.replaceAll("openticket:","opendiscord:")
|
|
||||||
}
|
|
||||||
/** ## ❌ Temporary function. Will be removed on full OTv4 release! */
|
|
||||||
export function TEMP_migrateDatabaseValuePrefix(value:string): string {
|
|
||||||
return value.replaceAll('"openticket:','"opendiscord:')
|
|
||||||
}
|
|
||||||
/** ## ❌ Temporary function. Will be removed on full OTv4 release! */
|
|
||||||
export function TEMP_migrateDatabaseStructurePrefix(structure:ODJsonDatabaseStructure): ODJsonDatabaseStructure {
|
|
||||||
return structure.map((data) => {
|
|
||||||
return {
|
|
||||||
category:TEMP_migrateDatabaseIdPrefix(data.category),
|
|
||||||
key:TEMP_migrateDatabaseIdPrefix(data.key),
|
|
||||||
value:JSON.parse(TEMP_migrateDatabaseValuePrefix(JSON.stringify(data.value)))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**## ODDatabaseManager `class`
|
/**## ODDatabaseManager `class`
|
||||||
* This is an Open Ticket database manager.
|
* This is an Open Ticket database manager.
|
||||||
*
|
*
|
||||||
@@ -118,10 +94,7 @@ export class ODJsonDatabase extends ODDatabase {
|
|||||||
|
|
||||||
/**Init the database. */
|
/**Init the database. */
|
||||||
init(): ODPromiseVoid {
|
init(): ODPromiseVoid {
|
||||||
//this.#system.getData()
|
this.#system.getData()
|
||||||
//TEMPORARY!!!
|
|
||||||
const newData = TEMP_migrateDatabaseStructurePrefix(this.#system.getData())
|
|
||||||
this.#system.setData(newData)
|
|
||||||
}
|
}
|
||||||
/**Set/overwrite the value of `category` & `key`. Returns `true` when overwritten!
|
/**Set/overwrite the value of `category` & `key`. Returns `true` when overwritten!
|
||||||
* @example
|
* @example
|
||||||
@@ -226,10 +199,7 @@ export class ODFormattedJsonDatabase extends ODDatabase {
|
|||||||
|
|
||||||
/**Init the database. */
|
/**Init the database. */
|
||||||
init(): ODPromiseVoid {
|
init(): ODPromiseVoid {
|
||||||
//this.#system.getData()
|
this.#system.getData()
|
||||||
//TEMPORARY!!!
|
|
||||||
const newData = TEMP_migrateDatabaseStructurePrefix(this.#system.getData())
|
|
||||||
this.#system.setData(newData)
|
|
||||||
}
|
}
|
||||||
/**Set/overwrite the value of `category` & `key`. Returns `true` when overwritten!
|
/**Set/overwrite the value of `category` & `key`. Returns `true` when overwritten!
|
||||||
* @example
|
* @example
|
||||||
|
|||||||
@@ -117,7 +117,11 @@ export interface ODUtilities {
|
|||||||
*
|
*
|
||||||
* It shouldn't be used by plugins because this is an internal API feature!
|
* It shouldn't be used by plugins because this is an internal API feature!
|
||||||
*/
|
*/
|
||||||
ODVersionMigration:new (version:api.ODVersion,func:() => void|Promise<void>,afterInitFunc:() => void|Promise<void>) => ODVersionMigration
|
ODVersionMigration:new (version:api.ODVersion,func:() => void|Promise<void>,afterInitFunc:() => void|Promise<void>) => ODVersionMigration,
|
||||||
|
/**## ordinalNumber `utility function`
|
||||||
|
* Get a human readable ordinal number (e.g. 1st, 2nd, 3rd, 4th, ...) from a Javascript number.
|
||||||
|
*/
|
||||||
|
ordinalNumber(num:number): string,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**## ODVersionMigration `utility class`
|
/**## ODVersionMigration `utility class`
|
||||||
@@ -252,5 +256,15 @@ export const utilities: ODUtilities = {
|
|||||||
"LOREMIPSUM", //TODO
|
"LOREMIPSUM", //TODO
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
ODVersionMigration
|
ODVersionMigration,
|
||||||
|
ordinalNumber(num:number){
|
||||||
|
const i = Math.abs(Math.round(num))
|
||||||
|
const cent = i % 100
|
||||||
|
if (cent >= 10 && cent <= 20) return i+'th'
|
||||||
|
const dec = i % 10
|
||||||
|
if (dec === 1) return i+'st'
|
||||||
|
if (dec === 2) return i+'nd'
|
||||||
|
if (dec === 3) return i+'rd'
|
||||||
|
return i+'th'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user