Don't allow duplicate registrations

This commit is contained in:
Cohee
2025-01-11 23:18:03 +02:00
parent 1dccb08cd6
commit 1f66bc7756
2 changed files with 5 additions and 3 deletions

View File

@ -50,8 +50,8 @@ export class MacrosParser {
* @returns {IterableIterator<CustomMacro>} * @returns {IterableIterator<CustomMacro>}
*/ */
static [Symbol.iterator] = function* () { static [Symbol.iterator] = function* () {
for (const macro of this.#macros.values()) { for (const macro of MacrosParser.#macros.keys()) {
yield { key: macro, description: this.#descriptions.get(macro) }; yield { key: macro, description: MacrosParser.#descriptions.get(macro) };
} }
}; };

View File

@ -23,6 +23,7 @@ import { SlashCommandDebugController } from './SlashCommandDebugController.js';
import { commonEnumProviders } from './SlashCommandCommonEnumsProvider.js'; import { commonEnumProviders } from './SlashCommandCommonEnumsProvider.js';
import { SlashCommandBreak } from './SlashCommandBreak.js'; import { SlashCommandBreak } from './SlashCommandBreak.js';
import { MacrosParser } from '../macros.js'; import { MacrosParser } from '../macros.js';
import { t } from '../i18n.js';
/** @typedef {import('./SlashCommand.js').NamedArgumentsCapture} NamedArgumentsCapture */ /** @typedef {import('./SlashCommand.js').NamedArgumentsCapture} NamedArgumentsCapture */
/** @typedef {import('./SlashCommand.js').NamedArguments} NamedArguments */ /** @typedef {import('./SlashCommand.js').NamedArguments} NamedArguments */
@ -496,7 +497,8 @@ export class SlashCommandParser {
(li.querySelector('tt').remove(),li.innerHTML), (li.querySelector('tt').remove(),li.innerHTML),
)); ));
for (const macro of MacrosParser) { for (const macro of MacrosParser) {
options.push(new MacroAutoCompleteOption(macro.name, `{{${macro.name}}}`, macro.description || 'No description provided')); if (options.find(it => it.name === macro.key)) continue;
options.push(new MacroAutoCompleteOption(macro.key, `{{${macro.key}}}`, macro.description || t`No description provided`));
} }
const result = new AutoCompleteNameResult( const result = new AutoCompleteNameResult(
macro.name, macro.name,