Merge pull request #3121 from ceruleandeep/fix/handleIdForQRMenuAdd

Wire up id= parameter for /qr-context*
This commit is contained in:
Cohee 2024-11-29 14:27:57 +02:00 committed by GitHub
commit 2384031d09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -419,30 +419,35 @@ export class SlashCommandHandler {
namedArgumentList: [ namedArgumentList: [
SlashCommandNamedArgument.fromProps({ SlashCommandNamedArgument.fromProps({
name: 'set', name: 'set',
description: 'QR set name', description: 'Name of QR set to add the context menu to',
typeList: [ARGUMENT_TYPE.STRING], typeList: [ARGUMENT_TYPE.STRING],
isRequired: true, isRequired: true,
enumProvider: localEnumProviders.qrSets, enumProvider: localEnumProviders.qrSets,
}), }),
SlashCommandNamedArgument.fromProps({ SlashCommandNamedArgument.fromProps({
name: 'label', name: 'label',
description: 'Quick Reply label', description: 'Label of Quick Reply to add the context menu to',
typeList: [ARGUMENT_TYPE.STRING], typeList: [ARGUMENT_TYPE.STRING],
enumProvider: localEnumProviders.qrEntries, enumProvider: localEnumProviders.qrEntries,
}), }),
SlashCommandNamedArgument.fromProps({ SlashCommandNamedArgument.fromProps({
name: 'id', name: 'id',
description: 'numeric ID of the QR, e.g., id=42', description: 'Numeric ID of Quick Reply to add the context menu to, e.g. id=42',
typeList: [ARGUMENT_TYPE.NUMBER], typeList: [ARGUMENT_TYPE.NUMBER],
enumProvider: localEnumProviders.qrIds, enumProvider: localEnumProviders.qrIds,
}), }),
new SlashCommandNamedArgument( new SlashCommandNamedArgument(
'chain', 'boolean', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', 'chain',
'If true, button QR is sent together with (before) the clicked QR from the context menu',
[ARGUMENT_TYPE.BOOLEAN],
false,
false,
'false',
), ),
], ],
unnamedArgumentList: [ unnamedArgumentList: [
SlashCommandArgument.fromProps({ SlashCommandArgument.fromProps({
description: 'QR set name', description: 'Name of QR set to add as a context menu',
typeList: [ARGUMENT_TYPE.STRING], typeList: [ARGUMENT_TYPE.STRING],
isRequired: true, isRequired: true,
enumProvider: localEnumProviders.qrSets, enumProvider: localEnumProviders.qrSets,
@ -450,13 +455,16 @@ export class SlashCommandHandler {
], ],
helpString: ` helpString: `
<div> <div>
Add context menu preset to a QR. Add a context menu preset to a QR.
</div>
<div>
If <code>id</code> and <code>label</code> are both provided, <code>id</code> will be used.
</div> </div>
<div> <div>
<strong>Example:</strong> <strong>Example:</strong>
<ul> <ul>
<li> <li>
<pre><code>/qr-contextadd set=MyPreset label=MyButton chain=true MyOtherPreset</code></pre> <pre><code>/qr-contextadd set=MyQRSetWithTheButton label=MyButton chain=true MyQRSetWithContextItems</code></pre>
</li> </li>
</ul> </ul>
</div> </div>
@ -470,27 +478,27 @@ export class SlashCommandHandler {
namedArgumentList: [ namedArgumentList: [
SlashCommandNamedArgument.fromProps({ SlashCommandNamedArgument.fromProps({
name: 'set', name: 'set',
description: 'QR set name', description: 'Name of QR set to remove the context menu from',
typeList: [ARGUMENT_TYPE.STRING], typeList: [ARGUMENT_TYPE.STRING],
isRequired: true, isRequired: true,
enumProvider: localEnumProviders.qrSets, enumProvider: localEnumProviders.qrSets,
}), }),
SlashCommandNamedArgument.fromProps({ SlashCommandNamedArgument.fromProps({
name: 'label', name: 'label',
description: 'Quick Reply label', description: 'Label of Quick Reply to remove the context menu from',
typeList: [ARGUMENT_TYPE.STRING], typeList: [ARGUMENT_TYPE.STRING],
enumProvider: localEnumProviders.qrEntries, enumProvider: localEnumProviders.qrEntries,
}), }),
SlashCommandNamedArgument.fromProps({ SlashCommandNamedArgument.fromProps({
name: 'id', name: 'id',
description: 'numeric ID of the QR, e.g., id=42', description: 'Numeric ID of Quick Reply to remove the context menu from, e.g. id=42',
typeList: [ARGUMENT_TYPE.NUMBER], typeList: [ARGUMENT_TYPE.NUMBER],
enumProvider: localEnumProviders.qrIds, enumProvider: localEnumProviders.qrIds,
}), }),
], ],
unnamedArgumentList: [ unnamedArgumentList: [
SlashCommandArgument.fromProps({ SlashCommandArgument.fromProps({
description: 'QR set name', description: 'Name of QR set to remove',
typeList: [ARGUMENT_TYPE.STRING], typeList: [ARGUMENT_TYPE.STRING],
isRequired: true, isRequired: true,
enumProvider: localEnumProviders.qrSets, enumProvider: localEnumProviders.qrSets,
@ -500,6 +508,9 @@ export class SlashCommandHandler {
<div> <div>
Remove context menu preset from a QR. Remove context menu preset from a QR.
</div> </div>
<div>
If <code>id</code> and <code>label</code> are both provided, <code>id</code> will be used.
</div>
<div> <div>
<strong>Example:</strong> <strong>Example:</strong>
<ul> <ul>
@ -541,6 +552,9 @@ export class SlashCommandHandler {
<div> <div>
Remove all context menu presets from a QR. Remove all context menu presets from a QR.
</div> </div>
<div>
If <code>id</code> and a label are both provided, <code>id</code> will be used.
</div>
<div> <div>
<strong>Example:</strong> <strong>Example:</strong>
<ul> <ul>
@ -908,12 +922,11 @@ export class SlashCommandHandler {
} }
} }
createContextItem(args, name) { createContextItem(args, name) {
try { try {
this.api.createContextItem( this.api.createContextItem(
args.set, args.set,
args.label, args.id !== undefined ? Number(args.id) : args.label,
name, name,
isTrueBoolean(args.chain), isTrueBoolean(args.chain),
); );
@ -923,14 +936,14 @@ export class SlashCommandHandler {
} }
deleteContextItem(args, name) { deleteContextItem(args, name) {
try { try {
this.api.deleteContextItem(args.set, args.label, name); this.api.deleteContextItem(args.set, args.id !== undefined ? Number(args.id) : args.label, name);
} catch (ex) { } catch (ex) {
toastr.error(ex.message); toastr.error(ex.message);
} }
} }
clearContextMenu(args, label) { clearContextMenu(args, label) {
try { try {
this.api.clearContextMenu(args.set, args.label ?? label); this.api.clearContextMenu(args.set, args.id !== undefined ? Number(args.id) : args.label ?? label);
} catch (ex) { } catch (ex) {
toastr.error(ex.message); toastr.error(ex.message);
} }