~rumpelsepp/public-inbox

mnotify: Add room state command v1 APPLIED

Cadence Ember: 1
 Add room state command

 2 files changed, 18 insertions(+), 0 deletions(-)
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/13929/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH mnotify] Add room state command Export this patch

From: Cadence Ember <cloudrac3r@vivaldi.net>
---
Saw this project and had to contribute.
This is my first time using Go.

Try it: ./mnotify room -R '!Room:server.tld' --state
'm.room.power_levels/'

 cmd_room.go | 17 +++++++++++++++++
 main.go     |  1 +
 2 files changed, 18 insertions(+)

diff --git a/cmd_room.go b/cmd_room.go
index 90ce2b2..b109184 100644
--- a/cmd_room.go
+++ b/cmd_room.go
@@ -4,6 +4,7 @@ import (
	"encoding/json"
	"fmt"
	"os"
	"strings"

	"github.com/spf13/cobra"
	"maunium.net/go/mautrix"
@@ -25,8 +26,11 @@ type roomCommand struct {
	includeMembers bool
	number         uint
	profile        string
	state          string
}

type anyEvent map[string]interface{}

const (
	profilePrivate        = "private_chat"
	profileTrustedPrivate = "trusted_private_chat"
@@ -79,6 +83,19 @@ func (c *roomCommand) run(cmd *cobra.Command, args []string) error {
				return err
			}
		}
	case c.state != "":
		if strings.Contains(c.state, "/") {
			var (
				split = strings.Split(c.state, "/")
				eventType = event.Type{split[0], event.StateEventType}
				content anyEvent
			)
			client.StateEvent(roomID, eventType, split[1], &content)
			o, _ := json.Marshal(content)
			fmt.Println(string(o))
		} else {
			fmt.Println("--state: you must supply a state key and event type separated by /")
		}
	case c.list:
		rooms, err := client.JoinedRooms()
		if err != nil {
diff --git a/main.go b/main.go
index cc7e338..4a0941e 100644
--- a/main.go
+++ b/main.go
@@ -210,6 +210,7 @@ func main() {
	roomFlags.BoolVarP(&roomCmd.join, "join", "", false, "Join a room")
	roomFlags.BoolVarP(&roomCmd.messages, "messages", "m", false, "List messages of a room")
	roomFlags.UintVarP(&roomCmd.number, "number", "n", 10, "List messages of a room")
	roomFlags.StringVarP(&roomCmd.state, "state", "", "", "Output the value of a state/type key")
	rootCobraCmd.AddCommand(roomCobraCmd)

	// send
-- 
2.25.1