add slash commands to get existing QRs and QR sets

This commit is contained in:
LenAnderson
2023-12-23 16:36:41 +00:00
parent 6e3159db3f
commit a8f130ec5d
2 changed files with 64 additions and 0 deletions

View File

@ -393,4 +393,44 @@ export class QuickReplyApi {
await set.delete();
this.settingsUi.rerender();
}
/**
* Gets a list of all quick reply sets.
*
* @returns array with the names of all quick reply sets
*/
listSets() {
return QuickReplySet.list.map(it=>it.name);
}
/**
* Gets a list of all globally active quick reply sets.
*
* @returns array with the names of all quick reply sets
*/
listGlobalSets() {
return this.settings.config.setList.map(it=>it.set.name);
}
/**
* Gets a list of all quick reply sets activated by the current chat.
*
* @returns array with the names of all quick reply sets
*/
listChatSets() {
return this.settings.chatConfig?.setList?.flatMap(it=>it.set.name) ?? [];
}
/**
* Gets a list of all quick replies in the quick reply set.
*
* @param {String} setName name of the existing quick reply set
* @returns array with the labels of this set's quick replies
*/
listQuickReplies(setName) {
const set = this.getSetByName(setName);
if (!set) {
throw new Error(`No quick reply set with name "${name}" found.`);
}
return set.qrList.map(it=>it.label);
}
}

View File

@ -24,6 +24,8 @@ export class SlashCommandHandler {
registerSlashCommand('qr-chat-set', (args, value)=>this.toggleChatSet(value, args), [], '<span class="monospace">[visible=true] (number)</span> toggle chat QR set', true, true);
registerSlashCommand('qr-chat-set-on', (args, value)=>this.addChatSet(value, args), [], '<span class="monospace">[visible=true] (number)</span> activate chat QR set', true, true);
registerSlashCommand('qr-chat-set-off', (_, value)=>this.removeChatSet(value), [], '<span class="monospace">(number)</span> deactivate chat QR set', true, true);
registerSlashCommand('qr-set-list', (_, value)=>this.listSets(value ?? 'all'), [], '(all|global|chat) gets a list of the names of all quick reply sets', true, true);
registerSlashCommand('qr-list', (_, value)=>this.listQuickReplies(value), [], '(set name) gets a list of the names of all quick replies in this quick reply set', true, true);
const qrArgs = `
label - string - text on the button, e.g., label=MyButton
@ -243,4 +245,26 @@ export class SlashCommandHandler {
toastr.error(ex.message);
}
}
listSets(source) {
try {
switch (source) {
case 'global':
return this.api.listGlobalSets();
case 'chat':
return this.api.listChatSets();
default:
return this.api.listSets();
}
} catch (ex) {
toastr.error(ex.message);
}
}
listQuickReplies(name) {
try {
return this.api.listQuickReplies(name);
} catch (ex) {
toastr.error(ex.message);
}
}
}