Quick Replies: Add auto-execute on new chat

This commit is contained in:
Cohee
2024-08-14 00:08:16 +03:00
parent 78bee4631d
commit 06d300ad36
5 changed files with 33 additions and 0 deletions

View File

@ -83,6 +83,15 @@ export class AutoExecuteHandler {
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
*/

View File

@ -44,6 +44,7 @@ export class QuickReply {
/**@type {boolean}*/ executeOnAi = false;
/**@type {boolean}*/ executeOnChatChange = false;
/**@type {boolean}*/ executeOnGroupMemberDraft = false;
/**@type {boolean}*/ executeOnNewChat = false;
/**@type {string}*/ automationId = '';
/**@type {function}*/ onExecute;
@ -1061,6 +1062,13 @@ export class QuickReply {
this.updateContext();
});
/**@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');
automationId.value = this.automationId;
automationId.addEventListener('input', () => {