diff --git a/src/commands/autocomplete.ts b/src/commands/autocomplete.ts new file mode 100644 index 0000000..e7cac2a --- /dev/null +++ b/src/commands/autocomplete.ts @@ -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) + })) +} \ No newline at end of file diff --git a/src/core/api/defaults/responder.ts b/src/core/api/defaults/responder.ts index 95534bb..ffe8cb4 100644 --- a/src/core/api/defaults/responder.ts +++ b/src/core/api/defaults/responder.ts @@ -308,7 +308,8 @@ export class ODContextMenuResponder_Default { - 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){ diff --git a/src/data/framework/commandLoader.ts b/src/data/framework/commandLoader.ts index b24d09b..4e10510 100644 --- a/src/data/framework/commandLoader.ts +++ b/src/data/framework/commandLoader.ts @@ -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 diff --git a/src/index.ts b/src/index.ts index fe323ab..9963ce9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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])