MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / resolveParticipantFromContext

Method resolveParticipantFromContext

aban/aban.ts:283–357  ·  view source on GitHub ↗
(
    client: TelegramClient,
    message: Api.Message,
    userId: number,
    knownEntity?: any
  )

Source from the content-addressed store, hash-verified

281
282 private static async resolveParticipantFromContext(
283 client: TelegramClient,
284 message: Api.Message,
285 userId: number,
286 knownEntity?: any
287 ): Promise<any | undefined> {
288 const chat = (message as any).peerId;
289 if (!chat) {
290 return undefined;
291 }
292
293 if ((message as any).isChannel) {
294 try {
295 // 优先 getParticipant(accessHash=0):目标是成员/可解析时一次成功,且不要求“当前页”
296 const viaPart = await this.resolveUserViaGetParticipant(client, chat, userId);
297 if (viaPart) return viaPart;
298
299 let offset = 0;
300 const limit = 200;
301 for (let i = 0; i < 5; i++) {
302 const res: any = await client.invoke(
303 new Api.channels.GetParticipants({
304 channel: chat,
305 filter: new Api.ChannelParticipantsRecent(),
306 offset,
307 limit,
308 hash: 0 as any,
309 })
310 );
311
312 const participants: any[] = res?.participants || [];
313 const users: any[] = res?.users || [];
314 const matchedUser = users.find((u) => Number(u?.id) === userId);
315 if (matchedUser) {
316 const input = await this.safeGetInputEntity(client, matchedUser);
317 if (input) {
318 return input;
319 }
320 }
321
322 if (!participants.length) break;
323 offset += participants.length;
324 }
325 } catch {
326 return undefined;
327 }
328 }
329
330 if ((message as any).isGroup) {
331 try {
332 const peer: any = knownEntity || await this.safeGetEntity(client, chat);
333 const chatId = Number(peer?.chatId ?? peer?.id ?? (chat as any)?.chatId);
334 if (!Number.isFinite(chatId)) {
335 return undefined;
336 }
337
338 const full: any = await client.invoke(
339 new Api.messages.GetFullChat({
340 chatId: bigInt(chatId),

Callers 2

resolveTargetMethod · 0.95
resolveFromStringMethod · 0.95

Calls 2

safeGetInputEntityMethod · 0.95
safeGetEntityMethod · 0.95

Tested by

no test coverage detected