( target: TargetChat, identifier: string, )
| 1133 | showTotal: false, |
| 1134 | ...(username ? { search: username } : {}), |
| 1135 | }); |
| 1136 | |
| 1137 | return participants.find((user): user is Api.User => { |
| 1138 | if (!(user instanceof Api.User)) return false; |
| 1139 | if (isNumeric) return String(user.id) === String(Number(identifier)); |
| 1140 | return (user.username || "").toLowerCase() === username; |
| 1141 | }); |
| 1142 | } |
| 1143 | |
| 1144 | async function findUserInChannelParticipants( |
| 1145 | target: TargetChat, |
| 1146 | identifier: string, |
| 1147 | ): Promise<Api.User | undefined> { |
| 1148 | const client = await getGlobalClient(); |
| 1149 | if (!client) throw new Error("Telegram 客户端未初始化"); |
| 1150 | |
| 1151 | const isNumeric = /^-?\d+$/.test(identifier); |
| 1152 | const username = isNumeric ? "" : identifier.replace(/^@/, "").toLowerCase(); |
| 1153 | |
| 1154 | if (username) { |
| 1155 | try { |
| 1156 | const users = await client.getParticipants(target.entity, { |
| 1157 | search: username, |
no outgoing calls
no test coverage detected