feat: add private daily summaries and history sync

This commit is contained in:
Benature
2026-11-05 22:18:12 +08:00
parent 97ad48e69e
commit 41d71f83cb
13 changed files with 1282 additions and 32 deletions

View File

@ -232,10 +232,19 @@ class LarkClient:
self._thread_chats[chat_id] = decoders.is_thread_chat(info)
return self._thread_chats[chat_id]
def pull_history(self, chat_id: str, positions, save_storage=None):
resp = self.api('messages.PullMessagesByPositionsRequest', {'chatId': str(chat_id), 'positions': [int(p) for p in positions]})
def pull_history(self, chat_id: str, positions, save_storage=None, visible_only=False, thread_chat=None):
request = {'chatId': str(chat_id), 'positions': [int(p) for p in positions]}
if visible_only:
request.update({
'type': 'CHAT',
'onlyVisibleMessages': True,
'needNextPosition': True,
'direction': 'UP',
})
resp = self.api('messages.PullMessagesByPositionsRequest', request)
messages = (resp or {}).get('messages') or {}
thread_chat = self.is_thread_chat(chat_id)
if thread_chat is None:
thread_chat = self.is_thread_chat(chat_id)
out = []
for pos_key, v in sorted(messages.items(), key=lambda kv: int(kv[0])):
message_type = decoders.enum_to_int(v.get('type', 0))
@ -247,7 +256,8 @@ class LarkClient:
out.append(msg)
if save_storage is not None:
try:
save_storage.save_message(msg)
direction = 'out' if str(v.get('fromId') or '') == str(self.auth.user_id or '') else 'in'
save_storage.save_message(msg, direction=direction)
except Exception:
pass
return out