57 lines
3.0 KiB
Python
57 lines
3.0 KiB
Python
from pathlib import Path
|
|
import ast,os
|
|
for root in (Path('C:/kefu/wechat_rpa'),Path('C:/wechat_rpa')):
|
|
p=root/'wechat_bot.py'
|
|
text=p.read_text(encoding='utf-8')
|
|
old=''' return bool(entry.get("draft") and str(draft).replace("\\r\\n", "\\n") ==
|
|
str(entry["draft"]).replace("\\r\\n", "\\n"))'''
|
|
new=''' matches = bool(entry.get("draft") and str(draft).replace("\\r\\n", "\\n") ==
|
|
str(entry["draft"]).replace("\\r\\n", "\\n"))
|
|
if entry and not matches:
|
|
self._retire_discarded_review_marker(state)
|
|
return matches'''
|
|
assert text.count(old)==1
|
|
text=text.replace(old,new)
|
|
needle=' def _record_assistant_automated_attempt(self, state, reply_text):'
|
|
method=''' def _retire_discarded_review_marker(self, state):
|
|
discarded = getattr(self, "_review_assistant_discarded_drafts", {})
|
|
if not discarded:
|
|
return True
|
|
try:
|
|
context = self._review_assistant_context(state or {})
|
|
if not context:
|
|
return False
|
|
key = str(context["account"]) + "\\0" + str(context["conv_id"])
|
|
old = discarded.pop(key, None)
|
|
if old is None:
|
|
return True
|
|
if self._persist_pending_replies():
|
|
return True
|
|
discarded[key] = old
|
|
except Exception:
|
|
if 'old' in locals() and old is not None:
|
|
discarded[key] = old
|
|
return False
|
|
|
|
'''
|
|
assert text.count(needle)==1
|
|
text=text.replace(needle,method+needle)
|
|
needle=''' self._clear_foreign_draft_hold(expected_fp)
|
|
print(" [助理审核] 已核对人工回复,仅清除本会话作废的原始 AI 草稿,重新处理新消息。")'''
|
|
assert text.count(needle)==1
|
|
text=text.replace(needle,''' if not self._retire_discarded_review_marker(pending_state):
|
|
return self._deny_send("已清除旧审核稿,但作废记录尚未保存,等待重试")
|
|
self._clear_foreign_draft_hold(expected_fp)
|
|
print(" [助理审核] 已核对人工回复,仅清除本会话作废的原始 AI 草稿,重新处理新消息。")''')
|
|
needle=''' normalized_draft = self._normalized_message_text(existing_draft)
|
|
if normalized_draft:
|
|
if self._is_discarded_review_draft'''
|
|
assert text.count(needle)==1
|
|
text=text.replace(needle,''' normalized_draft = self._normalized_message_text(existing_draft)
|
|
if not normalized_draft and not self._retire_discarded_review_marker(pending_state):
|
|
return self._deny_send("旧审核稿作废记录尚未保存,等待重试")
|
|
if normalized_draft:
|
|
if self._is_discarded_review_draft''')
|
|
ast.parse(text)
|
|
temp=p.with_suffix('.assistant.tmp');temp.write_text(text,encoding='utf-8',newline='\n');os.replace(temp,p)
|