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