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

Function findUserInChannelParticipants

admin_board/admin_board.ts:1156–1215  ·  view source on GitHub ↗
(
  target: TargetChat,
  identifier: string,
)

Source from the content-addressed store, hash-verified

1154 if (username) {
1155 try {
1156 const users = await client.getParticipants(target.entity, {
1157 search: username,
1158 showTotal: false,
1159 });
1160 const matched = users.find((user): user is Api.User => {
1161 return (
1162 user instanceof Api.User &&
1163 (user.username || "").toLowerCase() === username
1164 );
1165 });
1166 if (matched) return matched;
1167 } catch {
1168 // Ignore and continue to other fallbacks.
1169 }
1170 }
1171
1172 if (!isNumeric) return undefined;
1173
1174 const inputChannel = await client.getInputEntity(target.entity as any);
1175 let offset = 0;
1176 const limit = 200;
1177
1178 for (let index = 0; index < 5; index++) {
1179 const result: any = await client.invoke(
1180 new Api.channels.GetParticipants({
1181 channel: inputChannel as any,
1182 filter: new Api.ChannelParticipantsRecent(),
1183 offset,
1184 limit,
1185 hash: 0 as any,
1186 }),
1187 );
1188
1189 const users: Api.User[] = (result?.users || []).filter(
1190 (user: any): user is Api.User => user instanceof Api.User,
1191 );
1192 const matched = users.find(
1193 (user) => String(user.id) === String(Number(identifier)),
1194 );
1195 if (matched) return matched;
1196
1197 const participants: any[] = result?.participants || [];
1198 if (!participants.length) break;
1199 offset += participants.length;
1200 }
1201
1202 return undefined;
1203}
1204
1205async function resolveUserForSeatAction(
1206 target: TargetChat,
1207 identifier: string,
1208): Promise<Api.User | undefined> {
1209 const client = await getGlobalClient();
1210 if (!client) throw new Error("Telegram 客户端未初始化");
1211
1212 const trimmed = identifier.trim();
1213 if (!trimmed) return undefined;

Callers 1

resolveUserForSeatActionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected