MCPcopy Index your code
hub / github.com/TeleBoxOrg/TeleBox_Plugins / streamProcessMembers

Function streamProcessMembers

clean_member/clean_member.ts:306–496  ·  view source on GitHub ↗
(options: StreamProcessOptions)

Source from the content-addressed store, hash-verified

304}
305
306async function streamProcessMembers(options: StreamProcessOptions): Promise<StreamProcessResult> {
307 const { client, chatEntity, mode, day, adminIds, onlySearch, maxRemove, statusCallback, modeNames } = options;
308 const result: StreamProcessResult = {
309 totalScanned: 0,
310 totalFound: 0,
311 totalRemoved: 0,
312 users: [],
313 failedUsers: []
314 };
315 let offset = 0;
316 const limit = 200;
317 let hasMore = true;
318 let batchNumber = 0;
319 try {
320 while (hasMore) {
321 batchNumber++;
322 if (statusCallback) {
323 await statusCallback(
324 `🔍 扫描第 ${batchNumber} 批 (${modeNames[mode]}) | 已扫描: ${result.totalScanned} | 已找到: ${result.totalFound}${!onlySearch ? ` | 已移出: ${result.totalRemoved}` : ''}`,
325 true
326 );
327 }
328 const participantsResult = await client.invoke(new Api.channels.GetParticipants({
329 channel: chatEntity,
330 filter: new Api.ChannelParticipantsRecent(),
331 offset: offset,
332 limit: limit,
333 hash: 0 as any,
334 }));
335 if ("users" in participantsResult && participantsResult.users.length > 0) {
336 const users = participantsResult.users as Api.User[];
337 result.totalScanned += users.length;
338 for (const user of users) {
339 const uid = Number(user.id);
340 if (adminIds.has(uid)) continue;
341 let shouldProcess = false;
342 if (mode === "1") {
343 const lastOnlineDays = getLastOnlineDays(user);
344 if (lastOnlineDays !== null && lastOnlineDays > day) {
345 shouldProcess = true;
346 }
347 } else if (mode === "2") {
348 try {
349 const userEntity = await client.getInputEntity(uid);
350 const minDate = Math.floor(Date.now() / 1000) - day * 24 * 60 * 60;
351 const res = await client.invoke(new Api.messages.Search({
352 peer: chatEntity,
353 q: "",
354 filter: new Api.InputMessagesFilterEmpty(),
355 minDate,
356 maxDate: undefined as any,
357 offsetId: 0,
358 addOffset: 0,
359 limit: 1,
360 maxId: 0,
361 minId: 0,
362 hash: 0 as any,
363 fromId: userEntity,

Callers 1

clean_memberFunction · 0.85

Calls 6

statusCallbackFunction · 0.85
removeChatMemberFunction · 0.85
errorMethod · 0.80
warnMethod · 0.80
getLastOnlineDaysFunction · 0.70
sleepFunction · 0.50

Tested by

no test coverage detected