mirror of
https://github.com/Equicord/Equicord.git
synced 2025-04-01 13:11:57 -04:00
CommandsAPI: Fix issue with overlapping IDS (#3271)
This commit is contained in:
parent
d178dcc480
commit
7eec2e5d5b
1 changed files with 7 additions and 1 deletions
|
@ -31,6 +31,7 @@ export const commands = {} as Record<string, Command>;
|
||||||
// hack for plugins being evaluated before we can grab these from webpack
|
// hack for plugins being evaluated before we can grab these from webpack
|
||||||
const OptPlaceholder = Symbol("OptionalMessageOption") as any as Option;
|
const OptPlaceholder = Symbol("OptionalMessageOption") as any as Option;
|
||||||
const ReqPlaceholder = Symbol("RequiredMessageOption") as any as Option;
|
const ReqPlaceholder = Symbol("RequiredMessageOption") as any as Option;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional message option named "message" you can use in commands.
|
* Optional message option named "message" you can use in commands.
|
||||||
* Used in "tableflip" or "shrug"
|
* Used in "tableflip" or "shrug"
|
||||||
|
@ -44,11 +45,16 @@ export let OptionalMessageOption: Option = OptPlaceholder;
|
||||||
*/
|
*/
|
||||||
export let RequiredMessageOption: Option = ReqPlaceholder;
|
export let RequiredMessageOption: Option = ReqPlaceholder;
|
||||||
|
|
||||||
|
// Discord's command list has random gaps for some reason, which can cause issues while rendering the commands
|
||||||
|
// Add this offset to every added command to keep them unique
|
||||||
|
let commandIdOffset: number;
|
||||||
|
|
||||||
export const _init = function (cmds: Command[]) {
|
export const _init = function (cmds: Command[]) {
|
||||||
try {
|
try {
|
||||||
BUILT_IN = cmds;
|
BUILT_IN = cmds;
|
||||||
OptionalMessageOption = cmds.find(c => (c.untranslatedName || c.displayName) === "shrug")!.options![0];
|
OptionalMessageOption = cmds.find(c => (c.untranslatedName || c.displayName) === "shrug")!.options![0];
|
||||||
RequiredMessageOption = cmds.find(c => (c.untranslatedName || c.displayName) === "me")!.options![0];
|
RequiredMessageOption = cmds.find(c => (c.untranslatedName || c.displayName) === "me")!.options![0];
|
||||||
|
commandIdOffset = Math.abs(BUILT_IN.map(x => Number(x.id)).sort((x, y) => x - y)[0]) - BUILT_IN.length;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
new Logger("CommandsAPI").error("Failed to load CommandsApi", e, " - cmds is", cmds);
|
new Logger("CommandsAPI").error("Failed to load CommandsApi", e, " - cmds is", cmds);
|
||||||
}
|
}
|
||||||
|
@ -142,7 +148,7 @@ export function registerCommand<C extends Command>(command: C, plugin: string) {
|
||||||
command.isVencordCommand = true;
|
command.isVencordCommand = true;
|
||||||
command.untranslatedName ??= command.name;
|
command.untranslatedName ??= command.name;
|
||||||
command.untranslatedDescription ??= command.description;
|
command.untranslatedDescription ??= command.description;
|
||||||
command.id ??= `-${BUILT_IN.length + 1}`;
|
command.id ??= `-${BUILT_IN.length + commandIdOffset + 1}`;
|
||||||
command.applicationId ??= "-1"; // BUILT_IN;
|
command.applicationId ??= "-1"; // BUILT_IN;
|
||||||
command.type ??= ApplicationCommandType.CHAT_INPUT;
|
command.type ??= ApplicationCommandType.CHAT_INPUT;
|
||||||
command.inputType ??= ApplicationCommandInputType.BUILT_IN_TEXT;
|
command.inputType ??= ApplicationCommandInputType.BUILT_IN_TEXT;
|
||||||
|
|
Loading…
Add table
Reference in a new issue