| 348 | |
| 349 | constructor() { |
| 350 | super(); |
| 351 | this.restorePromise = this.restoreJobs().catch((error) => { |
| 352 | if (String(error?.message || error).includes("runtime is not initialized")) return; |
| 353 | console.error("[tmp_admin] 恢复临时管理员任务失败:", error); |
| 354 | }); |
| 355 | } |
| 356 | |
| 357 | cleanup(): void { |
| 358 | for (const job of this.jobs.values()) { |
| 359 | if (job.timer) clearTimeout(job.timer); |
| 360 | } |
| 361 | this.jobs.clear(); |
| 362 | } |
| 363 | |
| 364 | description: string = `\n临时管理员\n\n${helpText}`; |
| 365 | |
| 366 | cmdHandlers: Record< |
| 367 | string, |
| 368 | (msg: Api.Message, trigger?: Api.Message) => Promise<void> |
| 369 | > = { |
| 370 | tmp_admin: async (msg: Api.Message, trigger?: Api.Message) => { |
| 371 | await this.restorePromise; |
| 372 | const parts = (msg.message || "").trim().split(/\s+/).filter(Boolean); |
| 373 | const sub = (parts[1] || "").toLowerCase(); |
| 374 | |
| 375 | if (["help", "h"].includes(sub)) { |
| 376 | await respondToCommand(msg, trigger, { text: helpText, parseMode: "html" }); |
| 377 | return; |
| 378 | } |
| 379 | |
| 380 | const isInChannel = (msg as any).isChannel; |
| 381 | if (!isInChannel) { |
| 382 | await respondToCommand(msg, trigger, { |
| 383 | text: `请在超级群/频道中使用 <code>${commandName}</code> 命令`, |
| 384 | parseMode: "html", |
| 385 | }); |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | const channel = await msg.getInputChat(); |
| 390 | const chatEntity = await msg.getChat(); |
| 391 | if (!channel || !(chatEntity instanceof Api.Channel)) { |
| 392 | await respondToCommand(msg, trigger, { text: "无法获取当前超级群/频道实体" }); |
| 393 | return; |
| 394 | } |
| 395 | const chatKey = getChatKey(chatEntity, msg); |
| 396 | |
| 397 | if (["ls", "list"].includes(sub)) { |
| 398 | await this.listJobs(msg, trigger, chatKey); |
| 399 | return; |
| 400 | } |
| 401 | |
| 402 | if (["rm", "remove", "del"].includes(sub)) { |
| 403 | const targetSourceMsg = getTargetSourceMessage(msg, trigger); |
| 404 | const targetArg = messageHasReply(targetSourceMsg) ? undefined : parts[2]; |
| 405 | await this.removeTemporaryAdmin({ |
| 406 | msg, |
| 407 | targetSourceMsg, |
nothing calls this directly
no test coverage detected