( client: any, raw: string, )
| 180 | const entity = await resolveEntityWithFallback(client, raw); |
| 181 | if (!(entity instanceof Api.User)) { |
| 182 | throw new Error("解析结果不是用户实体"); |
| 183 | } |
| 184 | return { |
| 185 | raw, |
| 186 | display: buildEntityDisplay(entity, raw), |
| 187 | manualMode: false, |
| 188 | entity, |
| 189 | }; |
| 190 | } catch (error) { |
| 191 | const errorMessage = extractErrorMessage(error); |
| 192 | if (errorMessage === "解析结果不是用户实体") { |
| 193 | throw new Error(`源用户解析失败: ${raw}\n原因: 解析结果不是用户实体`); |
| 194 | } |
| 195 | |
| 196 | if (/^-?\d+$/.test(raw)) { |
| 197 | return { |
| 198 | raw, |
| 199 | display: raw, |
| 200 | manualMode: true, |
| 201 | manualUserId: normalizeId(raw), |
| 202 | }; |
| 203 | } |
| 204 | |
| 205 | const username = normalizeUsername(raw); |
| 206 | if (username) { |
| 207 | return { |
| 208 | raw, |
| 209 | display: `@${username}`, |
| 210 | manualMode: true, |
| 211 | manualUsername: username, |
| 212 | }; |
| 213 | } |
| 214 | |
| 215 | throw new Error(`源用户解析失败: ${raw}\n原因: ${errorMessage}`); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | function parseRequestedCount(raw: string): number { |
| 220 | const value = parseInt(raw, 10); |
| 221 | if (!Number.isFinite(value) || value <= 0) { |
| 222 | throw new Error("最大消息数必须是大于 0 的整数"); |
| 223 | } |
| 224 | return Math.min(value, MAX_MESSAGE_COUNT); |
| 225 | } |
| 226 | |
| 227 | function buildChatMessageLink( |
no test coverage detected