MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / handleAdmin

Method handleAdmin

openlist/openlist.ts:412–476  ·  view source on GitHub ↗
(msg: Api.Message, adminArgs: string[])

Source from the content-addressed store, hash-verified

410 const safeLatest = this.sanitizeBackupName(latest);
411 if (!safeLatest) {
412 await msg.edit({ text: `未找到任何备份于:${codeTag(backupBaseDir)}`, parseMode: "html" });
413 return;
414 }
415 targetBackupDir = path.join(backupBaseDir, safeLatest);
416 }
417
418 if (!(await this.dirExists(`${targetBackupDir}/data`))) {
419 await msg.edit({ text: `无效的备份目录:${codeTag(targetBackupDir)}`, parseMode: "html" });
420 return;
421 }
422
423 await msg.edit({ text: `将从 ${codeTag(targetBackupDir)} 恢复...`, parseMode: "html" });
424 await execAsync(`systemctl stop openlist || true`);
425 await execAsync(`cp -r "${targetBackupDir}/data" "${installPath}/"`);
426 await execAsync(`systemctl start openlist`);
427
428 await msg.edit({ text: "恢复成功" });
429 } catch (error: any) {
430 await msg.edit({ text: `恢复失败: ${htmlEscape(error?.message || error)}`, parseMode: "html" });
431 }
432 }
433
434 private async handleAdmin(msg: Api.Message, adminArgs: string[]) {
435 try {
436 const installPath = await this.detectInstalledPath();
437 if (!(await this.fileExists(`${installPath}/openlist`))) {
438 await msg.edit({ text: "未检测到 OpenList 安装" });
439 return;
440 }
441
442 const sub = adminArgs[0] || "";
443 const arg = adminArgs[1] || "";
444 let commandArgs: string[] = [];
445 let displayCommand = "";
446
447 // 记录需要更新的凭证
448 let newUser = "";
449 let newPass = "";
450
451 switch (sub) {
452 case "setuser":
453 if (!arg) {
454 await msg.edit({ text: "用法: admin setuser [新用户名]" });
455 return;
456 }
457 commandArgs = ["admin", "setuser", arg];
458 displayCommand = `admin setuser ${arg}`;
459 newUser = arg;
460 break;
461 case "setpass":
462 if (!arg) {
463 await msg.edit({ text: "用法: admin setpass [新密码]" });
464 return;
465 }
466 commandArgs = ["admin", "set", arg]; // 原脚本中使用 'set' 而非 'setpass'
467 displayCommand = "admin set <新密码>";
468 newPass = arg;
469 break;

Callers 1

handleCommandMethod · 0.95

Calls 6

detectInstalledPathMethod · 0.95
fileExistsMethod · 0.95
preTagFunction · 0.85
htmlEscapeFunction · 0.70
editMethod · 0.45

Tested by

no test coverage detected