From a32f4572d7461ab50474d173f8eb6f9bb8e96363 Mon Sep 17 00:00:00 2001 From: H Vs Date: Tue, 15 Apr 2025 09:44:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tasks.py b/tasks.py index 7792de5..6539375 100644 --- a/tasks.py +++ b/tasks.py @@ -639,7 +639,7 @@ def scheduled_task_add_contacts_from_chatrooms(self, redis_config, kafka_config, nickname = next((member['nickName'] for member in chatroom_member_list if member['wxid'] == wxid), None) if not remaining_chatroot_members: - logger.info(f'{nickname}-{wxid} 在 {chatroom_nickname} 群里没有好友可以邀请') + logger.info(f'{nickname}-{wxid} 在 {chatroom_nickname}-{chatroom_id} 群里没有好友可以邀请') # 任务状态推送到kafka k_message = wx_add_contacts_from_chatroom_task_status_message(wxid, chatroom_id, 2) await kafka_service.send_message_async(k_message) @@ -676,7 +676,7 @@ def scheduled_task_add_contacts_from_chatrooms(self, redis_config, kafka_config, logger.info(f'{nickname}-{wxid}在{chatroom_nickname}-{chatroom_id} 群的 {member_nickname}-{contact_wxid} 已经邀请过2次,不再邀请') continue - # 当天邀请过,不再邀请 + # 24小时邀请过,不再邀请 if len(sorted_history) > 0: last_add_time = sorted_history[0].addTime @@ -697,24 +697,28 @@ def scheduled_task_add_contacts_from_chatrooms(self, redis_config, kafka_config, is_more_than_one_day = is_add_time_more_than_one_day(last_add_time) if not is_more_than_one_day: - logger.info(f'{nickname}-{wxid}在{chatroom_nickname}-{chatroom_id} 群的 {member_nickname}-{contact_wxid} 已经当天邀请,不再邀请') + logger.info(f'{nickname}-{wxid}在{chatroom_nickname}-{chatroom_id} 群的 {member_nickname}-{contact_wxid} 已经24小时邀请,不再邀请') continue ret, msg, data = await gewe_service.add_group_member_as_friend_async(token_id, app_id, chatroom_id, m.get('wxid'), f'我是群聊"{chatroom_nickname}"群的{nickname}') + + history = AddGroupContactsHistory.model_validate({ + "chatroomId": chatroom_id, + "wxid": wxid, + "contactWixd": contact_wxid, + "addTime": int(time.time()) + }) + if ret != 200: - logger.warning(f'{nickname}-{wxid} 在 {chatroom_nickname}-{chatroom_id} 群好友邀请失败原因:{ret} {msg} {data}') + logger.warning(f'{nickname}-{wxid} 在 {chatroom_nickname}-{chatroom_id} 群好友 {contact_wxid} 邀请失败原因:{ret} {msg} {data}') if '操作过于频繁' in data.get('msg'): await gewe_service.save_wx_expection_async(wxid, "addGroupMemberAsFriend", msg, today_seconds_remaining()) + await gewe_service.save_group_add_contacts_history_async(wxid, chatroom_id, contact_wxid, history) logger.warning(f'{nickname}-{wxid} 在 {chatroom_nickname}-{chatroom_id} 群的 {member_nickname}-{contact_wxid} 操作过于频繁,本次群好友邀请任务未完成跳过。当天不再处理该号群好友邀请任务') return - history = AddGroupContactsHistory.model_validate({ - "chatroomId": chatroom_id, - "wxid": wxid, - "contactWixd": contact_wxid, - "addTime": int(time.time()) - }) + await gewe_service.save_group_add_contacts_history_async(wxid, chatroom_id, contact_wxid, history) wixd_add_contacts_from_chatrooms_times[wxid] += 1 logger.info(f'{nickname} 向 {chatroom_nickname}-{chatroom_id} 群的 {m.get("nickName")}-{m.get("wxid")} 发送好友邀请 {msg}')