From b6ee0f901e67f9f938ca66175c47bc7d489fcbd3 Mon Sep 17 00:00:00 2001 From: saces Date: Fri, 6 Feb 2026 18:34:15 +0100 Subject: [PATCH] improve message sending --- libmxclient/mxclient/client.go | 10 +++------- smal/src/demobot/demobot.py | 8 +++++++- smal/src/smal/bot.py | 17 +++++++++++++++++ smal/src/smal/pygomx.py | 7 ++----- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/libmxclient/mxclient/client.go b/libmxclient/mxclient/client.go index 4b3d2a7..3ec1267 100644 --- a/libmxclient/mxclient/client.go +++ b/libmxclient/mxclient/client.go @@ -75,14 +75,10 @@ func (mxc *MXClient) _onMessage(ctx context.Context, evt *event.Event) { */ } -type sendmessage_data_content struct { - Body string `json:"body"` -} - type sendmessage_data struct { - RoomId id.RoomID `json:"roomid"` - Type event.Type `json:"type"` - Content sendmessage_data_content `json:"content"` + RoomId id.RoomID `json:"roomid"` + Type event.Type `json:"type"` + Content map[string]any `json:"content"` } func (mxc *MXClient) SendRoomMessage(ctx context.Context, data string) (*mautrix.RespSendEvent, error) { diff --git a/smal/src/demobot/demobot.py b/smal/src/demobot/demobot.py index 8f58537..8f6f4e8 100644 --- a/smal/src/demobot/demobot.py +++ b/smal/src/demobot/demobot.py @@ -48,7 +48,13 @@ class DemoBot(SMALBot): if msg["content"]["body"].startswith("!echo"): logger.error(f"reply to this: {msg}") - self.sendmessage(msg["roomid"], "huhu") + txt = msg["content"]["body"][5:].strip() + + if txt.strip() == "": + txt = "Are you kidding me?" + + # self.sendmessage(msg["roomid"], txt) + self.sendmessagereply(msg["roomid"], msg["id"], msg["sender"], txt) return diff --git a/smal/src/smal/bot.py b/smal/src/smal/bot.py index 6ee0f29..bc44d7d 100644 --- a/smal/src/smal/bot.py +++ b/smal/src/smal/bot.py @@ -30,5 +30,22 @@ class SMALBot(SMALApp): data["roomid"] = roomid data["content"] = {} data["content"]["body"] = text + data["content"]["msgtype"] = "m.text" + + self._sendmessage(data) + + def sendmessagereply(self, roomid, msgid, mxid, text): + data = {} + data["roomid"] = roomid + data["content"] = {} + data["content"]["body"] = text + data["content"]["msgtype"] = "m.text" + data["content"]["m.mentions"] = {} + data["content"]["m.mentions"]["user_ids"] = [ + mxid, + ] + data["content"]["m.relates_to"] = {} + data["content"]["m.relates_to"]["m.in_reply_to"] = {} + data["content"]["m.relates_to"]["m.in_reply_to"]["event_id"] = msgid self._sendmessage(data) diff --git a/smal/src/smal/pygomx.py b/smal/src/smal/pygomx.py index 7dc28e5..bdb5188 100644 --- a/smal/src/smal/pygomx.py +++ b/smal/src/smal/pygomx.py @@ -74,11 +74,8 @@ class _MXClient: def _sendmessage(self, data_dict): data = json.dumps(data_dict).encode(encoding="utf-8") r = lib.apiv0_sendmessage(self.client_id, data) - result = ffi.string(r) - lib.FreeCString(r) - # if result.startswith(b"ERR:"): - # raise APIError(result) - print("_sendmessage: ", result) + result = checkApiError(r) + return result def process_event(self, evt): if hasattr(self, "on_event") and callable(self.on_event):