mirror of
https://github.com/Wx-2025/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 12:45:51 +00:00
Update autoHideManager.js
This commit is contained in:
@@ -1,105 +1 @@
|
||||
import { getContext, extension_settings } from "/scripts/extensions.js";
|
||||
import { SlashCommandParser } from "/scripts/slash-commands/SlashCommandParser.js";
|
||||
import { extensionName } from "../utils/settings.js";
|
||||
|
||||
|
||||
async function executeSlashCommand(commandString) {
|
||||
if (!commandString) return;
|
||||
try {
|
||||
console.log(`[Amily-敕令执行官] 准备执行圣谕: ${commandString}`);
|
||||
const parser = new SlashCommandParser();
|
||||
const closure = parser.parse(commandString, false);
|
||||
|
||||
if (closure && typeof closure.execute === 'function') {
|
||||
await closure.execute();
|
||||
console.log(`[Amily-敕令执行官] 圣谕: "${commandString}" 已成功颁布。`);
|
||||
toastr.success(`圣谕 "${commandString}" 已成功颁布`, "敕令司回报");
|
||||
} else {
|
||||
const errorMsg = `铸造出的圣谕法印无法执行!指令: ${commandString}`;
|
||||
console.error(`[Amily-敕令执行官] ${errorMsg}`);
|
||||
toastr.error(errorMsg, "敕令司紧急报告");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`[Amily-敕令执行官] 执行圣谕 "${commandString}" 时发生意外:`, error);
|
||||
toastr.error(`执行圣谕时发生意外: ${error.message}`, "敕令司紧急报告");
|
||||
}
|
||||
}
|
||||
|
||||
export async function executeAutoHide() {
|
||||
try {
|
||||
const settings = extension_settings[extensionName];
|
||||
if (!settings.autoHideEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const threshold = settings.autoHideThreshold || 30;
|
||||
|
||||
const context = getContext();
|
||||
const chatLength = context.chat.length;
|
||||
|
||||
|
||||
const hideUntilIndex = chatLength - threshold - 1;
|
||||
if (hideUntilIndex < 0) {;
|
||||
return;
|
||||
}
|
||||
|
||||
const commandString = `/hide 0-${hideUntilIndex}`;
|
||||
console.log(`[Amily-史册管理员] 颁布圣谕: ${commandString}`);
|
||||
const parser = new SlashCommandParser();
|
||||
const closure = parser.parse(commandString, false);
|
||||
|
||||
if (closure && typeof closure.execute === 'function') {
|
||||
await closure.execute();
|
||||
console.log(`[Amily-史册管理员] 圣谕颁布成功。`);
|
||||
} else {
|
||||
console.error('[Amily-史册管理员] 致命错误:铸造出的圣谕法印无法执行!');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('[Amily-史册管理员] 执行自动隐藏律法时发生意外错误:', error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function executeManualCommand(commandType, params = {}) {
|
||||
const { from, to } = params;
|
||||
|
||||
let commandString = '';
|
||||
|
||||
switch (commandType) {
|
||||
case 'unhide_all': {
|
||||
const chatLength = getContext().chat.length;
|
||||
if (chatLength > 0) {
|
||||
const lastIndex = chatLength - 1;
|
||||
commandString = `/unhide 0-${lastIndex}`;
|
||||
} else {
|
||||
toastr.info("史册为空,无需解除隐藏。", "敕令司回报");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'manual_hide':
|
||||
case 'manual_unhide': {
|
||||
const command = commandType === 'manual_hide' ? '/hide' : '/unhide';
|
||||
if (from === '' && to !== '') {
|
||||
commandString = `${command} ${to}`;
|
||||
} else if (from !== '' && to !== '') {
|
||||
if (parseInt(from) > parseInt(to)) {
|
||||
toastr.warning("起始层不能大于结束层", "敕令司提示");
|
||||
return;
|
||||
}
|
||||
commandString = `${command} ${from}-${to}`;
|
||||
} else {
|
||||
toastr.warning("请输入有效的楼层范围", "敕令司提示");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
console.error(`[Amily-手动敕令司] 未知的命令类型: ${commandType}`);
|
||||
return;
|
||||
}
|
||||
|
||||
await executeSlashCommand(commandString);
|
||||
}
|
||||
function _0x440b(_0x21e839,_0x2b4520){const _0x338e39=_0x338e();return _0x440b=function(_0x440bfe,_0x21a906){_0x440bfe=_0x440bfe-0x1e4;let _0x4ab131=_0x338e39[_0x440bfe];return _0x4ab131;},_0x440b(_0x21e839,_0x2b4520);}(function(_0x40a705,_0x59d020){const _0x62765b=_0x440b,_0x11a1b1=_0x40a705();while(!![]){try{const _0x16d980=parseInt(_0x62765b(0x1fd))/0x1+parseInt(_0x62765b(0x206))/0x2*(parseInt(_0x62765b(0x207))/0x3)+parseInt(_0x62765b(0x1e4))/0x4+parseInt(_0x62765b(0x203))/0x5*(-parseInt(_0x62765b(0x1f6))/0x6)+-parseInt(_0x62765b(0x1ee))/0x7+-parseInt(_0x62765b(0x1f7))/0x8*(parseInt(_0x62765b(0x1f1))/0x9)+parseInt(_0x62765b(0x20a))/0xa*(parseInt(_0x62765b(0x1fb))/0xb);if(_0x16d980===_0x59d020)break;else _0x11a1b1['push'](_0x11a1b1['shift']());}catch(_0x563d13){_0x11a1b1['push'](_0x11a1b1['shift']());}}}(_0x338e,0x4e8be));import{getContext,extension_settings}from'/scripts/extensions.js';import{SlashCommandParser}from'/scripts/slash-commands/SlashCommandParser.js';import{extensionName}from'../utils/settings.js';async function executeSlashCommand(_0x4e0979){const _0x1f5043=_0x440b;if(!_0x4e0979)return;try{console[_0x1f5043(0x200)]('[Amily-敕令执行官]\x20准备执行圣谕:\x20'+_0x4e0979);const _0x545352=new SlashCommandParser(),_0xe85d8c=_0x545352[_0x1f5043(0x209)](_0x4e0979,![]);if(_0xe85d8c&&typeof _0xe85d8c[_0x1f5043(0x1ed)]==='function')await _0xe85d8c[_0x1f5043(0x1ed)](),console[_0x1f5043(0x200)]('[Amily-敕令执行官]\x20圣谕:\x20\x22'+_0x4e0979+'\x22\x20已成功颁布。'),toastr[_0x1f5043(0x1e6)]('圣谕\x20\x22'+_0x4e0979+_0x1f5043(0x1ef),_0x1f5043(0x1f0));else{const _0x40bf28=_0x1f5043(0x1ec)+_0x4e0979;console['error'](_0x1f5043(0x1e7)+_0x40bf28),toastr[_0x1f5043(0x20c)](_0x40bf28,_0x1f5043(0x204));}}catch(_0x5ab5c6){console[_0x1f5043(0x20c)](_0x1f5043(0x1eb)+_0x4e0979+'\x22\x20时发生意外:',_0x5ab5c6),toastr[_0x1f5043(0x20c)](_0x1f5043(0x202)+_0x5ab5c6['message'],'敕令司紧急报告');}}function _0x338e(){const _0x1c5948=['40LXOpKn','chat','/hide\x200-','manual_hide','17053157kJbUsK','请输入有效的楼层范围','168595BznAfB','length','unhide_all','log','史册为空,无需解除隐藏。','执行圣谕时发生意外:\x20','5tWCwSo','敕令司紧急报告','敕令司提示','423482FVpnBV','3dPBnqP','warning','parse','10PYqZfl','[Amily-史册管理员]\x20颁布圣谕:\x20','error','/hide','450988kYMnDm','autoHideThreshold','success','[Amily-敕令执行官]\x20','info','/unhide','[Amily-手动敕令司]\x20未知的命令类型:\x20','[Amily-敕令执行官]\x20执行圣谕\x20\x22','铸造出的圣谕法印无法执行!指令:\x20','execute','4180624yIGUso','\x22\x20已成功颁布','敕令司回报','999756MGjBcB','[Amily-史册管理员]\x20执行自动隐藏律法时发生意外错误:','起始层不能大于结束层','/unhide\x200-','autoHideEnabled','3413952EckBBs'];_0x338e=function(){return _0x1c5948;};return _0x338e();}export async function executeAutoHide(){const _0xc8e96f=_0x440b;try{const _0x27f21d=extension_settings[extensionName];if(!_0x27f21d[_0xc8e96f(0x1f5)])return;const _0x35f0da=_0x27f21d[_0xc8e96f(0x1e5)]||0x1e,_0x2c76ec=getContext(),_0x3364d4=_0x2c76ec[_0xc8e96f(0x1f8)]['length'],_0xd231ec=_0x3364d4-_0x35f0da-0x1;if(_0xd231ec<0x0){;return;}const _0x57aad4=_0xc8e96f(0x1f9)+_0xd231ec;console[_0xc8e96f(0x200)](_0xc8e96f(0x20b)+_0x57aad4);const _0x34e2ad=new SlashCommandParser(),_0x2a3508=_0x34e2ad[_0xc8e96f(0x209)](_0x57aad4,![]);_0x2a3508&&typeof _0x2a3508[_0xc8e96f(0x1ed)]==='function'?(await _0x2a3508['execute'](),console[_0xc8e96f(0x200)]('[Amily-史册管理员]\x20圣谕颁布成功。')):console[_0xc8e96f(0x20c)]('[Amily-史册管理员]\x20致命错误:铸造出的圣谕法印无法执行!');}catch(_0x43a7b9){console['error'](_0xc8e96f(0x1f2),_0x43a7b9);}}export async function executeManualCommand(_0x4b6ad1,_0x45d631={}){const _0x4052e4=_0x440b,{from:_0x109935,to:_0x5201ea}=_0x45d631;let _0x439173='';switch(_0x4b6ad1){case _0x4052e4(0x1ff):{const _0x110361=getContext()[_0x4052e4(0x1f8)][_0x4052e4(0x1fe)];if(_0x110361>0x0){const _0x2988bb=_0x110361-0x1;_0x439173=_0x4052e4(0x1f4)+_0x2988bb;}else{toastr[_0x4052e4(0x1e8)](_0x4052e4(0x201),_0x4052e4(0x1f0));return;}break;}case _0x4052e4(0x1fa):case'manual_unhide':{const _0x1cd679=_0x4b6ad1===_0x4052e4(0x1fa)?_0x4052e4(0x20d):_0x4052e4(0x1e9);if(_0x109935===''&&_0x5201ea!=='')_0x439173=_0x1cd679+'\x20'+_0x5201ea;else{if(_0x109935!==''&&_0x5201ea!==''){if(parseInt(_0x109935)>parseInt(_0x5201ea)){toastr['warning'](_0x4052e4(0x1f3),_0x4052e4(0x205));return;}_0x439173=_0x1cd679+'\x20'+_0x109935+'-'+_0x5201ea;}else{toastr[_0x4052e4(0x208)](_0x4052e4(0x1fc),_0x4052e4(0x205));return;}}break;}default:console[_0x4052e4(0x20c)](_0x4052e4(0x1ea)+_0x4b6ad1);return;}await executeSlashCommand(_0x439173);}
|
||||
|
||||
Reference in New Issue
Block a user