Commit 8e9615f
Changed files (5)
src
src/history/query.py
@@ -18,8 +18,8 @@ from messages.parser import parse_msg
from messages.progress import modify_progress
from messages.sender import send2tg
from messages.utils import blockquote, equal_prefix, smart_split, startswith_prefix
-from permission import slim_cid
from publish import publish_telegraph
+from utils import slim_cid
HELP = f"""🗣**查询当前对话聊天记录**
`/hist` 使用说明:
src/history/utils.py
@@ -12,8 +12,7 @@ from pyrogram.types import Chat, Message, User
from config import DB, HISTORY, TID, cache
from database.turso import turso_list_tables
from messages.sender import send2tg
-from permission import slim_cid
-from utils import find_url, to_int, true
+from utils import find_url, slim_cid, to_int, true
TURSO_KWARGS: dict = {
"db_name": HISTORY.TURSO_DATABASE,
@@ -82,7 +81,7 @@ def fine_grained_check(info: dict) -> bool:
return True
-async def chat_info(client: Client, chat_id: int) -> Chat:
+async def get_chat(client: Client, chat_id: int) -> Chat:
if cache.get(f"chat-info-{slim_cid(chat_id)}"):
return cache.get(f"chat-info-{slim_cid(chat_id)}")
if chat_id == 1:
@@ -91,7 +90,7 @@ async def chat_info(client: Client, chat_id: int) -> Chat:
logger.debug(f"Getting chat info for {chat_id}")
chat = await client.get_chat(int(chat_id))
except PeerIdInvalid:
- return await chat_info(client, int(f"-100{chat_id}"))
+ return await get_chat(client, int(f"-100{chat_id}"))
except Exception:
chat = Chat(id=1)
cache.set(f"chat-info-{slim_cid(chat_id)}", chat, ttl=3600) # cache for 1 hour
src/llm/gpt.py
@@ -18,8 +18,7 @@ from messages.parser import parse_msg
from messages.progress import modify_progress
from messages.sender import send2tg
from messages.utils import count_without_entities, equal_prefix, startswith_prefix
-from permission import slim_cid
-from utils import env_list
+from utils import env_list, slim_cid
HELP = f"""🤖**GPT对话**
`{PREFIX.GPT}` 后接提示词即可与GPT对话
src/permission.py
@@ -8,7 +8,7 @@ from pyrogram.client import Client
from pyrogram.types import Message
from config import ENABLE, TID, cache
-from utils import i_am_bot, to_int, true
+from utils import i_am_bot, slim_cid, to_int, true
# ruff: noqa: SIM103
@@ -187,7 +187,3 @@ def check_service(cid: int | str, ctype: str) -> dict:
logger.warning(f"Set `{option}` for chat={cid} to {to_bool(value)}")
logger.success(f"Permission for chat={cid}: {permission}")
return permission
-
-
-def slim_cid(cid: int | str) -> str:
- return str(cid).strip().removeprefix("-100")
src/utils.py
@@ -290,6 +290,10 @@ def ts_to_dt(ts: str | float | None) -> datetime | None:
return None
+def slim_cid(cid: int | str) -> str:
+ return str(cid).strip().removeprefix("-100")
+
+
def env_list(value: str | None = None, *, env_key: str = "", separator: str = ",") -> list[str]:
"""Get list from environment variable."""
if value is None: