| 1079 | if (msg.out) return true; |
| 1080 | |
| 1081 | // 2. 检查是否是 Saved Messages |
| 1082 | try { |
| 1083 | // 使用缓存的用户ID,避免重复获取 |
| 1084 | if (!cachedUserId) { |
| 1085 | const client = await getGlobalClient(); |
| 1086 | if (!client) return false; |
| 1087 | const me = await client.getMe(); |
| 1088 | cachedUserId = me.id.toString(); |
| 1089 | } |
| 1090 | |
| 1091 | // 检查消息的聊天对象 |
| 1092 | const peerId = msg.peerId; |
| 1093 | const chatId = msg.chatId; |
| 1094 | |
| 1095 | // Saved Messages 的特征:chatId 等于当前用户的 ID |
| 1096 | if (chatId && chatId.toString() === cachedUserId) { |
| 1097 | return true; |
| 1098 | } |
| 1099 | |
| 1100 | // 也可以通过 peerId 检查 |
| 1101 | if (peerId && typeof peerId === 'object' && 'userId' in peerId) { |
| 1102 | if (peerId.userId.toString() === cachedUserId) { |
| 1103 | return true; |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | } catch (error) { |
| 1108 | console.error("[autodelcmd] 检查消息来源时出错:", error); |
| 1109 | } |
| 1110 | |
| 1111 | // 3. 其他情况不处理 |
| 1112 | return false; |
| 1113 | } |
| 1114 | |
| 1115 | // 监听所有消息,实现命令后处理 |
| 1116 | cleanup(): void { |
| 1117 | serviceInstance?.cleanup(); |
| 1118 | serviceInstance = null; |
| 1119 | cachedUserId = null; |
| 1120 | } |