| 63 | description: string = `消息历史查询插件\n\n${help_text}`; |
| 64 | |
| 65 | constructor() { |
| 66 | super(); |
| 67 | } |
| 68 | |
| 69 | cmdHandlers: Record<string, (msg: Api.Message, trigger?: Api.Message) => Promise<void>> = { |
| 70 | his: async (msg: Api.Message, trigger?: Api.Message) => { |
| 71 | const client = await getGlobalClient(); |
| 72 | if (!client) { |
| 73 | await msg.edit({ text: "❌ 客户端未初始化", parseMode: "html" }); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | // 简单参数解析 |
| 78 | const lines = msg.text?.trim()?.split(/\r?\n/g) || []; |
| 79 | const parts = lines?.[0]?.split(/\s+/) || []; |
| 80 | const [, ...args] = parts; // 跳过命令本身 |
| 81 | |
| 82 | try { |
| 83 | const DEFAULT_COUNT = 30; |
| 84 | |
| 85 | // 处理帮助命令 |
| 86 | if (args[0] === "help" || args[0] === "h") { |
| 87 | await msg.edit({ text: help_text, parseMode: "html" }); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | // 无参数时的处理 |
| 92 | if (args.length === 0) { |
| 93 | // 如果是回复消息,则查询被回复者 |
| 94 | if (msg.isReply) { |
| 95 | const reply = await safeGetReplyMessage(msg); |
| 96 | if (reply && reply.senderId) { |
| 97 | const target = reply.senderId.toString(); |
| 98 | await this.queryHistory(msg, target, DEFAULT_COUNT, client); |
| 99 | return; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // 否则显示错误提示 |
| 104 | await msg.edit({ |
| 105 | text: "❌ 请回复一条消息或指定查询目标", |
| 106 | parseMode: "html" |
| 107 | }); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | // 一个参数的情况 |
| 112 | if (args.length === 1) { |
| 113 | const arg = args[0]; |
| 114 | const num = parseInt(arg); |
| 115 | |
| 116 | // 如果是数字且在回复消息的情况下,作为数量参数 |
| 117 | if (!isNaN(num) && num > 0 && msg.isReply) { |
| 118 | const reply = await safeGetReplyMessage(msg); |
| 119 | if (reply && reply.senderId) { |
| 120 | const target = reply.senderId.toString(); |
| 121 | const count = Math.min(num, 100); // 最大限制100条 |
| 122 | await this.queryHistory(msg, target, count, client); |
nothing calls this directly
no test coverage detected