This commit is contained in:
Your Name
2026-09-01 15:58:34 +08:00
parent 2fc864cc00
commit 89cae5b8cc
8 changed files with 295 additions and 63 deletions
+16 -2
View File
@@ -1556,12 +1556,14 @@ class DouyinImService:
conversation_id: str,
content: str,
conversation_short_id: str = "",
expected_peer_uid: str = "",
) -> tuple[bool, Optional[dict]]:
async with self._session_lock:
return await self._send_text_unlocked(
conversation_id,
content,
conversation_short_id=conversation_short_id,
expected_peer_uid=expected_peer_uid,
)
async def _send_text_unlocked(
@@ -1569,6 +1571,7 @@ class DouyinImService:
conversation_id: str,
content: str,
conversation_short_id: str = "",
expected_peer_uid: str = "",
) -> tuple[bool, Optional[dict]]:
"""发送一条私信;若因签名凭证失效(7911)失败,刷新 web_protect 后自动重试一次。
@@ -1580,6 +1583,7 @@ class DouyinImService:
conversation_id,
content,
conversation_short_id=conversation_short_id,
expected_peer_uid=expected_peer_uid,
)
self.last_error = http.last_error
needs_refresh = http.last_send_needs_refresh
@@ -1681,8 +1685,17 @@ class DouyinImService:
except Exception as e:
logger.error(f"on_session_invalid handler error: {e}")
async def send_message(self, conversation_id: str, content: str) -> bool:
"""手动发送私信"""
async def send_message(
self,
conversation_id: str,
content: str,
expected_peer_uid: str = "",
) -> bool:
"""手动发送私信。
``expected_peer_uid`` 由调用方(消息页)指定收件人,写入点会在发出去
之前核对,避免界面按昵称匹配到同名的另一个人。
"""
from .conv_util import normalize_conversation_id
from .auth import DouyinAuth
from .dy_util import DEFAULT_USER_AGENT
@@ -1705,6 +1718,7 @@ class DouyinImService:
conversation_id,
content,
conversation_short_id=str(meta.get("conversation_short_id") or ""),
expected_peer_uid=expected_peer_uid,
)
if sent and resolved:
self._conv_meta[conversation_id] = {