diff --git a/src/actions/createTicket.ts b/src/actions/createTicket.ts index e877a90..1d05f8f 100644 --- a/src/actions/createTicket.ts +++ b/src/actions/createTicket.ts @@ -20,7 +20,7 @@ export const registerActions = async () => { const channelCategory = option.get("opendiscord:channel-category").value const channelBackupCategory = option.get("opendiscord:channel-category-backup").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 //handle category @@ -237,4 +237,4 @@ export const registerActions = async () => { ]) }) ]) -} \ No newline at end of file +} diff --git a/src/core/api/defaults/config.ts b/src/core/api/defaults/config.ts index 7a50dad..e39b98e 100644 --- a/src/core/api/defaults/config.ts +++ b/src/core/api/defaults/config.ts @@ -411,7 +411,7 @@ export interface ODJsonConfig_DefaultOptionTicketChannelType { /**The prefix used in the name of this ticket channel. */ prefix:string, /**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. */ category:string, /**An optional discord category id to move this ticket to when closed. */ diff --git a/src/core/api/openticket/option.ts b/src/core/api/openticket/option.ts index 6741616..9bd6ad9 100644 --- a/src/core/api/openticket/option.ts +++ b/src/core/api/openticket/option.ts @@ -151,7 +151,7 @@ export interface ODTicketOptionIds { "opendiscord:questions":ODOptionData, "opendiscord:channel-prefix":ODOptionData, - "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, "opendiscord:channel-category-closed":ODOptionData, "opendiscord:channel-category-backup":ODOptionData, @@ -353,10 +353,11 @@ export class ODOptionSuffixManager extends ODManager { } /**Instantly get the suffix from an `ODTicketOption`. */ - async getSuffixFromOption(option:ODTicketOption,user:discord.User): Promise { + async getSuffixFromOption(option:ODTicketOption,user:discord.User, guild: discord.Guild): Promise { const suffix = this.getAll().find((suffix) => suffix.option.id.value == option.id.value) if (!suffix) return null - return await suffix.getSuffix(user) + const member = await guild.members.fetch(user.id); + return await suffix.getSuffix(member) } } @@ -377,7 +378,7 @@ export class ODOptionSuffix extends ODManagerData { } /**Get the suffix for a new ticket. */ - async getSuffix(user:discord.User): Promise { + async getSuffix(member:discord.GuildMember): Promise { throw new ODSystemError("Tried to use an unimplemented ODOptionSuffix!") } } @@ -390,8 +391,21 @@ export class ODOptionSuffix extends ODManagerData { * Use `getSuffix()` to get the new suffix! */ export class ODOptionUserNameSuffix extends ODOptionSuffix { - async getSuffix(user:discord.User): Promise { - return user.username + async getSuffix(member:discord.GuildMember): Promise { + 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 { + return member.displayName } } @@ -403,8 +417,8 @@ export class ODOptionUserNameSuffix extends ODOptionSuffix { * Use `getSuffix()` to get the new suffix! */ export class ODOptionUserIdSuffix extends ODOptionSuffix { - async getSuffix(user:discord.User): Promise { - return user.id + async getSuffix(member:discord.GuildMember): Promise { + return member.id } } @@ -429,7 +443,7 @@ export class ODOptionCounterDynamicSuffix extends ODOptionSuffix { 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) } - async getSuffix(user:discord.User): Promise { + async getSuffix(member:discord.GuildMember): Promise { const rawCurrentValue = await this.database.get("opendiscord:option-suffix-counter",this.option.id.value) const currentValue = (typeof rawCurrentValue != "number") ? 0 : rawCurrentValue const newValue = currentValue+1 @@ -459,7 +473,7 @@ export class ODOptionCounterFixedSuffix extends ODOptionSuffix { 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) } - async getSuffix(user:discord.User): Promise { + async getSuffix(member:discord.GuildMember): Promise { const rawCurrentValue = await this.database.get("opendiscord:option-suffix-counter",this.option.id.value) const currentValue = (typeof rawCurrentValue != "number") ? 0 : rawCurrentValue const newValue = (currentValue >= 9999) ? 0 : currentValue+1 @@ -504,7 +518,7 @@ export class ODOptionRandomNumberSuffix extends ODOptionSuffix { if (history.includes(number)) return this.#generateUniqueValue(history) else return number } - async getSuffix(user:discord.User): Promise { + async getSuffix(member:discord.GuildMember): Promise { const rawCurrentValues = await this.database.get("opendiscord:option-suffix-history",this.option.id.value) const currentValues = ((Array.isArray(rawCurrentValues)) ? rawCurrentValues : []) as string[] const newValue = this.#generateUniqueValue(currentValues) @@ -542,7 +556,7 @@ export class ODOptionRandomHexSuffix extends ODOptionSuffix { if (history.includes(hex)) return this.#generateUniqueValue(history) else return hex } - async getSuffix(user:discord.User): Promise { + async getSuffix(member:discord.GuildMember): Promise { const rawCurrentValues = await this.database.get("opendiscord:option-suffix-history",this.option.id.value) const currentValues = ((Array.isArray(rawCurrentValues)) ? rawCurrentValues : []) as string[] const newValue = this.#generateUniqueValue(currentValues) diff --git a/src/data/framework/checkerLoader.ts b/src/data/framework/checkerLoader.ts index b7eee42..ef7a3d7 100644 --- a/src/data/framework/checkerLoader.ts +++ b/src/data/framework/checkerLoader.ts @@ -402,7 +402,7 @@ export const defaultOptionsStructure = new api.ODCheckerArrayStructure("opendisc //TICKET CHANNEL {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:"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:"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."})}, @@ -700,4 +700,4 @@ export const defaultDropdownOptionsFunction = (manager:api.ODCheckerManager, fun }) return {valid:(final.length < 1),messages:final} -} \ No newline at end of file +} diff --git a/src/data/openticket/optionLoader.ts b/src/data/openticket/optionLoader.ts index 0124902..38dd5de 100644 --- a/src/data/openticket/optionLoader.ts +++ b/src/data/openticket/optionLoader.ts @@ -139,6 +139,7 @@ export const loadTicketOptionSuffix = (option:api.ODTicketOption): api.ODOptionS const mode = option.get("opendiscord:channel-suffix").value const globalDatabase = opendiscord.databases.get("opendiscord:global") 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-hex") return new api.ODOptionRandomHexSuffix(option.id.value,option,globalDatabase) else if (mode == "counter-fixed") return new api.ODOptionCounterFixedSuffix(option.id.value,option,globalDatabase)