Commit 59ced81
src/history/sync.py
@@ -15,6 +15,7 @@ from pyrogram.types import Chat, Message
from config import DOWNLOAD_DIR, HISTORY, TZ, cache
from database import create_d1_database, create_d1_table, query_d1
from messages.parser import parse_msg
+from permission import check_save_d1
from utils import i_am_bot
# ruff: noqa: S608
@@ -26,12 +27,14 @@ async def sync_history_to_d1(client: Client, message: Message) -> None:
if not HISTORY.D1_ENABLE:
return
info = parse_msg(message, silent=True)
+ if not check_save_d1(info["ctype"], info["cid"]):
+ return
table_name = await get_table_name(client, info["cid"])
records = {
"mid": info["mid"],
"time": info["time"],
"user": info["full_name"],
- "content": info["text"],
+ "content": message.content, # text or edited text
"mtype": info["mtype"],
"uid": info["uid"],
"filename": info["file_name"],
src/main.py
@@ -24,6 +24,7 @@ from bridge.social import forward_social_media_results
from config import DAILY_MESSAGES, DEVICE_NAME, ENABLE, PROXY, TOKEN, TZ, cache
from danmu.sync import sync_server_to_r2
from handler import handle_social_media, handle_utilities
+from history.sync import sync_history_to_d1
from llm.summary import daily_summary
from llm.utils import clean_gemini_files
from messages.parser import parse_msg
@@ -86,6 +87,10 @@ async def main():
await handle_utilities(client, message, **permission)
await handle_social_media(client, message, **permission)
+ @app.on_edited_message()
+ async def edited(client: Client, message: Message):
+ await sync_history_to_d1(client, message)
+
if ENABLE.CRONTAB:
scheduler = AsyncIOScheduler()
scheduler.add_job(scheduling, "interval", args=[app], seconds=60) # run crontab jobs every 60 seconds