Added user-nickname channel suffix option

This commit is contained in:
Jasper
2025-09-14 22:23:42 +02:00
committed by GitHub
5 changed files with 37 additions and 17 deletions
+1 -1
View File
@@ -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 channelTopic = option.get("opendiscord:channel-topic").value const channelTopic = option.get("opendiscord:channel-topic").value
const channelSuffix = await opendiscord.options.suffix.getSuffixFromOption(option,user) const channelSuffix = await opendiscord.options.suffix.getSuffixFromOption(option,user,guild)
const channelName = channelPrefix+channelSuffix const channelName = channelPrefix+channelSuffix
//handle category //handle category
+1 -1
View File
@@ -411,7 +411,7 @@ export interface ODJsonConfig_DefaultOptionTicketChannelType {
/**The prefix used in the name of this ticket channel. */ /**The prefix used in the name of this ticket channel. */
prefix:string, prefix:string,
/**The type of suffix used in the name of this ticket channel. */ /**The type of suffix used in the name of this ticket channel. */
suffix:"user-name"|"user-id"|"random-number"|"random-hex"|"counter-dynamic"|"counter-fixed", suffix:"user-name"|"user-nickname"|"user-id"|"random-number"|"random-hex"|"counter-dynamic"|"counter-fixed",
/**An optional discord category id to create this ticket in. */ /**An optional discord category id to create this ticket in. */
category:string, category:string,
/**An optional discord category id to move this ticket to when closed. */ /**An optional discord category id to move this ticket to when closed. */
+31 -12
View File
@@ -151,7 +151,7 @@ export interface ODTicketOptionIds {
"opendiscord:questions":ODOptionData<string[]>, "opendiscord:questions":ODOptionData<string[]>,
"opendiscord:channel-prefix":ODOptionData<string>, "opendiscord:channel-prefix":ODOptionData<string>,
"opendiscord:channel-suffix":ODOptionData<"user-name"|"user-id"|"random-number"|"random-hex"|"counter-dynamic"|"counter-fixed">, "opendiscord:channel-suffix":ODOptionData<"user-name"|"user-nickname"|"user-id"|"random-number"|"random-hex"|"counter-dynamic"|"counter-fixed">,
"opendiscord:channel-category":ODOptionData<string>, "opendiscord:channel-category":ODOptionData<string>,
"opendiscord:channel-category-closed":ODOptionData<string>, "opendiscord:channel-category-closed":ODOptionData<string>,
"opendiscord:channel-category-backup":ODOptionData<string>, "opendiscord:channel-category-backup":ODOptionData<string>,
@@ -353,10 +353,16 @@ export class ODOptionSuffixManager extends ODManager<ODOptionSuffix> {
} }
/**Instantly get the suffix from an `ODTicketOption`. */ /**Instantly get the suffix from an `ODTicketOption`. */
async getSuffixFromOption(option:ODTicketOption,user:discord.User): Promise<string|null> { async getSuffixFromOption(option:ODTicketOption,user:discord.User,guild:discord.Guild): 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 await suffix.getSuffix(user) try{
const member = await guild.members.fetch(user.id)
return await suffix.getSuffix(member)
}catch(err){
process.emit("uncaughtException",err)
return null
}
} }
} }
@@ -377,7 +383,7 @@ export class ODOptionSuffix extends ODManagerData {
} }
/**Get the suffix for a new ticket. */ /**Get the suffix for a new ticket. */
async getSuffix(user:discord.User): Promise<string> { async getSuffix(member:discord.GuildMember): Promise<string> {
throw new ODSystemError("Tried to use an unimplemented ODOptionSuffix!") throw new ODSystemError("Tried to use an unimplemented ODOptionSuffix!")
} }
} }
@@ -390,8 +396,21 @@ 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 {
async getSuffix(user:discord.User): Promise<string> { async getSuffix(member:discord.GuildMember): Promise<string> {
return user.username return member.user.username
}
}
/**## ODOptionUserNicknameSuffix `class`
* This is an Open Ticket user-nickname option suffix.
*
* This class can generate a user-nickname suffix for a discord channel name from a specific option.
*
* Use `getSuffix()` to get the new suffix!
*/
export class ODOptionUserNicknameSuffix extends ODOptionSuffix {
async getSuffix(member:discord.GuildMember): Promise<string> {
return member.displayName
} }
} }
@@ -403,8 +422,8 @@ 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 {
async getSuffix(user:discord.User): Promise<string> { async getSuffix(member:discord.GuildMember): Promise<string> {
return user.id return member.id
} }
} }
@@ -429,7 +448,7 @@ 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)
} }
async getSuffix(user:discord.User): Promise<string> { async getSuffix(member:discord.GuildMember): Promise<string> {
const rawCurrentValue = await 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
@@ -459,7 +478,7 @@ 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)
} }
async getSuffix(user:discord.User): Promise<string> { async getSuffix(member:discord.GuildMember): Promise<string> {
const rawCurrentValue = await 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
@@ -504,7 +523,7 @@ 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
} }
async getSuffix(user:discord.User): Promise<string> { async getSuffix(member:discord.GuildMember): Promise<string> {
const rawCurrentValues = await 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)
@@ -542,7 +561,7 @@ 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
} }
async getSuffix(user:discord.User): Promise<string> { async getSuffix(member:discord.GuildMember): Promise<string> {
const rawCurrentValues = await 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)
+1 -1
View File
@@ -402,7 +402,7 @@ export const defaultOptionsStructure = new api.ODCheckerArrayStructure("opendisc
//TICKET CHANNEL //TICKET CHANNEL
{key:"channel",checker:new api.ODCheckerObjectStructure("opendiscord:ticket-channel",{cliInitSkipKeys:["backupCategory","claimedCategory"],children:[ {key:"channel",checker:new api.ODCheckerObjectStructure("opendiscord:ticket-channel",{cliInitSkipKeys:["backupCategory","claimedCategory"],children:[
{key:"prefix",checker:new api.ODCheckerStringStructure("opendiscord:ticket-channel-prefix",{maxLength:25,regex:/^[^\s]*$/,cliDisplayName:"Prefix",cliDisplayDescription:"The prefix of the name of the ticket channel. (e.g. 'question-')"})}, {key:"prefix",checker:new api.ODCheckerStringStructure("opendiscord:ticket-channel-prefix",{maxLength:25,regex:/^[^\s]*$/,cliDisplayName:"Prefix",cliDisplayDescription:"The prefix of the name of the ticket channel. (e.g. 'question-')"})},
{key:"suffix",checker:new api.ODCheckerStringStructure("opendiscord:ticket-channel-suffix",{choices:["user-name","user-id","random-number","random-hex","counter-dynamic","counter-fixed"],cliDisplayName:"Suffix",cliDisplayDescription:"The suffix mode to use. The number/text will be appended after the prefix."})}, {key:"suffix",checker:new api.ODCheckerStringStructure("opendiscord:ticket-channel-suffix",{choices:["user-name","user-nickname","user-id","random-number","random-hex","counter-dynamic","counter-fixed"],cliDisplayName:"Suffix",cliDisplayDescription:"The suffix mode to use. The number/text will be appended after the prefix."})},
{key:"category",checker:new api.ODCheckerCustomStructure_DiscordId("opendiscord:ticket-channel-category","category",true,[],{cliDisplayName:"Category",cliDisplayDescription:"The category the ticket will be created in. Leave empty for no category."})}, {key:"category",checker:new api.ODCheckerCustomStructure_DiscordId("opendiscord:ticket-channel-category","category",true,[],{cliDisplayName:"Category",cliDisplayDescription:"The category the ticket will be created in. Leave empty for no category."})},
{key:"closedCategory",checker:new api.ODCheckerCustomStructure_DiscordId("opendiscord:ticket-channel-closed-category","category",true,[],{cliDisplayName:"Closed Category",cliDisplayDescription:"An additional category where the ticket will be moved to when closed."})}, {key:"closedCategory",checker:new api.ODCheckerCustomStructure_DiscordId("opendiscord:ticket-channel-closed-category","category",true,[],{cliDisplayName:"Closed Category",cliDisplayDescription:"An additional category where the ticket will be moved to when closed."})},
+1
View File
@@ -139,6 +139,7 @@ export const loadTicketOptionSuffix = (option:api.ODTicketOption): api.ODOptionS
const mode = option.get("opendiscord:channel-suffix").value const mode = option.get("opendiscord:channel-suffix").value
const globalDatabase = opendiscord.databases.get("opendiscord:global") const globalDatabase = opendiscord.databases.get("opendiscord:global")
if (mode == "user-name") return new api.ODOptionUserNameSuffix(option.id.value,option) if (mode == "user-name") return new api.ODOptionUserNameSuffix(option.id.value,option)
else if (mode == "user-nickname") return new api.ODOptionUserNicknameSuffix(option.id.value,option)
else if (mode == "random-number") return new api.ODOptionRandomNumberSuffix(option.id.value,option,globalDatabase) else if (mode == "random-number") return new api.ODOptionRandomNumberSuffix(option.id.value,option,globalDatabase)
else if (mode == "random-hex") return new api.ODOptionRandomHexSuffix(option.id.value,option,globalDatabase) else if (mode == "random-hex") return new api.ODOptionRandomHexSuffix(option.id.value,option,globalDatabase)
else if (mode == "counter-fixed") return new api.ODOptionCounterFixedSuffix(option.id.value,option,globalDatabase) else if (mode == "counter-fixed") return new api.ODOptionCounterFixedSuffix(option.id.value,option,globalDatabase)