diff options
author | Alexey Yerin <yyp@disroot.org> | 2021-12-06 23:09:08 +0300 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-12-07 08:44:34 +0100 |
commit | 65718d37abc15e727c20b9b031d32b953b258d2a (patch) | |
tree | 427294504a61dda88a7054c38cf22295d10efc34 /commands.go | |
parent | Allow selecting buffers with Alt+{1..9} (diff) |
Implement /kick and /[un]ban commands
Diffstat (limited to 'commands.go')
-rw-r--r-- | commands.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/commands.go b/commands.go index 5dff158..403aec8 100644 --- a/commands.go +++ b/commands.go @@ -142,6 +142,30 @@ func init() { Desc: "invite someone to a channel", Handle: commandDoInvite, }, + "KICK": { + AllowHome: false, + MinArgs: 1, + MaxArgs: 2, + Usage: "<nick> [channel]", + Desc: "eject someone from the channel", + Handle: commandDoKick, + }, + "BAN": { + AllowHome: false, + MinArgs: 1, + MaxArgs: 2, + Usage: "<nick> [channel]", + Desc: "ban someone from entering the channel", + Handle: commandDoBan, + }, + "UNBAN": { + AllowHome: false, + MinArgs: 1, + MaxArgs: 2, + Usage: "<nick> [channel]", + Desc: "remove effect of a ban from the user", + Handle: commandDoUnban, + }, } } @@ -506,6 +530,58 @@ func commandDoInvite(app *App, args []string) (err error) { return nil } +func commandDoKick(app *App, args []string) (err error) { + nick := args[0] + netID, channel := app.win.CurrentBuffer() + s := app.sessions[netID] + if s == nil { + return errOffline + } + if len(args) >= 2 { + channel = args[1] + } else if channel == "" { + return fmt.Errorf("either send this command from a channel, or specify the channel") + } + comment := "" + if len(args) == 3 { + comment = args[2] + } + s.Kick(nick, channel, comment) + return nil +} + +func commandDoBan(app *App, args []string) (err error) { + nick := args[0] + netID, channel := app.win.CurrentBuffer() + s := app.sessions[netID] + if s == nil { + return errOffline + } + if len(args) == 2 { + channel = args[1] + } else if channel == "" { + return fmt.Errorf("either send this command from a channel, or specify the channel") + } + s.ChangeMode(channel, "+b", []string{nick}) + return nil +} + +func commandDoUnban(app *App, args []string) (err error) { + nick := args[0] + netID, channel := app.win.CurrentBuffer() + s := app.sessions[netID] + if s == nil { + return errOffline + } + if len(args) == 2 { + channel = args[1] + } else if channel == "" { + return fmt.Errorf("either send this command from a channel, or specify the channel") + } + s.ChangeMode(channel, "-b", []string{nick}) + return nil +} + // implemented from https://golang.org/src/strings/strings.go?s=8055:8085#L310 func fieldsN(s string, n int) []string { s = strings.TrimSpace(s) |