Files
ST-Amily2-Chat-Optimisation/core/commands.js
2025-07-13 18:29:12 +08:00

2 lines
8.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
(function(_0x32181e,_0x25259b){const _0x3cfe5e=_0x1aeb,_0x1dc992=_0x32181e();while(!![]){try{const _0x101bbf=-parseInt(_0x3cfe5e(0x15d))/0x1*(-parseInt(_0x3cfe5e(0x164))/0x2)+-parseInt(_0x3cfe5e(0x159))/0x3+-parseInt(_0x3cfe5e(0x141))/0x4*(-parseInt(_0x3cfe5e(0x14e))/0x5)+-parseInt(_0x3cfe5e(0x13c))/0x6*(parseInt(_0x3cfe5e(0x14c))/0x7)+parseInt(_0x3cfe5e(0x162))/0x8+parseInt(_0x3cfe5e(0x150))/0x9+-parseInt(_0x3cfe5e(0x167))/0xa;if(_0x101bbf===_0x25259b)break;else _0x1dc992['push'](_0x1dc992['shift']());}catch(_0x55e432){_0x1dc992['push'](_0x1dc992['shift']());}}}(_0xadc3,0xd2aa0));import{getContext,extension_settings}from'/scripts/extensions.js';import{saveChatConditional,reloadCurrentChat}from'/script.js';import{extensionName}from'../utils/settings.js';import{SlashCommand}from'/scripts/slash-commands/SlashCommand.js';import{SlashCommandParser}from'/scripts/slash-commands/SlashCommandParser.js';function _0x1aeb(_0x3a818a,_0x4e54e8){const _0xadc363=_0xadc3();return _0x1aeb=function(_0x1aeb3b,_0x576b9b){_0x1aeb3b=_0x1aeb3b-0x13b;let _0x3994d0=_0xadc363[_0x1aeb3b];return _0x3994d0;},_0x1aeb(_0x3a818a,_0x4e54e8);}import{checkAndFixWithAPI}from'./api.js';async function checkLatestMessage(){const _0x5cd5e5=_0x1aeb,_0xe48b27=getContext(),_0xecf976=_0xe48b27['chat']||[];if(!_0xecf976||_0xecf976[_0x5cd5e5(0x145)]===0x0)return console[_0x5cd5e5(0x148)](_0x5cd5e5(0x161)),{'message':null,'previousMessages':[]};const _0x102bbc=_0xecf976[_0xecf976[_0x5cd5e5(0x145)]-0x1];console['log'](_0x5cd5e5(0x157),{'isUser':_0x102bbc[_0x5cd5e5(0x16f)],'messagePreview':_0x102bbc['mes']?.[_0x5cd5e5(0x14d)](0x0,0x32)+_0x5cd5e5(0x15c)});if(_0x102bbc[_0x5cd5e5(0x16f)])return console[_0x5cd5e5(0x148)](_0x5cd5e5(0x14a)),{'message':_0x102bbc,'previousMessages':[]};const _0x4b888c=extension_settings[extensionName],_0x2bb9de=_0x4b888c[_0x5cd5e5(0x160)]||0x2,_0xce015f=Math[_0x5cd5e5(0x172)](0x0,_0xecf976[_0x5cd5e5(0x145)]-_0x2bb9de-0x1),_0x43b48f=_0xecf976[_0x5cd5e5(0x155)](_0xce015f,_0xecf976['length']-0x1);return console[_0x5cd5e5(0x148)]('[Amily2-命令检查器]\x20已获取上下文消息:',{'count':_0x43b48f[_0x5cd5e5(0x145)]}),{'message':_0x102bbc,'previousMessages':_0x43b48f};}async function checkCommand(){const _0x5c6f2d=_0x1aeb,_0x447b34=extension_settings[extensionName];if(!_0x447b34['apiUrl'])return toastr[_0x5c6f2d(0x163)](_0x5c6f2d(0x143),_0x5c6f2d(0x146)),'';const _0x2addfc=await checkLatestMessage();if(!_0x2addfc[_0x5c6f2d(0x152)]||_0x2addfc['message'][_0x5c6f2d(0x16f)])return toastr[_0x5c6f2d(0x149)]('最新消息是用户消息,无需检查',_0x5c6f2d(0x146)),'';toastr['info'](_0x5c6f2d(0x151),_0x5c6f2d(0x146));const _0x194d63=await checkAndFixWithAPI(_0x2addfc[_0x5c6f2d(0x152)],_0x2addfc[_0x5c6f2d(0x173)]);return _0x194d63&&_0x194d63[_0x5c6f2d(0x16a)]&&_0x194d63['optimizedContent']!==_0x2addfc[_0x5c6f2d(0x152)]['mes']?toastr['warning'](_0x5c6f2d(0x16b),'命令检查器'):toastr['success'](_0x5c6f2d(0x14f),_0x5c6f2d(0x146)),'';}function _0xadc3(){const _0x10939d=['info','[Amily2-命令检查器]\x20目标为用户消息跳过。','[Amily2]\x20命令注册过程中发生意外错误:','2890321zvQITq','substring','725oVzRXy','未检测到问题','3173184xvDXoC','正在使用API检查回复...','message','检查最新的AI回复是否有问题','addCommandObject','slice','chat','[Amily2-命令检查器]\x20正在侦测消息:','fromProps','4492509HgXkBQ','test-reply-checker','未检测到需要修复的问题','...','9023KkxhFT','[Amily2-新诏]\x20/fix-reply\x20命令已成功颁布。','修复最新的AI回复中的问题','contextMessages','[Amily2-命令检查器]\x20没有聊天记录。','10413416cmdUDG','error','194TLtfmX','[Amily2-新诏]\x20/check-reply\x20命令已成功颁布。','最后一条消息是用户消息,无法测试','8490630apVALy','测试结果API未检测到问题请检查API配置或提示词','测试成功API检测到重复内容并提供了修复建议','optimizedContent','检测到问题,建议使用修复功能','undefined','没有找到可用于测试的AI消息','正在检查并修复回复...','is_user','测试聊天回复检查器功能','最新消息是用户消息,无需修复','max','previousMessages','需要至少2条消息才能测试','6amDjCy','[Amily2-新诏]\x20/test-reply-checker\x20命令已成功颁布。','apiUrl','mes','正在使用API测试检测功能...','30148vhMmVw','success','请先配置API\x20URL','check-reply','length','命令检查器','warning','log'];_0xadc3=function(){return _0x10939d;};return _0xadc3();}export async function fixCommand(){const _0x200418=_0x1aeb,_0x4b76c5=extension_settings[extensionName];if(!_0x4b76c5[_0x200418(0x13e)])return toastr[_0x200418(0x163)](_0x200418(0x143),_0x200418(0x146)),'';const _0x3c0054=getContext(),_0x157381=_0x3c0054[_0x200418(0x156)];if(!_0x157381||_0x157381['length']===0x0)return toastr['info']('没有可修复的消息',_0x200418(0x146)),'';const _0x593578=_0x157381[_0x157381[_0x200418(0x145)]-0x1];if(_0x593578[_0x200418(0x16f)])return toastr[_0x200418(0x149)](_0x200418(0x171),_0x200418(0x146)),'';const _0x733275=_0x4b76c5[_0x200418(0x160)]||0x2,_0x32a882=Math[_0x200418(0x172)](0x0,_0x157381[_0x200418(0x145)]-0x1-_0x733275),_0x598bef=_0x157381[_0x200418(0x155)](_0x32a882,_0x157381[_0x200418(0x145)]-0x1);toastr[_0x200418(0x149)](_0x200418(0x16e),_0x200418(0x146));const _0x4436fa=await checkAndFixWithAPI(_0x593578,_0x598bef);return _0x4436fa&&_0x4436fa['optimizedContent']&&_0x4436fa[_0x200418(0x16a)]!==_0x593578[_0x200418(0x13f)]?(_0x593578[_0x200418(0x13f)]=_0x4436fa[_0x200418(0x16a)],await saveChatConditional(),await reloadCurrentChat(),toastr[_0x200418(0x142)]('回复已修复',_0x200418(0x146))):toastr[_0x200418(0x149)](_0x200418(0x15b),_0x200418(0x146)),'';}export async function testReplyChecker(){const _0x483fd7=_0x1aeb,_0x4d5ec3=extension_settings[extensionName];if(!_0x4d5ec3[_0x483fd7(0x13e)])return toastr[_0x483fd7(0x163)](_0x483fd7(0x143),_0x483fd7(0x146)),'';const _0x2d05eb=getContext(),_0x431bb0=_0x2d05eb[_0x483fd7(0x156)];if(!_0x431bb0||_0x431bb0[_0x483fd7(0x145)]<0x2)return toastr[_0x483fd7(0x147)](_0x483fd7(0x13b),_0x483fd7(0x146)),'';let _0x549108=null;for(let _0x1342f5=_0x431bb0['length']-0x2;_0x1342f5>=0x0;_0x1342f5--){if(!_0x431bb0[_0x1342f5][_0x483fd7(0x16f)]){_0x549108=_0x431bb0[_0x1342f5][_0x483fd7(0x13f)];break;}}if(!_0x549108)return toastr[_0x483fd7(0x147)](_0x483fd7(0x16d),_0x483fd7(0x146)),'';const _0x1d9c6=_0x431bb0[_0x431bb0[_0x483fd7(0x145)]-0x1];if(_0x1d9c6[_0x483fd7(0x16f)])return toastr[_0x483fd7(0x147)](_0x483fd7(0x166),'命令检查器'),'';const _0xe667a2=_0x1d9c6[_0x483fd7(0x13f)];_0x1d9c6[_0x483fd7(0x13f)]=_0x549108+'\x0a\x0a'+_0x549108,toastr[_0x483fd7(0x149)](_0x483fd7(0x140),'命令检查器');const _0x119215=_0x4d5ec3['contextMessages']||0x2,_0x394d5c=Math[_0x483fd7(0x172)](0x0,_0x431bb0[_0x483fd7(0x145)]-_0x119215-0x1),_0x5e1927=_0x431bb0[_0x483fd7(0x155)](_0x394d5c,_0x431bb0[_0x483fd7(0x145)]-0x1),_0x5472a9=await checkAndFixWithAPI(_0x1d9c6,_0x5e1927);return _0x1d9c6['mes']=_0xe667a2,_0x5472a9&&_0x5472a9[_0x483fd7(0x16a)]&&_0x5472a9['optimizedContent']!==_0x549108+'\x0a\x0a'+_0x549108?toastr['success'](_0x483fd7(0x169),_0x483fd7(0x146)):toastr[_0x483fd7(0x147)](_0x483fd7(0x168),_0x483fd7(0x146)),'';}export async function registerSlashCommands(){const _0x3363ce=_0x1aeb;try{if(typeof SlashCommand===_0x3363ce(0x16c)||typeof SlashCommandParser===_0x3363ce(0x16c)){console[_0x3363ce(0x163)]('[Amily2]\x20致命错误SlashCommand\x20或\x20SlashCommandParser\x20模块未能加载。');return;}SlashCommandParser['addCommandObject'](SlashCommand[_0x3363ce(0x158)]({'name':_0x3363ce(0x144),'callback':checkCommand,'helpString':_0x3363ce(0x153)})),console['log'](_0x3363ce(0x165)),SlashCommandParser[_0x3363ce(0x154)](SlashCommand[_0x3363ce(0x158)]({'name':'fix-reply','callback':fixCommand,'helpString':_0x3363ce(0x15f)})),console['log'](_0x3363ce(0x15e)),SlashCommandParser[_0x3363ce(0x154)](SlashCommand[_0x3363ce(0x158)]({'name':_0x3363ce(0x15a),'callback':testReplyChecker,'helpString':_0x3363ce(0x170)})),console[_0x3363ce(0x148)](_0x3363ce(0x13d));}catch(_0x16a847){console[_0x3363ce(0x163)](_0x3363ce(0x14b),_0x16a847);}}