mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-03 03:17:54 +01:00
Merge pull request #2656 from SillyTavern/qr-new-chat
Quick Replies: Add auto-execute on new chat
This commit is contained in:
commit
c3caee759f
@ -204,6 +204,7 @@ export class QuickReplyApi {
|
|||||||
* @param {boolean} [props.executeOnAi] whether to execute the quick reply after the AI has sent a message
|
* @param {boolean} [props.executeOnAi] whether to execute the quick reply after the AI has sent a message
|
||||||
* @param {boolean} [props.executeOnChatChange] whether to execute the quick reply when a new chat is loaded
|
* @param {boolean} [props.executeOnChatChange] whether to execute the quick reply when a new chat is loaded
|
||||||
* @param {boolean} [props.executeOnGroupMemberDraft] whether to execute the quick reply when a group member is selected
|
* @param {boolean} [props.executeOnGroupMemberDraft] whether to execute the quick reply when a group member is selected
|
||||||
|
* @param {boolean} [props.executeOnNewChat] whether to execute the quick reply when a new chat is created
|
||||||
* @param {string} [props.automationId] when not empty, the quick reply will be executed when the WI with the given automation ID is activated
|
* @param {string} [props.automationId] when not empty, the quick reply will be executed when the WI with the given automation ID is activated
|
||||||
* @returns {QuickReply} the new quick reply
|
* @returns {QuickReply} the new quick reply
|
||||||
*/
|
*/
|
||||||
@ -218,6 +219,7 @@ export class QuickReplyApi {
|
|||||||
executeOnAi,
|
executeOnAi,
|
||||||
executeOnChatChange,
|
executeOnChatChange,
|
||||||
executeOnGroupMemberDraft,
|
executeOnGroupMemberDraft,
|
||||||
|
executeOnNewChat,
|
||||||
automationId,
|
automationId,
|
||||||
} = {}) {
|
} = {}) {
|
||||||
const set = this.getSetByName(setName);
|
const set = this.getSetByName(setName);
|
||||||
@ -236,6 +238,7 @@ export class QuickReplyApi {
|
|||||||
qr.executeOnAi = executeOnAi ?? false;
|
qr.executeOnAi = executeOnAi ?? false;
|
||||||
qr.executeOnChatChange = executeOnChatChange ?? false;
|
qr.executeOnChatChange = executeOnChatChange ?? false;
|
||||||
qr.executeOnGroupMemberDraft = executeOnGroupMemberDraft ?? false;
|
qr.executeOnGroupMemberDraft = executeOnGroupMemberDraft ?? false;
|
||||||
|
qr.executeOnNewChat = executeOnNewChat ?? false;
|
||||||
qr.automationId = automationId ?? '';
|
qr.automationId = automationId ?? '';
|
||||||
qr.onUpdate();
|
qr.onUpdate();
|
||||||
return qr;
|
return qr;
|
||||||
@ -258,6 +261,7 @@ export class QuickReplyApi {
|
|||||||
* @param {boolean} [props.executeOnAi] whether to execute the quick reply after the AI has sent a message
|
* @param {boolean} [props.executeOnAi] whether to execute the quick reply after the AI has sent a message
|
||||||
* @param {boolean} [props.executeOnChatChange] whether to execute the quick reply when a new chat is loaded
|
* @param {boolean} [props.executeOnChatChange] whether to execute the quick reply when a new chat is loaded
|
||||||
* @param {boolean} [props.executeOnGroupMemberDraft] whether to execute the quick reply when a group member is selected
|
* @param {boolean} [props.executeOnGroupMemberDraft] whether to execute the quick reply when a group member is selected
|
||||||
|
* @param {boolean} [props.executeOnNewChat] whether to execute the quick reply when a new chat is created
|
||||||
* @param {string} [props.automationId] when not empty, the quick reply will be executed when the WI with the given automation ID is activated
|
* @param {string} [props.automationId] when not empty, the quick reply will be executed when the WI with the given automation ID is activated
|
||||||
* @returns {QuickReply} the altered quick reply
|
* @returns {QuickReply} the altered quick reply
|
||||||
*/
|
*/
|
||||||
@ -273,6 +277,7 @@ export class QuickReplyApi {
|
|||||||
executeOnAi,
|
executeOnAi,
|
||||||
executeOnChatChange,
|
executeOnChatChange,
|
||||||
executeOnGroupMemberDraft,
|
executeOnGroupMemberDraft,
|
||||||
|
executeOnNewChat,
|
||||||
automationId,
|
automationId,
|
||||||
} = {}) {
|
} = {}) {
|
||||||
const qr = this.getQrByLabel(setName, label);
|
const qr = this.getQrByLabel(setName, label);
|
||||||
@ -290,6 +295,7 @@ export class QuickReplyApi {
|
|||||||
qr.executeOnAi = executeOnAi ?? qr.executeOnAi;
|
qr.executeOnAi = executeOnAi ?? qr.executeOnAi;
|
||||||
qr.executeOnChatChange = executeOnChatChange ?? qr.executeOnChatChange;
|
qr.executeOnChatChange = executeOnChatChange ?? qr.executeOnChatChange;
|
||||||
qr.executeOnGroupMemberDraft = executeOnGroupMemberDraft ?? qr.executeOnGroupMemberDraft;
|
qr.executeOnGroupMemberDraft = executeOnGroupMemberDraft ?? qr.executeOnGroupMemberDraft;
|
||||||
|
qr.executeOnNewChat = executeOnNewChat ?? qr.executeOnNewChat;
|
||||||
qr.automationId = automationId ?? qr.automationId;
|
qr.automationId = automationId ?? qr.automationId;
|
||||||
qr.onUpdate();
|
qr.onUpdate();
|
||||||
return qr;
|
return qr;
|
||||||
|
@ -108,6 +108,10 @@
|
|||||||
<input type="checkbox" id="qr--executeOnChatChange" >
|
<input type="checkbox" id="qr--executeOnChatChange" >
|
||||||
<span><i class="fa-solid fa-fw fa-message"></i><span data-i18n="Execute on chat change">Execute on chat change</span></span>
|
<span><i class="fa-solid fa-fw fa-message"></i><span data-i18n="Execute on chat change">Execute on chat change</span></span>
|
||||||
</label>
|
</label>
|
||||||
|
<label class="checkbox_label">
|
||||||
|
<input type="checkbox" id="qr--executeOnNewChat">
|
||||||
|
<span><i class="fa-solid fa-fw fa-comments"></i><span data-i18n="Execute on new chat">Execute on new chat</span></span>
|
||||||
|
</label>
|
||||||
<label class="checkbox_label">
|
<label class="checkbox_label">
|
||||||
<input type="checkbox" id="qr--executeOnGroupMemberDraft">
|
<input type="checkbox" id="qr--executeOnGroupMemberDraft">
|
||||||
<span><i class="fa-solid fa-fw fa-people-group"></i><span data-i18n="Execute on group member draft">Execute on group member draft</span></span>
|
<span><i class="fa-solid fa-fw fa-people-group"></i><span data-i18n="Execute on group member draft">Execute on group member draft</span></span>
|
||||||
|
@ -105,6 +105,7 @@ const loadSets = async () => {
|
|||||||
qr.executeOnAi = slot.autoExecute_botMessage ?? false;
|
qr.executeOnAi = slot.autoExecute_botMessage ?? false;
|
||||||
qr.executeOnChatChange = slot.autoExecute_chatLoad ?? false;
|
qr.executeOnChatChange = slot.autoExecute_chatLoad ?? false;
|
||||||
qr.executeOnGroupMemberDraft = slot.autoExecute_groupMemberDraft ?? false;
|
qr.executeOnGroupMemberDraft = slot.autoExecute_groupMemberDraft ?? false;
|
||||||
|
qr.executeOnNewChat = slot.autoExecute_newChat ?? false;
|
||||||
qr.automationId = slot.automationId ?? '';
|
qr.automationId = slot.automationId ?? '';
|
||||||
qr.contextList = (slot.contextMenu ?? []).map(it=>({
|
qr.contextList = (slot.contextMenu ?? []).map(it=>({
|
||||||
set: it.preset,
|
set: it.preset,
|
||||||
@ -260,3 +261,8 @@ const onWIActivation = async (entries) => {
|
|||||||
await autoExec.handleWIActivation(entries);
|
await autoExec.handleWIActivation(entries);
|
||||||
};
|
};
|
||||||
eventSource.on(event_types.WORLD_INFO_ACTIVATED, (...args) => executeIfReadyElseQueue(onWIActivation, args));
|
eventSource.on(event_types.WORLD_INFO_ACTIVATED, (...args) => executeIfReadyElseQueue(onWIActivation, args));
|
||||||
|
|
||||||
|
const onNewChat = async () => {
|
||||||
|
await autoExec.handleNewChat();
|
||||||
|
};
|
||||||
|
eventSource.on(event_types.CHAT_CREATED, (...args) => executeIfReadyElseQueue(onNewChat, args));
|
||||||
|
@ -83,6 +83,15 @@ export class AutoExecuteHandler {
|
|||||||
await this.performAutoExecute(qrList);
|
await this.performAutoExecute(qrList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async handleNewChat() {
|
||||||
|
if (!this.checkExecute()) return;
|
||||||
|
const qrList = [
|
||||||
|
...this.settings.config.setList.map(link=>link.set.qrList.filter(qr=>qr.executeOnNewChat)).flat(),
|
||||||
|
...(this.settings.chatConfig?.setList?.map(link=>link.set.qrList.filter(qr=>qr.executeOnNewChat))?.flat() ?? []),
|
||||||
|
];
|
||||||
|
await this.performAutoExecute(qrList);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {any[]} entries Set of activated entries
|
* @param {any[]} entries Set of activated entries
|
||||||
*/
|
*/
|
||||||
|
@ -44,6 +44,7 @@ export class QuickReply {
|
|||||||
/**@type {boolean}*/ executeOnAi = false;
|
/**@type {boolean}*/ executeOnAi = false;
|
||||||
/**@type {boolean}*/ executeOnChatChange = false;
|
/**@type {boolean}*/ executeOnChatChange = false;
|
||||||
/**@type {boolean}*/ executeOnGroupMemberDraft = false;
|
/**@type {boolean}*/ executeOnGroupMemberDraft = false;
|
||||||
|
/**@type {boolean}*/ executeOnNewChat = false;
|
||||||
/**@type {string}*/ automationId = '';
|
/**@type {string}*/ automationId = '';
|
||||||
|
|
||||||
/**@type {function}*/ onExecute;
|
/**@type {function}*/ onExecute;
|
||||||
@ -1061,6 +1062,13 @@ export class QuickReply {
|
|||||||
this.updateContext();
|
this.updateContext();
|
||||||
});
|
});
|
||||||
/**@type {HTMLInputElement}*/
|
/**@type {HTMLInputElement}*/
|
||||||
|
const executeOnNewChat = dom.querySelector('#qr--executeOnNewChat');
|
||||||
|
executeOnNewChat.checked = this.executeOnNewChat;
|
||||||
|
executeOnNewChat.addEventListener('click', ()=>{
|
||||||
|
this.executeOnNewChat = executeOnNewChat.checked;
|
||||||
|
this.updateContext();
|
||||||
|
});
|
||||||
|
/**@type {HTMLInputElement}*/
|
||||||
const automationId = dom.querySelector('#qr--automationId');
|
const automationId = dom.querySelector('#qr--automationId');
|
||||||
automationId.value = this.automationId;
|
automationId.value = this.automationId;
|
||||||
automationId.addEventListener('input', () => {
|
automationId.addEventListener('input', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user