Add QR auto-exec on app startup
This commit is contained in:
parent
9587a704c5
commit
c328d6f04a
|
@ -285,6 +285,7 @@ window["SillyTavern"] = {};
|
|||
|
||||
// Event source init
|
||||
export const event_types = {
|
||||
APP_READY: 'app_ready',
|
||||
EXTRAS_CONNECTED: 'extras_connected',
|
||||
MESSAGE_SWIPED: 'message_swiped',
|
||||
MESSAGE_SENT: 'message_sent',
|
||||
|
@ -744,6 +745,7 @@ async function firstLoadInit() {
|
|||
initCfg();
|
||||
doDailyExtensionUpdatesCheck();
|
||||
hideLoader();
|
||||
await eventSource.emit(event_types.APP_READY);
|
||||
}
|
||||
|
||||
function cancelStatusCheck() {
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
<input type="checkbox" id="quickReply_hidden" >
|
||||
<span><i class="fa-solid fa-fw fa-eye-slash"></i> Invisible (auto-execute only)</span>
|
||||
</label>
|
||||
<label class="checkbox_label" for="quickReply_autoExecute_appStartup">
|
||||
<input type="checkbox" id="quickReply_autoExecute_appStartup" >
|
||||
<span><i class="fa-solid fa-fw fa-rocket"></i> Execute on app startup</span>
|
||||
</label>
|
||||
<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>
|
||||
|
|
|
@ -155,6 +155,7 @@ async function onQuickReplyCtxButtonClick(id) {
|
|||
$('#quickReply_autoExecute_userMessage').prop('checked', qr.autoExecute_userMessage ?? false);
|
||||
$('#quickReply_autoExecute_botMessage').prop('checked', qr.autoExecute_botMessage ?? false);
|
||||
$('#quickReply_autoExecute_chatLoad').prop('checked', qr.autoExecute_chatLoad ?? false);
|
||||
$('#quickReply_autoExecute_appStartup').prop('checked', qr.autoExecute_appStartup ?? false);
|
||||
$('#quickReply_hidden').prop('checked', qr.hidden ?? false);
|
||||
|
||||
$('#quickReply_hidden').on('input', () => {
|
||||
|
@ -163,6 +164,12 @@ async function onQuickReplyCtxButtonClick(id) {
|
|||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#quickReply_autoExecute_appStartup').on('input', () => {
|
||||
const state = !!$('#quickReply_autoExecute_appStartup').prop('checked');
|
||||
qr.autoExecute_appStartup = state;
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#quickReply_autoExecute_userMessage').on('input', () => {
|
||||
const state = !!$('#quickReply_autoExecute_userMessage').prop('checked');
|
||||
qr.autoExecute_userMessage = state;
|
||||
|
@ -647,6 +654,21 @@ async function onChatChanged(chatId) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes quick replies on app ready.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function onAppReady() {
|
||||
if (!extension_settings.quickReply.quickReplyEnabled) return;
|
||||
|
||||
for (let i = 0; i < extension_settings.quickReply.numberOfSlots; i++) {
|
||||
const qr = extension_settings.quickReply.quickReplySlots[i];
|
||||
if (qr?.autoExecute_appStartup) {
|
||||
await sendQuickReply(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jQuery(async () => {
|
||||
moduleWorker();
|
||||
setInterval(moduleWorker, UPDATE_INTERVAL);
|
||||
|
@ -731,6 +753,7 @@ jQuery(async () => {
|
|||
eventSource.on(event_types.MESSAGE_RECEIVED, onMessageReceived);
|
||||
eventSource.on(event_types.MESSAGE_SENT, onMessageSent);
|
||||
eventSource.on(event_types.CHAT_CHANGED, onChatChanged);
|
||||
eventSource.on(event_types.APP_READY, onAppReady);
|
||||
});
|
||||
|
||||
jQuery(() => {
|
||||
|
|
Loading…
Reference in New Issue