From ae3bb9c7a39202ba462b3b8a0a564804a5517cf4 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 14 Jun 2019 21:01:24 +0300 Subject: Add pm command --- ui/command-processor.go | 16 ++++++++++------ ui/commands.go | 21 +++++++++++++++++++-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/ui/command-processor.go b/ui/command-processor.go index 0692ae3..96b1ada 100644 --- a/ui/command-processor.go +++ b/ui/command-processor.go @@ -76,12 +76,15 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor { Gomuks: parent.gmx, }, aliases: map[string]*Alias{ - "part": {"leave"}, - "send": {"sendevent"}, - "msend": {"msendevent"}, - "state": {"setstate"}, - "mstate": {"msetstate"}, - "rb": {"rainbow"}, + "part": {"leave"}, + "send": {"sendevent"}, + "msend": {"msendevent"}, + "state": {"setstate"}, + "mstate": {"msetstate"}, + "rb": {"rainbow"}, + "createroom": {"create"}, + "dm": {"pm"}, + "query": {"pm"}, }, commands: map[string]CommandHandler{ "unknown-command": cmdUnknownCommand, @@ -91,6 +94,7 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor { "clearcache": cmdClearCache, "leave": cmdLeave, "create": cmdCreateRoom, + "pm": cmdPrivateMessage, "join": cmdJoin, "kick": cmdKick, "ban": cmdBan, diff --git a/ui/commands.go b/ui/commands.go index b418e84..5bcba98 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -27,8 +27,9 @@ import ( "github.com/lucasb-eyer/go-colorful" - "maunium.net/go/gomuks/debug" "maunium.net/go/mautrix" + + "maunium.net/go/gomuks/debug" ) func cmdMe(cmd *Command) { @@ -122,6 +123,7 @@ func cmdHelp(cmd *Command) { /rainbow - Send a rainbow message (markdown not supported). /create [room name] - Create a room. +/pm <...> - Create a private chat with the given user(s). /join - Join a room. /leave - Leave the current room. @@ -201,7 +203,6 @@ func cmdKick(cmd *Command) { debug.Print("Error in kick call:", err) debug.Print("Failed to kick user:", err) } - } func cmdCreateRoom(cmd *Command) { @@ -217,6 +218,22 @@ func cmdCreateRoom(cmd *Command) { cmd.MainView.SwitchRoom("", room) } +func cmdPrivateMessage(cmd *Command) { + if len(cmd.Args) == 0 { + cmd.Reply("Usage: /pm [more user ids...]") + } + req := &mautrix.ReqCreateRoom{ + Preset: "trusted_private_chat", + Invite: cmd.Args, + } + room, err := cmd.Matrix.CreateRoom(req) + if err != nil { + cmd.Reply("Failed to create room:", err) + return + } + cmd.MainView.SwitchRoom("", room) +} + func cmdJoin(cmd *Command) { if len(cmd.Args) == 0 { cmd.Reply("Usage: /join ") -- cgit v1.2.3