commit e1ec501

delthas  ·  2023-11-13 12:17:05 +0000 UTC
parent d2b79de
Add an optional message argument to KICK

Fixes: https://todo.sr.ht/~taiite/senpai/126
2 files changed,  +17, -8
+14, -6
 1@@ -174,8 +174,8 @@ func init() {
 2 		"KICK": {
 3 			AllowHome: true,
 4 			MinArgs:   1,
 5-			MaxArgs:   2,
 6-			Usage:     "<nick> [channel]",
 7+			MaxArgs:   3,
 8+			Usage:     "<nick> [channel] [message]",
 9 			Desc:      "eject someone from the channel",
10 			Handle:    commandDoKick,
11 		},
12@@ -623,14 +623,22 @@ func commandDoKick(app *App, args []string) (err error) {
13 	if s == nil {
14 		return errOffline
15 	}
16+	// Check whether the argument after the user is a channel, to accept both:
17+	// - KICK user #chan you are mean
18+	// - KICK user you are mean
19+	comment := ""
20 	if len(args) >= 2 {
21-		channel = args[1]
22-	} else if channel == "" {
23+		if s.IsChannel(args[1]) {
24+			channel = args[1]
25+		} else {
26+			comment = args[1] + " "
27+		}
28+	}
29+	if channel == "" {
30 		return fmt.Errorf("either send this command from a channel, or specify the channel")
31 	}
32-	comment := ""
33 	if len(args) == 3 {
34-		comment = args[2]
35+		comment += args[2]
36 	}
37 	s.Kick(nick, channel, comment)
38 	return nil
+3, -2
 1@@ -198,8 +198,9 @@ _name_ is matched case-insensitively.  It can be one of the following:
 2 *INVITE* <nick> [channel]
 3 	Invite _nick_ to _channel_ (the current channel if not given).
 4 
 5-*KICK* <nick> [channel]
 6-	Eject _nick_ from _channel_ (the current channel if not given).
 7+*KICK* <nick> [channel] [message]
 8+	Eject _nick_ from _channel_ (the current channel if not given) with an
 9+	optional kick message/reason.
10 
11 *BAN* <nick> [channel]
12 	Ban _nick_ from entering _channel_ (the current channel if not given).