mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Remove custom Handlebars helpers for extensions.
This commit is contained in:
		| @@ -145,7 +145,7 @@ import { | |||||||
|     Stopwatch, |     Stopwatch, | ||||||
| } from './scripts/utils.js'; | } from './scripts/utils.js'; | ||||||
|  |  | ||||||
| import { ModuleWorkerWrapper, doDailyExtensionUpdatesCheck, extension_settings, getContext, loadExtensionSettings, processExtensionHelpers, registerExtensionHelper, renderExtensionTemplate, runGenerationInterceptors, saveMetadataDebounced } from './scripts/extensions.js'; | import { ModuleWorkerWrapper, doDailyExtensionUpdatesCheck, extension_settings, getContext, loadExtensionSettings, renderExtensionTemplate, runGenerationInterceptors, saveMetadataDebounced } from './scripts/extensions.js'; | ||||||
| import { COMMENT_NAME_DEFAULT, executeSlashCommands, getSlashCommandsHelp, processChatSlashCommands, registerSlashCommand } from './scripts/slash-commands.js'; | import { COMMENT_NAME_DEFAULT, executeSlashCommands, getSlashCommandsHelp, processChatSlashCommands, registerSlashCommand } from './scripts/slash-commands.js'; | ||||||
| import { | import { | ||||||
|     tag_map, |     tag_map, | ||||||
| @@ -338,8 +338,6 @@ export const event_types = { | |||||||
|  |  | ||||||
| export const eventSource = new EventEmitter(); | export const eventSource = new EventEmitter(); | ||||||
|  |  | ||||||
| eventSource.on(event_types.MESSAGE_RECEIVED, processExtensionHelpers); |  | ||||||
| eventSource.on(event_types.MESSAGE_SENT, processExtensionHelpers); |  | ||||||
| eventSource.on(event_types.CHAT_CHANGED, processChatSlashCommands); | eventSource.on(event_types.CHAT_CHANGED, processChatSlashCommands); | ||||||
|  |  | ||||||
| const characterGroupOverlay = new BulkEditOverlay(); | const characterGroupOverlay = new BulkEditOverlay(); | ||||||
| @@ -7164,7 +7162,10 @@ window['SillyTavern'].getContext = function () { | |||||||
|         saveReply, |         saveReply, | ||||||
|         registerSlashCommand: registerSlashCommand, |         registerSlashCommand: registerSlashCommand, | ||||||
|         executeSlashCommands: executeSlashCommands, |         executeSlashCommands: executeSlashCommands, | ||||||
|         registerHelper: registerExtensionHelper, |         /** | ||||||
|  |          * @deprecated Handlebars for extensions are no longer supported. | ||||||
|  |          */ | ||||||
|  |         registerHelper: () => {}, | ||||||
|         registedDebugFunction: registerDebugFunction, |         registedDebugFunction: registerDebugFunction, | ||||||
|         renderExtensionTemplate: renderExtensionTemplate, |         renderExtensionTemplate: renderExtensionTemplate, | ||||||
|         callPopup: callPopup, |         callPopup: callPopup, | ||||||
|   | |||||||
| @@ -47,8 +47,6 @@ export function saveMetadataDebounced() { | |||||||
|     }, 1000); |     }, 1000); | ||||||
| } | } | ||||||
|  |  | ||||||
| export const extensionsHandlebars = Handlebars.create(); |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Provides an ability for extensions to render HTML templates. |  * Provides an ability for extensions to render HTML templates. | ||||||
|  * Templates sanitation and localization is forced. |  * Templates sanitation and localization is forced. | ||||||
| @@ -61,40 +59,6 @@ export function renderExtensionTemplate(extensionName, templateId, templateData | |||||||
|     return renderTemplate(`scripts/extensions/${extensionName}/${templateId}.html`, templateData, sanitize, localize, true); |     return renderTemplate(`scripts/extensions/${extensionName}/${templateId}.html`, templateData, sanitize, localize, true); | ||||||
| } | } | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Registers a Handlebars helper for use in extensions. |  | ||||||
|  * @param {string} name Handlebars helper name |  | ||||||
|  * @param {function} helper Handlebars helper function |  | ||||||
|  */ |  | ||||||
| export function registerExtensionHelper(name, helper) { |  | ||||||
|     extensionsHandlebars.registerHelper(name, helper); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Applies handlebars extension helpers to a message. |  | ||||||
|  * @param {number} messageId Message index in the chat. |  | ||||||
|  */ |  | ||||||
| export function processExtensionHelpers(messageId) { |  | ||||||
|     const context = getContext(); |  | ||||||
|     const message = context.chat[messageId]; |  | ||||||
|  |  | ||||||
|     if (!message?.mes || typeof message.mes !== 'string') { |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     // Don't waste time if there are no mustaches |  | ||||||
|     if (!substituteParams(message.mes).includes('{{')) { |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     try { |  | ||||||
|         const template = extensionsHandlebars.compile(substituteParams(message.mes), { noEscape: true }); |  | ||||||
|         message.mes = template({}); |  | ||||||
|     } catch { |  | ||||||
|         // Ignore |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // Disables parallel updates | // Disables parallel updates | ||||||
| class ModuleWorkerWrapper { | class ModuleWorkerWrapper { | ||||||
|     constructor(callback) { |     constructor(callback) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user