( client: any, userId: number )
| 271 | |
| 272 | const collectDialogs = async (params: Record<string, any>) => { |
| 273 | try { |
| 274 | const dialogs = await client.getDialogs(params); |
| 275 | for (const dialog of dialogs || []) { |
| 276 | const key = `${dialog.id}`; |
| 277 | if (!dialogMap.has(key)) { |
| 278 | dialogMap.set(key, dialog); |
| 279 | } |
| 280 | } |
| 281 | } catch (error) { |
| 282 | console.error("findUserFromGroups getDialogs error:", error); |
| 283 | } |
| 284 | }; |
| 285 | |
| 286 | try { |
| 287 | await collectDialogs({}); |
| 288 | await collectDialogs({ folderId: 1 }); |
| 289 | |
| 290 | for (const dialog of dialogMap.values()) { |
| 291 | // 只检查群组和超级群组 |
| 292 | if ( |
| 293 | dialog.entity?.className === "Chat" || |
| 294 | dialog.entity?.className === "Channel" |
| 295 | ) { |
| 296 | try { |
| 297 | const participants = await client.getParticipants(dialog.entity, { |
| 298 | limit: 200, |
| 299 | }); |
| 300 | for (const participant of participants) { |
| 301 | if ( |
| 302 | participant.id?.toJSNumber?.() === userId || |
| 303 | Number(participant.id) === userId |
| 304 | ) { |
| 305 | return participant as Api.User; |
| 306 | } |
| 307 | } |
| 308 | } catch { |
| 309 | // 跳过无法获取成员的群组 |
| 310 | continue; |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | } catch (e) { |
| 315 | console.error("findUserFromGroups error:", e); |
| 316 | } |
| 317 | return null; |
| 318 | } |
| 319 | |
| 320 | class IsAlivePlugin extends Plugin { |
| 321 | |
| 322 | description: string = `\nisalive\n\n${help_text}`; |
| 323 | cmdHandlers: Record< |
| 324 | string, |
| 325 | (msg: Api.Message, trigger?: Api.Message) => Promise<void> |
| 326 | > = { |
| 327 | isalive: async (msg: Api.Message, trigger?: Api.Message) => { |
| 328 | const client = await getGlobalClient(); |
no test coverage detected