(msg: Api.Message)
| 177 | this.pendingDeleteTimers.delete(timer); |
| 178 | msg.delete().catch(() => {}); |
| 179 | }, seconds * 1000); |
| 180 | if (typeof (timer as any).unref === "function") { |
| 181 | (timer as any).unref(); |
| 182 | } |
| 183 | this.pendingDeleteTimers.add(timer); |
| 184 | } |
| 185 | |
| 186 | cleanup(): void { |
| 187 | // 真实资源清理:释放插件持有的定时器、监听器、运行时状态或临时资源。 |
| 188 | for (const timer of this.pendingDeleteTimers) { |
| 189 | clearTimeout(timer); |
| 190 | } |
| 191 | this.pendingDeleteTimers.clear(); |
| 192 | this.isPremium = null; |
| 193 | this.meId = null; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * [MODIFIED] Renamed and enhanced to get our own user ID and premium status. |
| 198 | */ |
| 199 | private async initializeSelf() { |
| 200 | if (this.meId === null) { |
| 201 | const client = await getGlobalClient(); |
| 202 | if (client) { |
| 203 | const me = await client.getMe() as Api.User; |
| 204 | this.isPremium = me?.premium || false; |
| 205 | this.meId = me?.id || null; |
| 206 | } else { |
| 207 | this.isPremium = false; |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | private async handleTrace(msg: Api.Message) { |
| 213 | try { |
| 214 | const parts = msg.message?.split(/\s+/) || []; |
| 215 | const [, sub, ...args] = parts; |
| 216 | const repliedMsg = await safeGetReplyMessage(msg); |
| 217 | |
| 218 | if (repliedMsg && !sub) { |
| 219 | return this.untraceUser(msg, repliedMsg); |
| 220 | } |
| 221 | |
| 222 | if (repliedMsg && sub) { |
| 223 | const fullEmojiText = msg.message.substring(parts[0].length).trim(); |
| 224 | return this.traceUser(msg, repliedMsg, fullEmojiText); |
| 225 | } |
| 226 | |
| 227 | switch (sub?.toLowerCase()) { |
| 228 | case "kw": |
| 229 | const action = (args[0] || "").toLowerCase(); |
| 230 | const keyword = args[1]; |
| 231 | const fullEmojiText = msg.message.substring(parts.slice(0, 3).join(" ").length).trim(); |
| 232 | if (action === "add" && keyword && fullEmojiText) { |
| 233 | return this.traceKeyword(msg, keyword, fullEmojiText); |
nothing calls this directly
no test coverage detected