mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'send-commands-return-value' of https://github.com/SillyTavern/SillyTavern into send-commands-return-value
This commit is contained in:
@ -41,10 +41,13 @@ export const slashCommandReturnHelper = {
|
|||||||
* @param {object|number|string} value The value to return
|
* @param {object|number|string} value The value to return
|
||||||
* @param {object} [options={}] Options
|
* @param {object} [options={}] Options
|
||||||
* @param {(o: object) => string} [options.objectToStringFunc=null] Function to convert the object to a string, if object was provided and 'object' was not the chosen return type
|
* @param {(o: object) => string} [options.objectToStringFunc=null] Function to convert the object to a string, if object was provided and 'object' was not the chosen return type
|
||||||
|
* @param {(o: object) => string} [options.objectToHtmlFunc=null] Analog to 'objectToStringFunc', which will be used here if not provided - but can do a different string layout if HTML is requested
|
||||||
* @returns {Promise<*>} The processed return value
|
* @returns {Promise<*>} The processed return value
|
||||||
*/
|
*/
|
||||||
async doReturn(type, value, { objectToStringFunc = o => o?.toString() } = {}) {
|
async doReturn(type, value, { objectToStringFunc = o => o?.toString(), objectToHtmlFunc = null } = {}) {
|
||||||
const stringValue = typeof value !== 'string' ? objectToStringFunc(value) : value;
|
const shouldHtml = type.endsWith('html');
|
||||||
|
const actualConverterFunc = shouldHtml && objectToHtmlFunc ? objectToHtmlFunc : objectToStringFunc;
|
||||||
|
const stringValue = typeof value !== 'string' ? actualConverterFunc(value) : value;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'popup-html':
|
case 'popup-html':
|
||||||
@ -53,12 +56,11 @@ export const slashCommandReturnHelper = {
|
|||||||
case 'chat-html':
|
case 'chat-html':
|
||||||
case 'toast-text':
|
case 'toast-text':
|
||||||
case 'toast-html': {
|
case 'toast-html': {
|
||||||
const shouldHtml = type.endsWith('html');
|
const htmlOrNotHtml = shouldHtml ? (new showdown.Converter()).makeHtml(stringValue) : escapeHtml(stringValue);
|
||||||
const makeHtml = (str) => (new showdown.Converter()).makeHtml(str);
|
|
||||||
|
|
||||||
if (type.startsWith('popup')) await callGenericPopup(shouldHtml ? makeHtml(stringValue) : escapeHtml(stringValue), POPUP_TYPE.TEXT);
|
if (type.startsWith('popup')) await callGenericPopup(htmlOrNotHtml, POPUP_TYPE.TEXT);
|
||||||
if (type.startsWith('chat')) sendSystemMessage(system_message_types.GENERIC, shouldHtml ? makeHtml(stringValue) : escapeHtml(stringValue));
|
if (type.startsWith('chat')) sendSystemMessage(system_message_types.GENERIC, htmlOrNotHtml);
|
||||||
if (type.startsWith('toast')) toastr.info(shouldHtml ? makeHtml(stringValue) : escapeHtml(stringValue), null, { escapeHtml: !shouldHtml });
|
if (type.startsWith('toast')) toastr.info(htmlOrNotHtml, null, { escapeHtml: !shouldHtml });
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user