| 52 | |
| 53 | cmdHandlers: Record<string, (msg: Api.Message, trigger?: Api.Message) => Promise<void>> = { |
| 54 | atadmins: async (msg: Api.Message) => { |
| 55 | const client = await getGlobalClient(); |
| 56 | if (!client) { |
| 57 | await msg.edit({ text: "❌ 客户端未初始化", parseMode: "html" }); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | // 参数解析(严格按acron.ts模式) |
| 62 | const lines = msg.message?.trim()?.split(/\r?\n/g) || []; |
| 63 | const parts = lines?.[0]?.split(/\s+/) || []; |
| 64 | const [, ...args] = parts; // 跳过命令本身 |
| 65 | const sub = (args[0] || "").toLowerCase(); |
| 66 | |
| 67 | try { |
| 68 | // 明确请求帮助时才显示 |
| 69 | if (sub === "help" || sub === "h") { |
| 70 | await msg.edit({ |
| 71 | text: help_text, |
| 72 | parseMode: "html" |
| 73 | }); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | // 执行AT管理员功能 |
| 78 | await this.handleAtAdmins(msg, args); |
| 79 | |
| 80 | } catch (error: any) { |
| 81 | console.error("[atadmins] 插件执行失败:", error); |
| 82 | await msg.edit({ |
| 83 | text: `❌ <b>操作失败:</b> ${htmlEscape(error.message)}`, |
| 84 | parseMode: "html" |
| 85 | }); |
| 86 | } |
| 87 | } |
| 88 | }; |
| 89 | |
| 90 | // 将管理员 mention 分片,控制单条消息的最大字数与最大 mention 数 |
| 91 | private chunkMentions(mentions: string[], header: string, maxLen = 3500, maxCount = 25): string[] { |
| 92 | const chunks: string[] = []; |
| 93 | let current = header; |
| 94 | let count = 0; |
| 95 | for (const m of mentions) { |
| 96 | const toAdd = (count === 0 ? "" : " , ") + m; |
| 97 | if (count >= maxCount || (current.length + toAdd.length) > maxLen) { |
| 98 | chunks.push(current); |
| 99 | current = header + m; // 新开一条 |
| 100 | count = 1; |
| 101 | } else { |
| 102 | current += toAdd; |
| 103 | count++; |
| 104 | } |
| 105 | } |
| 106 | if (count > 0) chunks.push(current); |
| 107 | return chunks; |
| 108 | } |
| 109 | |
| 110 | private async handleAtAdmins(msg: Api.Message, args: string[]): Promise<void> { |
| 111 | const client = await getGlobalClient(); |
nothing calls this directly
no test coverage detected