commit 5ab6aa2

Hubert Hirtz  ·  2021-10-23 16:42:50 +0000 UTC
parent ee83827
Add an /invite command
3 files changed,  +29, -1
+20, -0
 1@@ -121,6 +121,14 @@ func init() {
 2 			Desc:      "switch to the buffer containing a substring",
 3 			Handle:    commandDoBuffer,
 4 		},
 5+		"INVITE": {
 6+			AllowHome: true,
 7+			MinArgs:   1,
 8+			MaxArgs:   2,
 9+			Usage:     "<name> [channel]",
10+			Desc:      "invite someone to a channel",
11+			Handle:    commandDoInvite,
12+		},
13 	}
14 }
15 
16@@ -383,6 +391,18 @@ func commandDoTopic(app *App, args []string) (err error) {
17 	return
18 }
19 
20+func commandDoInvite(app *App, args []string) (err error) {
21+	nick := args[0]
22+	channel := app.win.CurrentBuffer()
23+	if len(args) == 2 {
24+		channel = args[1]
25+	} else if channel == Home {
26+		return fmt.Errorf("cannot invite to home")
27+	}
28+	app.s.Invite(nick, channel)
29+	return nil
30+}
31+
32 // implemented from https://golang.org/src/strings/strings.go?s=8055:8085#L310
33 func fieldsN(s string, n int) []string {
34 	s = strings.TrimSpace(s)
+5, -1
 1@@ -135,7 +135,8 @@ _name_ is matched case-insensitively.  It can be one of the following:
 2 	Reply to the last person who sent a private message.
 3 
 4 *ME* <content>
 5-	Send a message prefixed with your nick (a user action).
 6+	Send a message prefixed with your nick (a user action).  If sent from home,
 7+	reply to the last person who sent a private message.
 8 
 9 *QUOTE* <raw message>
10 	Send _raw message_ verbatim.
11@@ -149,6 +150,9 @@ _name_ is matched case-insensitively.  It can be one of the following:
12 *MODE* <nick/channel> <flags> [args]
13 	Change channel or user modes.
14 
15+*INVITE* <nick> [channel]
16+	Invite _nick_ to _channel_ (the current channel if not given).
17+
18 # SEE ALSO
19 
20 *senpai*(5)
+4, -0
 1@@ -449,6 +449,10 @@ func (s *Session) NewHistoryRequest(target string) *HistoryRequest {
 2 	}
 3 }
 4 
 5+func (s *Session) Invite(nick, channel string) {
 6+	s.out <- NewMessage("INVITE", nick, channel)
 7+}
 8+
 9 func (s *Session) HandleMessage(msg Message) (Event, error) {
10 	if s.registered {
11 		return s.handleRegistered(msg)