From cefa840c28067e33bf67dd65aa267779cdeae34e Mon Sep 17 00:00:00 2001 From: Pascal Abresch Date: Tue, 19 Mar 2019 16:06:40 +0100 Subject: [PATCH] adds kick, ban, unban and invite command --- ui/command-processor.go | 4 +++ ui/commands.go | 58 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) 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 ")