From 01523ae8cee20695eb6e9d0c4ecd705c6a317baa Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 12 Feb 2019 14:58:12 +0200 Subject: Fix go vet warning --- ui/messages/imagemessage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/messages/imagemessage.go b/ui/messages/imagemessage.go index 0efe676..cad76a4 100644 --- a/ui/messages/imagemessage.go +++ b/ui/messages/imagemessage.go @@ -80,7 +80,7 @@ func (msg *ImageMessage) updateData() { debug.Print("Loading image:", msg.Homeserver, msg.FileID) data, _, _, err := msg.matrix.Download(fmt.Sprintf("mxc://%s/%s", msg.Homeserver, msg.FileID)) if err != nil { - debug.Print("Failed to download image %s/%s: %v", msg.Homeserver, msg.FileID, err) + debug.Printf("Failed to download image %s/%s: %v", msg.Homeserver, msg.FileID, err) return } debug.Print("Image", msg.Homeserver, msg.FileID, "loaded.") -- cgit v1.2.3 From 576de5264e4d481467e3019ebe7d23a7a7c9a0af Mon Sep 17 00:00:00 2001 From: Pascal Abresch Date: Tue, 19 Mar 2019 15:57:50 +0100 Subject: adds /msend --- ui/command-processor.go | 2 ++ ui/commands.go | 9 +++++++++ 2 files changed, 11 insertions(+) (limited to 'ui') diff --git a/ui/command-processor.go b/ui/command-processor.go index 0aed4b2..dffd7e9 100644 --- a/ui/command-processor.go +++ b/ui/command-processor.go @@ -78,6 +78,7 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor { aliases: map[string]*Alias{ "part": {"leave"}, "send": {"sendevent"}, + "msend": {"msendevent"}, "state": {"setstate"}, "rb": {"rainbow"}, }, @@ -92,6 +93,7 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor { "toggle": cmdToggle, "logout": cmdLogout, "sendevent": cmdSendEvent, + "msendevent": cmdMSendEvent, "setstate": cmdSetState, "rainbow": cmdRainbow, }, diff --git a/ui/commands.go b/ui/commands.go index 12a99de..39b1a46 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -129,6 +129,15 @@ func cmdJoin(cmd *Command) { } } +func cmdMSendEvent(cmd *Command) { + if len(cmd.Args) < 2 { + cmd.Reply("Usage: /msend ") + return + } + cmd.Args = append([]string{cmd.Room.MxRoom().ID},cmd.Args...) + cmdSendEvent(cmd) +} + func cmdSendEvent(cmd *Command) { debug.Print(cmd.Command, cmd.Args, len(cmd.Args)) if len(cmd.Args) < 3 { -- cgit v1.2.3 From e9b76ccfec15ecab21c10f5a0133528526e856f7 Mon Sep 17 00:00:00 2001 From: Pascal Abresch Date: Tue, 19 Mar 2019 15:58:57 +0100 Subject: adds /msetstate --- ui/command-processor.go | 2 ++ ui/commands.go | 9 +++++++++ 2 files changed, 11 insertions(+) (limited to 'ui') diff --git a/ui/command-processor.go b/ui/command-processor.go index dffd7e9..b18f950 100644 --- a/ui/command-processor.go +++ b/ui/command-processor.go @@ -80,6 +80,7 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor { "send": {"sendevent"}, "msend": {"msendevent"}, "state": {"setstate"}, + "mstate":{"msetstate"}, "rb": {"rainbow"}, }, commands: map[string]CommandHandler{ @@ -95,6 +96,7 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor { "sendevent": cmdSendEvent, "msendevent": cmdMSendEvent, "setstate": cmdSetState, + "msetstate": cmdMSetState, "rainbow": cmdRainbow, }, } diff --git a/ui/commands.go b/ui/commands.go index 39b1a46..7175a21 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -167,6 +167,15 @@ func cmdSendEvent(cmd *Command) { } } +func cmdMSetState(cmd *Command) { + if len(cmd.Args) < 2 { + cmd.Reply("Usage: /msetstate ") + return + } + cmd.Args = append([]string{cmd.Room.MxRoom().ID},cmd.Args...) + cmdSetState(cmd) +} + func cmdSetState(cmd *Command) { if len(cmd.Args) < 4 { cmd.Reply("Usage: /setstate ") -- cgit v1.2.3 From c5bf3f894c4efad71757f0d64ec128c01cdc5805 Mon Sep 17 00:00:00 2001 From: Pascal Abresch Date: Tue, 19 Mar 2019 16:06:18 +0100 Subject: fixed send and setstate to allow spaces --- ui/commands.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/commands.go b/ui/commands.go index 7175a21..eb2a442 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -146,7 +146,7 @@ func cmdSendEvent(cmd *Command) { } roomID := cmd.Args[0] eventType := mautrix.NewEventType(cmd.Args[1]) - rawContent := strings.Join(cmd.Args[2:], "") + rawContent := strings.Join(cmd.Args[2:], " ") debug.Print(roomID, eventType, rawContent) var content interface{} @@ -188,7 +188,7 @@ func cmdSetState(cmd *Command) { if stateKey == "-" { stateKey = "" } - rawContent := strings.Join(cmd.Args[3:], "") + rawContent := strings.Join(cmd.Args[3:], " ") var content interface{} err := json.Unmarshal([]byte(rawContent), &content) -- cgit v1.2.3 From cefa840c28067e33bf67dd65aa267779cdeae34e Mon Sep 17 00:00:00 2001 From: Pascal Abresch Date: Tue, 19 Mar 2019 16:06:40 +0100 Subject: adds kick, ban, unban and invite command --- ui/command-processor.go | 4 ++++ ui/commands.go | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) (limited to 'ui') diff --git a/ui/command-processor.go b/ui/command-processor.go index b18f950..77a7b3d 100644 --- a/ui/command-processor.go +++ b/ui/command-processor.go @@ -91,6 +91,9 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor { "clearcache": cmdClearCache, "leave": cmdLeave, "join": cmdJoin, + "kick": cmdKick, + "ban": cmdBan, + "unban": cmdUnban, "toggle": cmdToggle, "logout": cmdLogout, "sendevent": cmdSendEvent, @@ -98,6 +101,7 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor { "setstate": cmdSetState, "msetstate": cmdMSetState, "rainbow": cmdRainbow, + "invite": cmdInvite, }, } } diff --git a/ui/commands.go b/ui/commands.go index eb2a442..bba1644 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -112,6 +112,64 @@ func cmdLeave(cmd *Command) { } } +func cmdInvite(cmd *Command) { + if len(cmd.Args) != 1 { + cmd.Reply("Usage: /invite ") + return + } + _, err := cmd.Matrix.Client().InviteUser(cmd.Room.MxRoom().ID, &mautrix.ReqInviteUser{cmd.Args[0]}) + if err != nil { + debug.Print("Error in invite call:", err) + cmd.Reply("Failed to invite user:", err) + } +} + +func cmdBan(cmd *Command) { + if len(cmd.Args) < 1 { + cmd.Reply("Usage: /ban ") + return + } + reason := "you are the weakest link, goodbye!" + if len(cmd.Args) >= 2 { + reason = strings.Join(cmd.Args[1:]," ") + } + _, err := cmd.Matrix.Client().BanUser(cmd.Room.MxRoom().ID, &mautrix.ReqBanUser{reason,cmd.Args[0]}) + if err != nil { + debug.Print("Error in ban call:", err) + cmd.Reply("Failed to ban user:", err) + } + +} + +func cmdUnban(cmd *Command) { + if len(cmd.Args) != 1 { + cmd.Reply("Usage: /unban ") + return + } + _, err := cmd.Matrix.Client().UnbanUser(cmd.Room.MxRoom().ID, &mautrix.ReqUnbanUser{cmd.Args[0]}) + if err != nil { + debug.Print("Error in unban call:", err) + cmd.Reply("Failed to unban user:", err) + } +} + +func cmdKick(cmd *Command) { + if len(cmd.Args) < 1 { + cmd.Reply("Usage: /kick ") + return + } + reason := "you are the weakest link, goodbye!" + if len(cmd.Args) >= 2 { + reason = strings.Join(cmd.Args[1:]," ") + } + _, err := cmd.Matrix.Client().KickUser(cmd.Room.MxRoom().ID, &mautrix.ReqKickUser{reason,cmd.Args[0]}) + if err != nil { + debug.Print("Error in kick call:", err) + debug.Print("Failed to kick user:", err) + } + +} + func cmdJoin(cmd *Command) { if len(cmd.Args) == 0 { cmd.Reply("Usage: /join ") -- cgit v1.2.3