mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
use scope macros for QR args
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import { callPopup } from '../../../../script.js';
|
import { callPopup } from '../../../../script.js';
|
||||||
import { setSlashCommandAutoComplete } from '../../../slash-commands.js';
|
import { setSlashCommandAutoComplete } from '../../../slash-commands.js';
|
||||||
|
import { SlashCommandScope } from '../../../slash-commands/SlashCommandScope.js';
|
||||||
import { getSortableDelay } from '../../../utils.js';
|
import { getSortableDelay } from '../../../utils.js';
|
||||||
import { log, warn } from '../index.js';
|
import { log, warn } from '../index.js';
|
||||||
import { QuickReplyContextLink } from './QuickReplyContextLink.js';
|
import { QuickReplyContextLink } from './QuickReplyContextLink.js';
|
||||||
@ -493,10 +494,11 @@ export class QuickReply {
|
|||||||
|
|
||||||
async execute(args = {}) {
|
async execute(args = {}) {
|
||||||
if (this.message?.length > 0 && this.onExecute) {
|
if (this.message?.length > 0 && this.onExecute) {
|
||||||
const message = this.message.replace(/\{\{arg::([^}]+)\}\}/g, (_, key) => {
|
const scope = new SlashCommandScope();
|
||||||
return args[key] ?? '';
|
for (const key of Object.keys(args)) {
|
||||||
});
|
scope.setMacro(`arg::${key}`, args[key]);
|
||||||
return await this.onExecute(this, message, args.isAutoExecute ?? false);
|
}
|
||||||
|
return await this.onExecute(this, this.message, args.isAutoExecute ?? false, scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { getRequestHeaders, substituteParams } from '../../../../script.js';
|
import { getRequestHeaders, substituteParams } from '../../../../script.js';
|
||||||
import { executeSlashCommands } from '../../../slash-commands.js';
|
import { executeSlashCommands } from '../../../slash-commands.js';
|
||||||
|
import { SlashCommandScope } from '../../../slash-commands/SlashCommandScope.js';
|
||||||
import { debounceAsync, warn } from '../index.js';
|
import { debounceAsync, warn } from '../index.js';
|
||||||
import { QuickReply } from './QuickReply.js';
|
import { QuickReply } from './QuickReply.js';
|
||||||
|
|
||||||
@ -102,8 +103,9 @@ export class QuickReplySet {
|
|||||||
/**
|
/**
|
||||||
* @param {QuickReply} qr
|
* @param {QuickReply} qr
|
||||||
* @param {String} [message] - optional altered message to be used
|
* @param {String} [message] - optional altered message to be used
|
||||||
|
* @param {SlashCommandScope} [scope] - optional scope to be used when running the command
|
||||||
*/
|
*/
|
||||||
async execute(qr, message = null, isAutoExecute = false) {
|
async execute(qr, message = null, isAutoExecute = false, scope = null) {
|
||||||
/**@type {HTMLTextAreaElement}*/
|
/**@type {HTMLTextAreaElement}*/
|
||||||
const ta = document.querySelector('#send_textarea');
|
const ta = document.querySelector('#send_textarea');
|
||||||
const finalMessage = message ?? qr.message;
|
const finalMessage = message ?? qr.message;
|
||||||
@ -119,7 +121,7 @@ export class QuickReplySet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (input[0] == '/' && !this.disableSend) {
|
if (input[0] == '/' && !this.disableSend) {
|
||||||
const result = await executeSlashCommands(input);
|
const result = await executeSlashCommands(input, true, scope);
|
||||||
return typeof result === 'object' ? result?.pipe : '';
|
return typeof result === 'object' ? result?.pipe : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user