Fixed option suffixes with ot-sqlite-database
This commit is contained in:
@@ -20,7 +20,7 @@ export const registerActions = async () => {
|
|||||||
const channelCategory = option.get("opendiscord:channel-category").value
|
const channelCategory = option.get("opendiscord:channel-category").value
|
||||||
const channelBackupCategory = option.get("opendiscord:channel-category-backup").value
|
const channelBackupCategory = option.get("opendiscord:channel-category-backup").value
|
||||||
const channelDescription = option.get("opendiscord:channel-description").value
|
const channelDescription = option.get("opendiscord:channel-description").value
|
||||||
const channelSuffix = opendiscord.options.suffix.getSuffixFromOption(option,user)
|
const channelSuffix = await opendiscord.options.suffix.getSuffixFromOption(option,user)
|
||||||
const channelName = channelPrefix+channelSuffix
|
const channelName = channelPrefix+channelSuffix
|
||||||
|
|
||||||
//handle category
|
//handle category
|
||||||
|
|||||||
@@ -350,10 +350,10 @@ export class ODOptionSuffixManager extends ODManager<ODOptionSuffix> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**Instantly get the suffix from an `ODTicketOption`. */
|
/**Instantly get the suffix from an `ODTicketOption`. */
|
||||||
getSuffixFromOption(option:ODTicketOption,user:discord.User): string|null {
|
async getSuffixFromOption(option:ODTicketOption,user:discord.User): Promise<string|null> {
|
||||||
const suffix = this.getAll().find((suffix) => suffix.option.id.value == option.id.value)
|
const suffix = this.getAll().find((suffix) => suffix.option.id.value == option.id.value)
|
||||||
if (!suffix) return null
|
if (!suffix) return null
|
||||||
return suffix.getSuffix(user)
|
return await suffix.getSuffix(user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,7 +374,7 @@ export class ODOptionSuffix extends ODManagerData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**Get the suffix for a new ticket. */
|
/**Get the suffix for a new ticket. */
|
||||||
getSuffix(user:discord.User): string {
|
async getSuffix(user:discord.User): Promise<string> {
|
||||||
throw new ODSystemError("Tried to use an unimplemented ODOptionSuffix!")
|
throw new ODSystemError("Tried to use an unimplemented ODOptionSuffix!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -387,7 +387,7 @@ export class ODOptionSuffix extends ODManagerData {
|
|||||||
* Use `getSuffix()` to get the new suffix!
|
* Use `getSuffix()` to get the new suffix!
|
||||||
*/
|
*/
|
||||||
export class ODOptionUserNameSuffix extends ODOptionSuffix {
|
export class ODOptionUserNameSuffix extends ODOptionSuffix {
|
||||||
getSuffix(user:discord.User): string {
|
async getSuffix(user:discord.User): Promise<string> {
|
||||||
return user.username
|
return user.username
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -400,7 +400,7 @@ export class ODOptionUserNameSuffix extends ODOptionSuffix {
|
|||||||
* Use `getSuffix()` to get the new suffix!
|
* Use `getSuffix()` to get the new suffix!
|
||||||
*/
|
*/
|
||||||
export class ODOptionUserIdSuffix extends ODOptionSuffix {
|
export class ODOptionUserIdSuffix extends ODOptionSuffix {
|
||||||
getSuffix(user:discord.User): string {
|
async getSuffix(user:discord.User): Promise<string> {
|
||||||
return user.id
|
return user.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -426,11 +426,11 @@ export class ODOptionCounterDynamicSuffix extends ODOptionSuffix {
|
|||||||
async #init(){
|
async #init(){
|
||||||
if (!await this.database.exists("opendiscord:option-suffix-counter",this.option.id.value)) await this.database.set("opendiscord:option-suffix-counter",this.option.id.value,0)
|
if (!await this.database.exists("opendiscord:option-suffix-counter",this.option.id.value)) await this.database.set("opendiscord:option-suffix-counter",this.option.id.value,0)
|
||||||
}
|
}
|
||||||
getSuffix(user:discord.User): string {
|
async getSuffix(user:discord.User): Promise<string> {
|
||||||
const rawCurrentValue = this.database.get("opendiscord:option-suffix-counter",this.option.id.value)
|
const rawCurrentValue = await this.database.get("opendiscord:option-suffix-counter",this.option.id.value)
|
||||||
const currentValue = (typeof rawCurrentValue != "number") ? 0 : rawCurrentValue
|
const currentValue = (typeof rawCurrentValue != "number") ? 0 : rawCurrentValue
|
||||||
const newValue = currentValue+1
|
const newValue = currentValue+1
|
||||||
this.database.set("opendiscord:option-suffix-counter",this.option.id.value,newValue)
|
await this.database.set("opendiscord:option-suffix-counter",this.option.id.value,newValue)
|
||||||
return newValue.toString()
|
return newValue.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -456,12 +456,12 @@ export class ODOptionCounterFixedSuffix extends ODOptionSuffix {
|
|||||||
async #init(){
|
async #init(){
|
||||||
if (!await this.database.exists("opendiscord:option-suffix-counter",this.option.id.value)) await this.database.set("opendiscord:option-suffix-counter",this.option.id.value,0)
|
if (!await this.database.exists("opendiscord:option-suffix-counter",this.option.id.value)) await this.database.set("opendiscord:option-suffix-counter",this.option.id.value,0)
|
||||||
}
|
}
|
||||||
getSuffix(user:discord.User): string {
|
async getSuffix(user:discord.User): Promise<string> {
|
||||||
const rawCurrentValue = this.database.get("opendiscord:option-suffix-counter",this.option.id.value)
|
const rawCurrentValue = await this.database.get("opendiscord:option-suffix-counter",this.option.id.value)
|
||||||
const currentValue = (typeof rawCurrentValue != "number") ? 0 : rawCurrentValue
|
const currentValue = (typeof rawCurrentValue != "number") ? 0 : rawCurrentValue
|
||||||
const newValue = (currentValue >= 9999) ? 0 : currentValue+1
|
const newValue = (currentValue >= 9999) ? 0 : currentValue+1
|
||||||
|
|
||||||
this.database.set("opendiscord:option-suffix-counter",this.option.id.value,newValue)
|
await this.database.set("opendiscord:option-suffix-counter",this.option.id.value,newValue)
|
||||||
if (newValue.toString().length == 1) return "000"+newValue.toString()
|
if (newValue.toString().length == 1) return "000"+newValue.toString()
|
||||||
else if (newValue.toString().length == 2) return "00"+newValue.toString()
|
else if (newValue.toString().length == 2) return "00"+newValue.toString()
|
||||||
else if (newValue.toString().length == 3) return "0"+newValue.toString()
|
else if (newValue.toString().length == 3) return "0"+newValue.toString()
|
||||||
@@ -501,13 +501,13 @@ export class ODOptionRandomNumberSuffix extends ODOptionSuffix {
|
|||||||
if (history.includes(number)) return this.#generateUniqueValue(history)
|
if (history.includes(number)) return this.#generateUniqueValue(history)
|
||||||
else return number
|
else return number
|
||||||
}
|
}
|
||||||
getSuffix(user:discord.User): string {
|
async getSuffix(user:discord.User): Promise<string> {
|
||||||
const rawCurrentValues = this.database.get("opendiscord:option-suffix-history",this.option.id.value)
|
const rawCurrentValues = await this.database.get("opendiscord:option-suffix-history",this.option.id.value)
|
||||||
const currentValues = ((Array.isArray(rawCurrentValues)) ? rawCurrentValues : []) as string[]
|
const currentValues = ((Array.isArray(rawCurrentValues)) ? rawCurrentValues : []) as string[]
|
||||||
const newValue = this.#generateUniqueValue(currentValues)
|
const newValue = this.#generateUniqueValue(currentValues)
|
||||||
currentValues.push(newValue)
|
currentValues.push(newValue)
|
||||||
if (currentValues.length > 50) currentValues.shift()
|
if (currentValues.length > 50) currentValues.shift()
|
||||||
this.database.set("opendiscord:option-suffix-history",this.option.id.value,currentValues)
|
await this.database.set("opendiscord:option-suffix-history",this.option.id.value,currentValues)
|
||||||
return newValue
|
return newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -539,13 +539,13 @@ export class ODOptionRandomHexSuffix extends ODOptionSuffix {
|
|||||||
if (history.includes(hex)) return this.#generateUniqueValue(history)
|
if (history.includes(hex)) return this.#generateUniqueValue(history)
|
||||||
else return hex
|
else return hex
|
||||||
}
|
}
|
||||||
getSuffix(user:discord.User): string {
|
async getSuffix(user:discord.User): Promise<string> {
|
||||||
const rawCurrentValues = this.database.get("opendiscord:option-suffix-history",this.option.id.value)
|
const rawCurrentValues = await this.database.get("opendiscord:option-suffix-history",this.option.id.value)
|
||||||
const currentValues = ((Array.isArray(rawCurrentValues)) ? rawCurrentValues : []) as string[]
|
const currentValues = ((Array.isArray(rawCurrentValues)) ? rawCurrentValues : []) as string[]
|
||||||
const newValue = this.#generateUniqueValue(currentValues)
|
const newValue = this.#generateUniqueValue(currentValues)
|
||||||
currentValues.push(newValue)
|
currentValues.push(newValue)
|
||||||
if (currentValues.length > 50) currentValues.shift()
|
if (currentValues.length > 50) currentValues.shift()
|
||||||
this.database.set("opendiscord:option-suffix-history",this.option.id.value,currentValues)
|
await this.database.set("opendiscord:option-suffix-history",this.option.id.value,currentValues)
|
||||||
return newValue
|
return newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user