Commit 565be4f

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-06-10 11:45:49
fix(history): fix keyword regex matching
1 parent 5843eac
Changed files (1)
src
history
src/history/query.py
@@ -70,7 +70,7 @@ async def query_chat_history(client: Client, message: Message, **kwargs):
     if error:
         await send2tg(client, message, texts=error, **kwargs)
         return
-    if qtype == "/hist":
+    if qtype == "hist":
         chat_id = slim_cid(info["cid"])
     table_name = await get_table_name(client, chat_id)
     chat_title = "".join(table_name.split("-")[1:])
@@ -122,8 +122,8 @@ def parse_queries(texts: str, qtype: str) -> tuple[str, str, str, str, str]:
     # #chat_id
     if matched := re.match(r"^/hist\s+#(-100)?(\d+)(\s+)?", texts):
         chat_id = matched.group(2)
-    texts = re.sub(rf"^/hist\s+#(-100)?{chat_id}", "", texts).lstrip()  # remove prefix + #chat_id
-
+    texts = texts.removeprefix("/hist").lstrip()  # remove prefix
+    texts = re.sub(rf"^#(-100)?{chat_id}", "", texts).lstrip()  # remove #chat_id
     # 2025-01-01
     if matched := re.match(r"(\d{4}-\d{2}-\d{2})(\s+)?", texts):
         match_time = matched.group(1)
@@ -195,6 +195,6 @@ async def query_turso(client: Client, table_name: str, match_time: str, user: st
     for row in rows:
         row_info = {col["name"]: x["value"] for x, col in zip(row, cols, strict=True)}
         url = f"https://t.me/c/{cid}/{row_info['mid']}"
-        texts += f"👤[{row_info['fullname']}]({url}) {row_info['time']}{mtype_emoji(row_info['mtype'])}:\n{row_info['content']}\n\n"
+        texts += f"👤[{row_info['fullname']}]({url}) {row_info['time']}{mtype_emoji(row_info['mtype'])}:\n{row_info['content']}\n"
         count += 1
     return {"texts": texts.strip(), "count": count}