Added autocomplete to panel, ticket & move cmds

Ticket/panel options are now autocompleted instead of being a choice in the slash commands. This also results in the max amount of tickets limit to be increased to infinity.
This commit is contained in:
DJj123dj
2025-08-28 09:00:07 +02:00
parent 793c6f0603
commit 82f2aeaa90
5 changed files with 42 additions and 45 deletions
+32
View File
@@ -0,0 +1,32 @@
///////////////////////////////////////
//AUTOCOMPLETE COMMAND UTILS
///////////////////////////////////////
import {opendiscord, api, utilities} from "../index"
import * as discord from "discord.js"
export const registerAutocompleteResponders = async () => {
//PANEL ID AUTOCOMPLETE
opendiscord.responders.autocomplete.add(new api.ODAutocompleteResponder("opendiscord:panel-id","panel","id"))
opendiscord.responders.autocomplete.get("opendiscord:panel-id").workers.add(new api.ODWorker("opendiscord:panel-id",0,async (instance,params,source,cancel) => {
//create panel choices
const panelChoices : {name:string, value:string}[] = []
opendiscord.configs.get("opendiscord:panels").data.forEach((panel) => {
panelChoices.push({name:panel.name, value:panel.id})
})
await instance.filteredAutocomplete(panelChoices)
}))
//OPTION ID AUTOCOMPLETE
opendiscord.responders.autocomplete.add(new api.ODAutocompleteResponder("opendiscord:option-id",/ticket|move/,"id"))
opendiscord.responders.autocomplete.get("opendiscord:option-id").workers.add(new api.ODWorker("opendiscord:option-id",0,async (instance,params,source,cancel) => {
//create ticket choices
const ticketChoices : {name:string, value:string}[] = []
opendiscord.configs.get("opendiscord:options").data.forEach((option) => {
if (option.type != "ticket") return
ticketChoices.push({name:option.name, value:option.id})
})
instance.filteredAutocomplete(ticketChoices)
}))
}
+2 -1
View File
@@ -308,7 +308,8 @@ export class ODContextMenuResponder_Default<Source extends string, Params, Worke
* It's used to generate typescript declarations for this class.
*/
export interface ODAutocompleteResponderManagerIds_Default {
//"opendiscord:example":{source:"autocomplete",params:{},workers:"opendiscord:example"},
"opendiscord:panel-id":{source:"autocomplete",params:{},workers:"opendiscord:panel-id"},
"opendiscord:option-id":{source:"autocomplete",params:{},workers:"opendiscord:option-id"}
}
/**## ODAutocompleteResponderManager_Default `default_class`
+4 -3
View File
@@ -1333,8 +1333,8 @@ export class ODAutocompleteResponderManager extends ODManager<ODAutocompleteResp
export class ODAutocompleteResponderInstance {
/**The interaction which is the source of this instance. */
interaction: discord.AutocompleteInteraction
/**Did a worker already reply to this instance/interaction? */
didReply: boolean = false
/**Did a worker already respond to this instance/interaction? */
didRespond: boolean = false
/**The user who triggered this autocomplete. */
user: discord.User
/**The guild member who triggered this autocomplete. */
@@ -1356,7 +1356,7 @@ export class ODAutocompleteResponderInstance {
this.target = interaction.options.getFocused(true)
setTimeout(async () => {
if (!this.didReply){
if (!this.didRespond){
process.emit("uncaughtException",new ODSystemError("Autocomplete responder instance failed to respond widthin 2.5sec!"))
}
},timeoutMs ?? 2500)
@@ -1374,6 +1374,7 @@ export class ODAutocompleteResponderInstance {
return {success:false}
}else{
await this.interaction.respond(newChoices)
this.didRespond = true
return {success:true}
}
}catch(err){
+3 -40
View File
@@ -23,19 +23,6 @@ export const loadAllSlashCommands = async () => {
if (!generalConfig.data.slashCommands) return
//create panel choices
const panelChoices : {name:string, value:string}[] = []
opendiscord.configs.get("opendiscord:panels").data.forEach((panel) => {
panelChoices.push({name:panel.name, value:panel.id})
})
//create ticket choices
const ticketChoices : {name:string, value:string}[] = []
opendiscord.configs.get("opendiscord:options").data.forEach((option) => {
if (option.type != "ticket") return
ticketChoices.push({name:option.name, value:option.id})
})
const allowedCommands: string[] = []
for (const key in generalConfig.data.system.permissions){
if (generalConfig.data.system.permissions[key] != "none") allowedCommands.push(key)
@@ -63,7 +50,7 @@ export const loadAllSlashCommands = async () => {
description:lang.getTranslation("commands.panelId"),
type:acot.String,
required:true,
choices:panelChoices
autocomplete:true
},
{
name:"auto-update",
@@ -72,14 +59,6 @@ export const loadAllSlashCommands = async () => {
required:false
}
]
},(current) => {
//check if this slash command needs to be updated
const idOption = current.options.find((opt) => opt.name == "id" && opt.type == acot.String)
if (!idOption || idOption.choices.length != panelChoices.length) return true
if (!panelChoices.every((panel) => {
return (idOption.choices.find((c) => c.value == panel.value && c.name == panel.name)) ? true : false
})) return true
return false
}))
//TICKET (when enabled)
@@ -95,17 +74,9 @@ export const loadAllSlashCommands = async () => {
description:lang.getTranslation("commands.ticketId"),
type:acot.String,
required:true,
choices:ticketChoices
autocomplete:true
}
]
},(current) => {
//check if this slash command needs to be updated
const idOption = current.options.find((opt) => opt.name == "id" && opt.type == acot.String)
if (!idOption || idOption.choices.length != ticketChoices.length) return true
if (!ticketChoices.every((ticket) => {
return (idOption.choices.find((c) => c.value == ticket.value && c.name == ticket.name)) ? true : false
})) return true
return false
}))
//CLOSE
@@ -267,7 +238,7 @@ export const loadAllSlashCommands = async () => {
description:lang.getTranslation("commands.moveId"),
type:acot.String,
required:true,
choices:ticketChoices
autocomplete:true
},
{
name:"reason",
@@ -276,14 +247,6 @@ export const loadAllSlashCommands = async () => {
required:false
}
]
},(current) => {
//check if this slash command needs to be updated
const idOption = current.options.find((opt) => opt.name == "id" && opt.type == acot.String)
if (!idOption || idOption.choices.length != ticketChoices.length) return true
if (!ticketChoices.every((ticket) => {
return (idOption.choices.find((c) => c.value == ticket.value && c.name == ticket.name)) ? true : false
})) return true
return false
}))
//RENAME
+1 -1
View File
@@ -721,7 +721,7 @@ const main = async () => {
//load autocomplete responders
opendiscord.log("Loading autocomplete responders...","system")
if (opendiscord.defaults.getDefault("autocompleteRespondersLoading")){
//TODO!!
await (await import("./commands/autocomplete.js")).registerAutocompleteResponders()
}
await opendiscord.events.get("onAutocompleteResponderLoad").emit([opendiscord.responders.autocomplete,opendiscord.responders,opendiscord.actions])
await opendiscord.events.get("afterAutocompleteRespondersLoaded").emit([opendiscord.responders.autocomplete,opendiscord.responders,opendiscord.actions])