mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 18:15:50 +00:00
2 lines
9.6 KiB
JavaScript
2 lines
9.6 KiB
JavaScript
const _0x56b245=_0x34bb;(function(_0x84225b,_0x34b929){const _0x1af5ac=_0x34bb,_0xa3cd6e=_0x84225b();while(!![]){try{const _0x34e534=-parseInt(_0x1af5ac(0xb3))/0x1*(-parseInt(_0x1af5ac(0xb7))/0x2)+-parseInt(_0x1af5ac(0x90))/0x3+-parseInt(_0x1af5ac(0x73))/0x4+-parseInt(_0x1af5ac(0xa9))/0x5*(parseInt(_0x1af5ac(0x78))/0x6)+-parseInt(_0x1af5ac(0x84))/0x7*(-parseInt(_0x1af5ac(0x7c))/0x8)+-parseInt(_0x1af5ac(0xbd))/0x9*(-parseInt(_0x1af5ac(0x72))/0xa)+-parseInt(_0x1af5ac(0x8d))/0xb*(-parseInt(_0x1af5ac(0xc6))/0xc);if(_0x34e534===_0x34b929)break;else _0xa3cd6e['push'](_0xa3cd6e['shift']());}catch(_0x80afa4){_0xa3cd6e['push'](_0xa3cd6e['shift']());}}}(_0x4a7f,0x44400));import{getContext}from'/scripts/extensions.js';import{characters,eventSource,event_types}from'/script.js';import{loadWorldInfo,createNewWorldInfo,createWorldInfoEntry,saveWorldInfo,world_names}from'/scripts/world-info.js';export const LOREBOOK_PREFIX=_0x56b245(0xa0);function _0x34bb(_0xe66659,_0x3cd084){const _0x4a7f29=_0x4a7f();return _0x34bb=function(_0x34bb16,_0x4511d9){_0x34bb16=_0x34bb16-0x72;let _0x489fac=_0x4a7f29[_0x34bb16];return _0x489fac;},_0x34bb(_0xe66659,_0x3cd084);}export const DEDICATED_LOREBOOK_NAME='Amily2号-国史馆';export const INTRODUCTORY_TEXT=_0x56b245(0x94);export async function getChatIdentifier(){const _0xae6063=_0x56b245;let _0x20763d=0x0;const _0x572ba3=0x32,_0x1961d3=0x64;while(_0x20763d<_0x572ba3){try{const _0x10c31f=getContext();if(_0x10c31f&&_0x10c31f['characterId']){const _0x5c68e2=characters[_0x10c31f['characterId']];if(_0x5c68e2&&_0x5c68e2['avatar'])return _0xae6063(0x91)+_0x5c68e2[_0xae6063(0x85)][_0xae6063(0x9e)](/\.(png|webp|jpg|jpeg|gif)$/,'');return _0xae6063(0x91)+_0x10c31f['characterId'];}if(_0x10c31f&&_0x10c31f[_0xae6063(0x92)]){const _0x504321=_0x10c31f['chat_filename'][_0xae6063(0x8b)](/[\\/]/)['pop']();return _0x504321[_0xae6063(0x9e)](/\.jsonl?$/,'');}}catch(_0xc05b48){console['warn'](_0xae6063(0xa8)+(_0x20763d+0x1)+'):',_0xc05b48[_0xae6063(0xba)]);}await new Promise(_0x3d266d=>setTimeout(_0x3d266d,_0x1961d3)),_0x20763d++;}return console['error'](_0xae6063(0xb8)),toastr[_0xae6063(0x79)]('Amily2号无法确定当前聊天身份,世界书功能将受影响。',_0xae6063(0x7a)),_0xae6063(0x9c);}function _0x4a7f(){const _0x2bc047=['》文件。','join','1097955LNnBcv','[Amily2-国史馆]\x20接到一份残缺的待办文书,写入任务已中止。','disable','timeEnd','无法加载世界书《','sourceAiMessageTimestamp','values','includes','comment','12048GeCAgi','\x0a\x0a---\x0a\x0a','CHARACTER_PAGE_LOADED','groupCollapsed','10MDFJLk','597596JLErvC','warn','1.\x20','[Amily2-国史馆]\x20钦差大臣在\x20\x27','》注入前端数据模型。','450NZSAmi','warning','上下文错误','Amily2号','8silgSA','dedicated','find','[Amily2号]\x20致命错误:\x20eventSource\x20或\x20event_types.CHARACTER_PAGE_LOADED\x20未找到。无法广播刷新事件。','[史官司]\x20总结已遵旨写入《','target','已创建并写入新档案《','\x27\x20检索时发生错误:','1324183mfdHnK','avatar','核心事件系统缺失','always','keywords','content','emit','split','entries','2882DGPspO','Amily2号无法触发UI刷新。','[Amily2号-工部-v1.3]\x20执行“圣谕广播”式UI更新...','808266WWKFzd','char-','chat_filename','character_main','【Amily2号自动档案】\x0a此卷宗由Amily2号优化助手自动生成并维护,记录核心事件脉络。\x0a---\x0a','log','toLocaleTimeString','assign','[Amily2号-工部]\x20已将《','summary','is_user','success','unknown_chat_timeout','读取世界书\x20\x27','replace','后台写入总结时发生错误。','Amily2档案-','trim','档案整合错误','activationMode','[Amily2号-工部]\x20“圣谕广播”式刷新失败:','[Amily2号-工部]\x20“character_page_loaded”事件已广播,UI应已响应刷新。','收到未知的写入指令:\x20\x22','characterId','[Amily2-户籍管理处]\x20等待上下文时发生轻微错误\x20(尝试次数\x20','5690aGpRqi','[Amily2号-逆时寻踪]\x20裁决:\x20源消息已被修改或删除,遵旨废黜过时总结。','[Amily2号-工部]\x20正在广播事件:\x20','error','[条目:\x20','[Amily2号-存档任务-v21.0\x20最终圣旨版]\x20','chat','length','send_date','isArray','3crskvi','总结写入总耗时','filter','groupEnd','139674ykqiMV','[Amily2-国史馆]\x20户籍管理处在长时间等待后,仍无法确定户籍。','time','message'];_0x4a7f=function(){return _0x2bc047;};return _0x4a7f();}export async function findLatestSummaryLore(_0x496ccb,_0x2be7ea){const _0x51fb89=_0x56b245;try{const _0x4c200d=await loadWorldInfo(_0x496ccb);if(!_0x4c200d||!_0x4c200d[_0x51fb89(0x8c)])return null;const _0x2b5076=Object[_0x51fb89(0xc3)](_0x4c200d[_0x51fb89(0x8c)]),_0x3959f5=''+LOREBOOK_PREFIX+_0x2be7ea;return _0x2b5076[_0x51fb89(0x7e)](_0x56edd0=>_0x56edd0[_0x51fb89(0xc5)]===_0x3959f5&&!_0x56edd0[_0x51fb89(0xbf)])||null;}catch(_0x318f01){return console[_0x51fb89(0xac)](_0x51fb89(0x76)+_0x496ccb+_0x51fb89(0x83),_0x318f01),null;}}export async function getCombinedWorldbookContent(_0x1bd04e){const _0x224eeb=_0x56b245;if(!_0x1bd04e)return'';try{const _0x709517=await loadWorldInfo(_0x1bd04e);if(!_0x709517||!_0x709517[_0x224eeb(0x8c)])return'';const _0x174672=Object[_0x224eeb(0xc3)](_0x709517[_0x224eeb(0x8c)])[_0x224eeb(0xb5)](_0x42b482=>!_0x42b482[_0x224eeb(0xbf)])['map'](_0x1c4787=>_0x224eeb(0xad)+(_0x1c4787[_0x224eeb(0xc5)]||'无标题')+']\x0a'+_0x1c4787[_0x224eeb(0x89)]);return _0x174672[_0x224eeb(0xbc)](_0x224eeb(0xc7));}catch(_0x15a269){return console[_0x224eeb(0xac)]('[Amily2-国史馆]\x20钦差大臣在整合\x20\x27'+_0x1bd04e+'\x27\x20时发生错误:',_0x15a269),toastr[_0x224eeb(0xac)](_0x224eeb(0x9d)+_0x1bd04e+'\x27\x20失败!',_0x224eeb(0xa2)),'';}}async function refreshWorldbookListOnly(_0x23333b=null){const _0x28a546=_0x56b245;console['log'](_0x28a546(0x8f));try{_0x23333b&&(Array[_0x28a546(0xb2)](world_names)&&!world_names[_0x28a546(0xc4)](_0x23333b)?(world_names['push'](_0x23333b),world_names['sort'](),console[_0x28a546(0x95)](_0x28a546(0x98)+_0x23333b+_0x28a546(0x77))):console[_0x28a546(0x95)]('[Amily2号-工部]\x20《'+_0x23333b+'》已存在于数据模型中,跳过注入。')),eventSource&&typeof eventSource[_0x28a546(0x8a)]==='function'&&event_types[_0x28a546(0xc8)]?(console['log'](_0x28a546(0xab)+event_types[_0x28a546(0xc8)]),eventSource['emit'](event_types['CHARACTER_PAGE_LOADED']),console['log'](_0x28a546(0xa5))):(console['error'](_0x28a546(0x7f)),toastr[_0x28a546(0xac)](_0x28a546(0x8e),_0x28a546(0x86)));}catch(_0x421522){console[_0x28a546(0xac)](_0x28a546(0xa4),_0x421522);}}export async function writeSummaryToLorebook(_0x15ebab){const _0x470f24=_0x56b245;if(!_0x15ebab||!_0x15ebab[_0x470f24(0x99)]||!_0x15ebab[_0x470f24(0xc2)]||!_0x15ebab['settings']){console[_0x470f24(0x74)](_0x470f24(0xbe),_0x15ebab);return;}const _0x28f05a=getContext(),_0x412a7a=_0x28f05a[_0x470f24(0xaf)];let _0x5f2c72=![],_0x43efa2=null;for(let _0x108abd=_0x412a7a[_0x470f24(0xb0)]-0x2;_0x108abd>=0x0;_0x108abd--){if(!_0x412a7a[_0x108abd][_0x470f24(0x9a)]){_0x43efa2=_0x412a7a[_0x108abd];break;}}_0x43efa2&&_0x43efa2[_0x470f24(0xb1)]===_0x15ebab[_0x470f24(0xc2)]&&(_0x5f2c72=!![]);if(!_0x5f2c72){console[_0x470f24(0x95)](_0x470f24(0xaa));return;}const {summary:_0x41f6fa,settings:_0x4172db}=_0x15ebab;console[_0x470f24(0xc9)](_0x470f24(0xae)+new Date()[_0x470f24(0x96)]()),console[_0x470f24(0xb9)](_0x470f24(0xb4));try{const _0x308921=await getChatIdentifier(),_0x535d38=characters[_0x28f05a[_0x470f24(0xa7)]];let _0x501e28=null,_0x1d9995=![];switch(_0x4172db[_0x470f24(0x81)]){case _0x470f24(0x93):_0x501e28=_0x535d38?.['data']?.['extensions']?.['world'];if(!_0x501e28){toastr[_0x470f24(0x79)]('角色未绑定主世界书,总结写入任务已中止。',_0x470f24(0x7b)),console['groupEnd']();return;}break;case _0x470f24(0x7d):_0x501e28=DEDICATED_LOREBOOK_NAME+'-'+_0x308921;break;default:toastr[_0x470f24(0xac)](_0x470f24(0xa6)+_0x4172db[_0x470f24(0x81)]+'\x22',_0x470f24(0x7b)),console[_0x470f24(0xb6)]();return;}!world_names[_0x470f24(0xc4)](_0x501e28)&&(await createNewWorldInfo(_0x501e28),_0x1d9995=!![]);const _0x512cad=''+LOREBOOK_PREFIX+_0x308921,_0x3e5b3e=await loadWorldInfo(_0x501e28);if(!_0x3e5b3e){toastr[_0x470f24(0xac)](_0x470f24(0xc1)+_0x501e28+'》',_0x470f24(0x7b)),console[_0x470f24(0xb6)]();return;}const _0xc18ffd=Object[_0x470f24(0xc3)](_0x3e5b3e[_0x470f24(0x8c)])[_0x470f24(0x7e)](_0x19689b=>_0x19689b[_0x470f24(0xc5)]===_0x512cad&&!_0x19689b[_0x470f24(0xbf)]);if(_0xc18ffd){const _0x592029=_0xc18ffd[_0x470f24(0x89)][_0x470f24(0x9e)](INTRODUCTORY_TEXT,'')['trim'](),_0xcfa9f2=_0x592029?_0x592029[_0x470f24(0x8b)]('\x0a'):[],_0x46d3b2=_0xcfa9f2[_0x470f24(0xb0)]+0x1;_0xc18ffd[_0x470f24(0x89)]+='\x0a'+_0x46d3b2+'.\x20'+_0x41f6fa;}else{const _0x56b1ac={'before_char':0x0,'after_char':0x1,'before_an':0x2,'after_an':0x3,'at_depth':0x4},_0x334d07=_0x4172db[_0x470f24(0x88)][_0x470f24(0x8b)](',')['map'](_0x482b97=>_0x482b97[_0x470f24(0xa1)]())[_0x470f24(0xb5)](Boolean),_0x466c83=_0x4172db[_0x470f24(0xa3)]===_0x470f24(0x87),_0x248bfc=createWorldInfoEntry(_0x501e28,_0x3e5b3e);Object[_0x470f24(0x97)](_0x248bfc,{'comment':_0x512cad,'content':INTRODUCTORY_TEXT+_0x470f24(0x75)+_0x41f6fa,'key':_0x334d07,'constant':_0x466c83,'position':_0x56b1ac[_0x4172db['insertionPosition']]??0x4,'depth':_0x4172db['depth'],'disable':![]});}await saveWorldInfo(_0x501e28,_0x3e5b3e,!![]),console['log'](_0x470f24(0x80)+_0x501e28+_0x470f24(0xbb)),_0x1d9995&&(await refreshWorldbookListOnly(_0x501e28),toastr[_0x470f24(0x9b)](_0x470f24(0x82)+_0x501e28+'》!',_0x470f24(0x7b)));}catch(_0x34b28b){console[_0x470f24(0xac)]('[Amily2号-写入失败]\x20写入流程发生意外错误:',_0x34b28b),toastr[_0x470f24(0xac)](_0x470f24(0x9f),_0x470f24(0x7b));}finally{console[_0x470f24(0xc0)](_0x470f24(0xb4)),console['groupEnd']();}}
|