(msg: Api.Message, repliedMsg: Api.Message, emojiText: string)
| 268 | private async handleMessage(msg: Api.Message) { |
| 269 | // Ensure we know who "I" am. |
| 270 | await this.initializeSelf(); |
| 271 | if (!this.db?.data || !msg.senderId || !this.meId) return; |
| 272 | |
| 273 | // If the message is from me, ignore it completely. |
| 274 | const senderId = msg.senderId.toString(); |
| 275 | const isSelf = senderId === this.meId.toString(); |
| 276 | if (isSelf) { |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | const { users, keywords, config } = this.db.data; |
| 281 | |
| 282 | try { |
| 283 | // User trace logic for incoming messages |
| 284 | if (users[senderId]) { |
| 285 | await this.sendReaction(msg.peerId, msg.id, users[senderId], config.big); |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | // Keyword trace logic for incoming messages |
| 290 | if (msg.message) { |
| 291 | for (const keyword in keywords) { |
| 292 | if (msg.message.includes(keyword)) { |
| 293 | await this.sendReaction(msg.peerId, msg.id, keywords[keyword], config.big); |
| 294 | return; |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | } catch (error) { |
| 299 | console.error("[trace] Listener failed to send reaction:", error); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | private async traceUser(msg: Api.Message, repliedMsg: Api.Message, emojiText: string) { |
| 304 | const userId = repliedMsg.senderId?.toString(); |
| 305 | if (!userId) { |
| 306 | await this.editAndDelete(msg, "❌ <b>操作失败</b>\n└ 无法获取用户信息"); |
| 307 | return; |
| 308 | } |
| 309 | const reactions = await this.parseReactions(msg, emojiText); |
| 310 | if (reactions.length === 0) { |
| 311 | await this.editAndDelete(msg, "❌ <b>操作失败</b>\n├ 未找到有效的表情符号\n└ 请检查帮助中的可用列表"); |
| 312 | return; |
| 313 | } |
| 314 | this.db.data.users[userId] = reactions; |
| 315 | await this.db.write(); |
| 316 | await this.sendReaction(repliedMsg.peerId, repliedMsg.id, reactions, this.db.data.config.big); |
| 317 | const userEntity = await this.formatEntity(userId); |
| 318 | // Extract actual emojis from the original message for display |
| 319 | // Get reaction display with entities for custom emojis |
| 320 | const reactionCount = reactions.length; |
| 321 | const customCount = reactions.filter(r => typeof r !== 'string').length; |
| 322 | |
| 323 | if (customCount > 0) { |
| 324 | // Build message with custom emoji entities |
| 325 | const msgBuilder = new this.MessageBuilder(); |
| 326 | msgBuilder.addLine('✅ 追踪成功'); |
no test coverage detected