~rumpelsepp/public-inbox

mnotify: Various changes I made for myself v1 APPLIED

They were useful in my script, so maybe they'll be useful for you.

You'll probably want to improve the documentation, I don't know.

Cadence Ember (3):
  sync --once
  room -l -R: examines a single room
  send --formatted: sets HTML content

 cmd_room.go | 33 +++++++++++++++++++++------------
 cmd_send.go |  9 ++++++++-
 cmd_sync.go |  5 +++++
 main.go     |  2 ++
 4 files changed, 36 insertions(+), 13 deletions(-)

-- 
2.25.1
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rumpelsepp/public-inbox/patches/13964/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH mnotify 1/3] sync --once Export this patch

---
 cmd_sync.go | 5 +++++
 main.go     | 1 +
 2 files changed, 6 insertions(+)

diff --git a/cmd_sync.go b/cmd_sync.go
index 866cbd0..cb72420 100644
--- a/cmd_sync.go
+++ b/cmd_sync.go
@@ -14,6 +14,7 @@ import (
type syncCommand struct {
	globalOpts  *globalOptions
	presence    bool
	once        bool
	syncTimeout int
}

@@ -119,5 +120,9 @@ func (c *syncCommand) run(cmd *cobra.Command, args []string) error {

		nextBatch = resp.NextBatch
		c.printSync(resp)

		if c.once {
			return nil
		}
	}
}
diff --git a/main.go b/main.go
index 4a0941e..8c6a449 100644
--- a/main.go
+++ b/main.go
@@ -234,6 +234,7 @@ func main() {
	// sync
	rootCobraCmd.AddCommand(syncCobraCmd)
	syncFlags := syncCobraCmd.Flags()
	syncFlags.BoolVarP(&syncCmd.once, "once", "", false, "Just sync once (without this, will sync forever)")
	syncFlags.BoolVarP(&syncCmd.presence, "presence", "p", false, "Set presence to online")
	syncFlags.IntVarP(&syncCmd.syncTimeout, "timeout", "t", 30000, "Matrix sync timeout in ms")

-- 
2.25.1

[PATCH mnotify 2/3] room -l -R: examines a single room Export this patch

---
 cmd_room.go | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/cmd_room.go b/cmd_room.go
index b109184..ef6cd33 100644
--- a/cmd_room.go
+++ b/cmd_room.go
@@ -101,7 +101,8 @@ func (c *roomCommand) run(cmd *cobra.Command, args []string) error {
		if err != nil {
			return err
		}
		for _, roomID := range rooms.JoinedRooms {

		var eachRoom = func(roomID id.RoomID) {
			var (
				room  = mautrix.NewRoom(roomID)
				event = room.GetStateEvent(event.StateCanonicalAlias, "")
@@ -116,18 +117,18 @@ func (c *roomCommand) run(cmd *cobra.Command, args []string) error {
				members, err := client.JoinedMembers(room.ID)
				if err != nil {
					fmt.Printf("error room %s: %s\n", roomID, err)
					continue
				}
				for k, v := range members.Joined {
					var displayName string
					if v.DisplayName != nil {
						displayName = *v.DisplayName
				} else {
					for k, v := range members.Joined {
						var displayName string
						if v.DisplayName != nil {
							displayName = *v.DisplayName
						}
						m := member{
							UserID:      string(k),
							DisplayName: displayName,
						}
						out.Members = append(out.Members, m)
					}
					m := member{
						UserID:      string(k),
						DisplayName: displayName,
					}
					out.Members = append(out.Members, m)
				}
			}
			if c.globalOpts.json {
@@ -140,6 +141,14 @@ func (c *roomCommand) run(cmd *cobra.Command, args []string) error {
				}
			}
		}

		if roomID != "" {
			eachRoom(roomID)
		} else {
			for _, roomID := range rooms.JoinedRooms {
				eachRoom(roomID)
			}
		}
	case c.join:
		if roomID == "" {
			dieNoRoomID()
-- 
2.25.1

[PATCH mnotify 3/3] send --formatted: sets HTML content Export this patch

---
 cmd_send.go | 9 ++++++++-
 main.go     | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/cmd_send.go b/cmd_send.go
index 84202be..eed39d9 100644
--- a/cmd_send.go
+++ b/cmd_send.go
@@ -6,11 +6,13 @@ import (

	"github.com/spf13/cobra"
	"maunium.net/go/mautrix/id"
	"maunium.net/go/mautrix/event"
)

type sendCommand struct {
	globalOpts *globalOptions
	message    string
	formatted  string
	    string
}

@@ -32,7 +34,12 @@ func (c *sendCommand) run(cmd *cobra.Command, args []string) error {
		msg = string(m)
	}

	_, err = c.globalOpts.client.SendText(id.RoomID(c.globalOpts.roomID), msg)
	if c.formatted != "" {
		var f = event.MessageEventContent{MsgType: "m.text", Body: msg, Format: "org.matrix.custom.html", FormattedBody: c.formatted}
		_, err = c.globalOpts.client.SendMessageEvent(id.RoomID(c.globalOpts.roomID), event.Type{"m.room.message", event.MessageEventType}, f)
	} else {
		_, err = c.globalOpts.client.SendText(id.RoomID(c.globalOpts.roomID), msg)
	}
	if err != nil {
		return err
	}
diff --git a/main.go b/main.go
index 8c6a449..95b68db 100644
--- a/main.go
+++ b/main.go
@@ -216,6 +216,7 @@ func main() {
	// send
	sendFlags := sendCobraCmd.Flags()
	sendFlags.StringVarP(&sendCmd.message, "message", "m", "", "Send this message instead of stdin")
	sendFlags.StringVarP(&sendCmd.formatted, "formatted", "", "", "Alternative formatted text")
	rootCobraCmd.AddCommand(sendCobraCmd)

	// synapse
-- 
2.25.1