Add user-nickname option for channel suffixe
This commit is contained in:
committed by
Steven Dubois
parent
b07252151b
commit
21ce2921a1
@@ -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 () => {
|
||||
])
|
||||
})
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -151,7 +151,7 @@ export interface ODTicketOptionIds {
|
||||
"opendiscord:questions":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-closed":ODOptionData<string>,
|
||||
"opendiscord:channel-category-backup":ODOptionData<string>,
|
||||
@@ -353,10 +353,11 @@ export class ODOptionSuffixManager extends ODManager<ODOptionSuffix> {
|
||||
}
|
||||
|
||||
/**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)
|
||||
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<string> {
|
||||
async getSuffix(member:discord.GuildMember): Promise<string> {
|
||||
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<string> {
|
||||
return user.username
|
||||
async getSuffix(member:discord.GuildMember): Promise<string> {
|
||||
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 +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<string> {
|
||||
return user.id
|
||||
async getSuffix(member:discord.GuildMember): Promise<string> {
|
||||
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<string> {
|
||||
async getSuffix(member:discord.GuildMember): Promise<string> {
|
||||
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<string> {
|
||||
async getSuffix(member:discord.GuildMember): Promise<string> {
|
||||
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<string> {
|
||||
async getSuffix(member:discord.GuildMember): Promise<string> {
|
||||
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<string> {
|
||||
async getSuffix(member:discord.GuildMember): Promise<string> {
|
||||
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)
|
||||
|
||||
@@ -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}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user