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

Method cleanDeletedMember

clean/clean.ts:259–324  ·  view source on GitHub ↗
(client: any, msg: Api.Message, cleanMembers: boolean = false)

Source from the content-addressed store, hash-verified

257
258 // 群组已注销账号清理
259 private async cleanDeletedMember(client: any, msg: Api.Message, cleanMembers: boolean = false): Promise<void> {
260 const chat = await msg.getChat();
261 if (!chat || !(chat instanceof Api.Chat || chat instanceof Api.Channel)) {
262 await this.sendError(msg, "此命令仅在群组中可用");
263 return;
264 }
265
266 await this.editMessage(msg, cleanMembers
267 ? "🔍 正在扫描并清理群组已注销账号..."
268 : "🔍 正在扫描群组已注销账号...");
269
270 const chatId = chat.id;
271 if (cleanMembers && !await this.checkBanPermission(client, chatId)) {
272 await this.sendError(msg, "没有封禁用户权限,无法执行清理");
273 return;
274 }
275
276 let deletedCount = 0;
277 const deletedUsers: Array<{id: string, username?: string}> = [];
278
279 const participants = client.iterParticipants(chatId);
280 for await (const participant of participants) {
281 if (participant instanceof Api.User && participant.deleted) {
282 deletedCount++;
283 deletedUsers.push({
284 id: participant.id.toString(),
285 username: participant.username || "未知"
286 });
287
288 if (cleanMembers) {
289 try {
290 await banUser(client, chatId, participant.id);
291 await sleep(100);
292 } catch (error: any) {
293 if (error.message?.includes("FLOOD_WAIT")) {
294 await this.handleFloodWait(msg, error);
295 return;
296 }
297 }
298 }
299 }
300 }
301
302 let result = "";
303 if (deletedCount === 0) {
304 result = "✅ <b>扫描完成</b>\n\n此群组中没有发现已注销账号。";
305 } else {
306 result = cleanMembers
307 ? `✅ <b>清理完成</b>\n\n已清理 <code>${deletedCount}</code> 个已注销账号:\n\n`
308 : `✅ <b>扫描完成</b>\n\n此群组的已注销账号数: <code>${deletedCount}</code>:\n\n`;
309
310 deletedUsers.slice(0, 15).forEach(user => {
311 result += `• <a href="tg://user?id=${user.id}">${user.id}</a>\n`;
312 });
313
314 if (deletedCount > 15) {
315 result += `\n... 还有 ${deletedCount - 15} 个未显示\n`;
316 }

Callers 1

handleDeletedCleanMethod · 0.95

Calls 5

sendErrorMethod · 0.95
editMessageMethod · 0.95
checkBanPermissionMethod · 0.95
handleFloodWaitMethod · 0.95
sleepFunction · 0.70

Tested by

no test coverage detected