From c3219bcba222ce097fa36165dd4b4bfcac4681f6 Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 7 May 2023 23:15:06 +0800 Subject: [PATCH] Update client_check_member.py --- .../tgclient/startup/extend/client_check_member.py | 53 +++++++++++++++++----- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/plugins/tgclient/startup/extend/client_check_member.py b/plugins/tgclient/startup/extend/client_check_member.py index 4723f2c7a..2c620f0f5 100644 --- a/plugins/tgclient/startup/extend/client_check_member.py +++ b/plugins/tgclient/startup/extend/client_check_member.py @@ -22,21 +22,52 @@ from telebot.util import quick_markup # 指定群ID chat_id_list = [-1001578009023, -1001979545570] +# 别人群ID[有API调用限制] +chat_id_list_other = [-1001771526434] + +async def writeLog(log_str): + if __name__ == "__main__": + print(log_str) + + now = mw.getDateFromNow() + log_file = mw.getServerDir() + '/tgclient/task.log' + mw.writeFileLog(now + ':' + log_str, log_file, limit_size=5 * 1024) + return True async def run(client): for chat_id in chat_id_list: - s = await client.send_message(chat_id, '开始自动检测已经注销群成员...') - count = 0 - async for user in client.iter_participants(chat_id): - if user.deleted: - count += 1 - msg = await client.kick_participant(chat_id, user) + try: + s = await client.send_message(chat_id, '开始自动检测已经注销群成员...') + count = 0 + async for user in client.iter_participants(chat_id): + if user.deleted: + count += 1 + msg = await client.kick_participant(chat_id, user) + + await client.edit_message(chat_id, s.id, '已经检测到有(%d)个账户已失效' % (count)) + await asyncio.sleep(3) + await client.edit_message(chat_id, s.id, '自动检测已经注销群成员完毕!!!') + await asyncio.sleep(3) + await client.delete_messages(chat_id, s) + except Exception as e: + print(str(e)) + writeLog(str(e)) + + for chat_id in chat_id_list_other: + try: + count = 0 + async for user in client.iter_participants(chat_id): + if user.deleted: + count += 1 + msg = await client.kick_participant(chat_id, user) + + other_s = await client.send_message(chat_id, '已经检测到有(%d)个账户已失效,并已经删除!' % (count)) + await asyncio.sleep(3) + await client.delete_messages(chat_id, other_s) + except Exception as e: + print(str(e)) + writeLog(str(e)) - await client.edit_message(chat_id, s.id, '已经检测到有(%d)个账户已失效' % (count)) - await asyncio.sleep(3) - await client.edit_message(chat_id, s.id, '自动检测已经注销群成员完毕!!!') - await asyncio.sleep(3) - await client.delete_messages(chat_id, s) await asyncio.sleep(300)