mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-10 00:50:43 +01:00
Auto-executable QR
This commit is contained in:
parent
7841f3d91f
commit
e593dd4dbd
@ -17,5 +17,16 @@
|
||||
<div class="quickReply_contextMenuEditor_actions">
|
||||
<span id="quickReply_contextMenuEditor_addPreset" class="menu_button menu_button_icon fa-solid fa-plus" title="Add preset to context menu"></span>
|
||||
</div>
|
||||
<h3><strong>Auto-Execute</strong></h3>
|
||||
<div class="flex-container flexFlowColumn">
|
||||
<label class="checkbox_label" for="quickReply_autoExecute_userMessage">
|
||||
<input type="checkbox" id="quickReply_autoExecute_userMessage" >
|
||||
<span><i class="fa-solid fa-fw fa-user"></i> Execute on user message</span>
|
||||
</label>
|
||||
<label class="checkbox_label" for="quickReply_autoExecute_botMessage">
|
||||
<input type="checkbox" id="quickReply_autoExecute_botMessage" >
|
||||
<span><i class="fa-solid fa-fw fa-robot"></i> Execute on AI message</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { saveSettingsDebounced, callPopup, getRequestHeaders, substituteParams } from "../../../script.js";
|
||||
import { saveSettingsDebounced, callPopup, getRequestHeaders, substituteParams, eventSource, event_types } from "../../../script.js";
|
||||
import { getContext, extension_settings } from "../../extensions.js";
|
||||
import { initScrollHeight, resetScrollHeight, getSortableDelay } from "../../utils.js";
|
||||
import { executeSlashCommands, registerSlashCommand } from "../../slash-commands.js";
|
||||
@ -152,6 +152,21 @@ async function onQuickReplyCtxButtonClick(id) {
|
||||
stop: () => { },
|
||||
});
|
||||
|
||||
$('#quickReply_autoExecute_userMessage').prop('checked', qr.autoExecute_userMessage ?? false);
|
||||
$('#quickReply_autoExecute_botMessage').prop('checked', qr.autoExecute_botMessage ?? false);
|
||||
|
||||
$('#quickReply_autoExecute_userMessage').on('input', () => {
|
||||
const state = !!$('#quickReply_autoExecute_userMessage').prop('checked');
|
||||
qr.autoExecute_userMessage = state;
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#quickReply_autoExecute_botMessage').on('input', () => {
|
||||
const state = !!$('#quickReply_autoExecute_botMessage').prop('checked');
|
||||
qr.autoExecute_botMessage = state;
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
if (await popupResult) {
|
||||
qr.contextMenu = Array.from(document.querySelectorAll('#quickReply_contextMenuEditor_content > .quickReplyContextMenuEditor_item'))
|
||||
.map(item => ({
|
||||
@ -545,6 +560,24 @@ function saveQROrder() {
|
||||
});
|
||||
}
|
||||
|
||||
async function onMessageReceived() {
|
||||
for (let i = 0; i < extension_settings.quickReply.numberOfSlots; i++) {
|
||||
const qr = extension_settings.quickReply.quickReplySlots[i];
|
||||
if (qr?.autoExecute_botMessage) {
|
||||
await sendQuickReply(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function onMessageSent() {
|
||||
for (let i = 0; i < extension_settings.quickReply.numberOfSlots; i++) {
|
||||
const qr = extension_settings.quickReply.quickReplySlots[i];
|
||||
if (qr?.autoExecute_userMessage) {
|
||||
await sendQuickReply(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jQuery(async () => {
|
||||
moduleWorker();
|
||||
setInterval(moduleWorker, UPDATE_INTERVAL);
|
||||
@ -625,6 +658,9 @@ jQuery(async () => {
|
||||
|
||||
await loadSettings('init');
|
||||
addQuickReplyBar();
|
||||
|
||||
eventSource.on(event_types.MESSAGE_RECEIVED, onMessageReceived);
|
||||
eventSource.on(event_types.MESSAGE_SENT, onMessageSent);
|
||||
});
|
||||
|
||||
jQuery(() => {
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { MenuItem } from "./MenuItem.js";
|
||||
import { SubMenu } from "./SubMenu.js";
|
||||
|
||||
export class MenuHeader extends MenuItem {
|
||||
constructor(/**@type {String}*/label) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { chat_metadata, getCurrentChatId, sendSystemMessage, system_message_types } from "../script.js";
|
||||
import { extension_settings } from "./extensions.js";
|
||||
import { chat_metadata, getCurrentChatId, saveSettingsDebounced, sendSystemMessage, system_message_types } from "../script.js";
|
||||
import { extension_settings, saveMetadataDebounced } from "./extensions.js";
|
||||
import { executeSlashCommands, registerSlashCommand } from "./slash-commands.js";
|
||||
|
||||
function getLocalVariable(name) {
|
||||
@ -18,6 +18,7 @@ function setLocalVariable(name, value) {
|
||||
}
|
||||
|
||||
chat_metadata.variables[name] = value;
|
||||
saveMetadataDebounced();
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -29,6 +30,7 @@ function getGlobalVariable(name) {
|
||||
|
||||
function setGlobalVariable(name, value) {
|
||||
extension_settings.variables.global[name] = value;
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
function addLocalVariable(name, value) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user