fix(xxm): use send_message instead of send_raw for proper UTF-8 encoding
This commit is contained in:
+10
-24
@@ -343,7 +343,6 @@ def _schedule_delayed(delay_sec: int, room: str):
|
||||
"""Schedule ##delay:N## re-invocation."""
|
||||
global _xmpp_ref
|
||||
import subprocess as _sp
|
||||
from xml.sax.saxutils import escape
|
||||
|
||||
def _fire():
|
||||
bot = _xmpp_ref
|
||||
@@ -354,10 +353,9 @@ def _schedule_delayed(delay_sec: int, room: str):
|
||||
raw = _call_llm(prompt, room, is_group=True)
|
||||
reply = _extract_response(raw)
|
||||
if reply:
|
||||
safe = escape(reply.strip())
|
||||
stanza = f"<message to='{room}' type='groupchat'><body>{safe}</body></message>"
|
||||
bot.send_raw(stanza)
|
||||
log(f"-> [Delay][{room}]: {reply.strip()[:80]}")
|
||||
text = reply.strip()
|
||||
bot.send_message(mto=room, mbody=text, mtype='groupchat')
|
||||
log(f"-> [Delay][{room}]: {text[:80]}")
|
||||
except Exception as e:
|
||||
log(f"!! delay err: {e}")
|
||||
|
||||
@@ -580,8 +578,7 @@ class _BridgeHandler(http.server.BaseHTTPRequestHandler):
|
||||
safe = _escape(msg.strip())
|
||||
bot = _xmpp_ref
|
||||
if bot:
|
||||
stanza = f'<message to="{to}" type="groupchat"><body>{safe}</body></message>'
|
||||
bot.send_raw(stanza)
|
||||
bot.send_message(mto=to, mbody=msg.strip(), mtype='groupchat')
|
||||
_record_group_msg(cfg["nick"], msg)
|
||||
log(f"[http] → [{to.split('@')[0]}]: {msg[:80]}")
|
||||
self._reply(200, {"ok": True})
|
||||
@@ -634,12 +631,11 @@ def _process_llm_reply(raw_reply: str, room: str):
|
||||
# Extract actual response
|
||||
reply_text = _extract_response(raw_reply)
|
||||
if reply_text:
|
||||
safe = _escape(reply_text.strip())
|
||||
text = reply_text.strip()
|
||||
bot = _xmpp_ref
|
||||
if bot:
|
||||
stanza = f"<message to='{room}' type='groupchat'><body>{safe}</body></message>"
|
||||
bot.send_raw(stanza)
|
||||
log(f"-> [{room.split('@')[0]}]: {reply_text.strip()[:80]}")
|
||||
bot.send_message(mto=room, mbody=text, mtype='groupchat')
|
||||
log(f"-> [{room.split('@')[0]}]: {text[:80]}")
|
||||
else:
|
||||
log(f"-> [{room.split('@')[0]}]: (silent)")
|
||||
_batch_done(room)
|
||||
@@ -716,21 +712,11 @@ def _handle_private_message(msg):
|
||||
if raw:
|
||||
reply = _extract_response(raw)
|
||||
if reply:
|
||||
from xml.sax.saxutils import escape
|
||||
safe = escape(reply.strip())
|
||||
if _IS_CHAT_BRIDGE:
|
||||
text = reply.strip()
|
||||
bot = _xmpp_ref
|
||||
if bot:
|
||||
stanza = f"<message to='{sender}' type='chat'><body>{safe}</body></message>"
|
||||
bot.send_raw(stanza)
|
||||
log(f"-> {sender}: {reply.strip()[:80]}")
|
||||
else:
|
||||
import subprocess as sp
|
||||
sp.run(["docker", "exec", "ejabberd", "ejabberdctl", "send_stanza",
|
||||
cfg["jid"], sender,
|
||||
f"<message from='{cfg['jid']}' to='{sender}' type='chat' xml:lang='en'><body>{safe}</body></message>"
|
||||
], capture_output=True, timeout=10)
|
||||
log(f"-> {sender}: {reply.strip()[:80]}")
|
||||
bot.send_message(mto=sender, mbody=text, mtype='chat')
|
||||
log(f"-> {sender}: {text[:80]}")
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
|
||||
Reference in New Issue
Block a user