commit e24f9a5

delthas  ·  2022-07-06 20:17:13 +0000 UTC
parent 6f0d19e
Implement /whois
2 files changed,  +31, -0
+27, -0
 1@@ -136,6 +136,14 @@ func init() {
 2 			Desc:      "switch to the buffer containing a substring",
 3 			Handle:    commandDoBuffer,
 4 		},
 5+		"WHOIS": {
 6+			AllowHome: false,
 7+			MinArgs:   0,
 8+			MaxArgs:   1,
 9+			Usage:     "<nick>",
10+			Desc:      "get information about someone",
11+			Handle:    commandDoWhois,
12+		},
13 		"INVITE": {
14 			AllowHome: true,
15 			MinArgs:   1,
16@@ -514,6 +522,25 @@ func commandDoTopic(app *App, args []string) (err error) {
17 	return nil
18 }
19 
20+func commandDoWhois(app *App, args []string) (err error) {
21+	netID, channel := app.win.CurrentBuffer()
22+	s := app.sessions[netID]
23+	if s == nil {
24+		return errOffline
25+	}
26+	var nick string
27+	if len(args) == 0 {
28+		if s.IsChannel(channel) {
29+			return fmt.Errorf("either send this command from a DM, or specify the user")
30+		}
31+		nick = channel
32+	} else {
33+		nick = args[0]
34+	}
35+	s.Whois(nick)
36+	return nil
37+}
38+
39 func commandDoInvite(app *App, args []string) (err error) {
40 	nick := args[0]
41 	netID, channel := app.win.CurrentBuffer()
+4, -0
 1@@ -564,6 +564,10 @@ func (s *Session) NewHistoryRequest(target string) *HistoryRequest {
 2 	}
 3 }
 4 
 5+func (s *Session) Whois(nick string) {
 6+	s.out <- NewMessage("WHOIS", nick)
 7+}
 8+
 9 func (s *Session) Invite(nick, channel string) {
10 	s.out <- NewMessage("INVITE", nick, channel)
11 }