commit e06eb23

delthas  ·  2023-11-13 12:22:32 +0000 UTC
parent e1ec501
Add a LIST command

Not very user-friendly for now, but better than /QUOTE LIST.

Fixes: https://todo.sr.ht/~taiite/senpai/121
3 files changed,  +35, -0
+24, -0
 1@@ -133,6 +133,14 @@ func init() {
 2 			Desc:      "send raw protocol data",
 3 			Handle:    commandDoQuote,
 4 		},
 5+		"LIST": {
 6+			AllowHome: true,
 7+			MinArgs:   0,
 8+			MaxArgs:   1,
 9+			Usage:     "[pattern]",
10+			Desc:      "list public channels",
11+			Handle:    commandDoList,
12+		},
13 		"REPLY": {
14 			AllowHome: true,
15 			MinArgs:   1,
16@@ -543,6 +551,22 @@ func commandDoQuote(app *App, args []string) (err error) {
17 	return nil
18 }
19 
20+func commandDoList(app *App, args []string) (err error) {
21+	if app.cfg.Transient {
22+		return fmt.Errorf("usage of LIST is disabled")
23+	}
24+	s := app.CurrentSession()
25+	if s == nil {
26+		return errOffline
27+	}
28+	var pattern string
29+	if len(args) > 0 {
30+		pattern = args[0]
31+	}
32+	s.List(pattern)
33+	return nil
34+}
35+
36 func commandDoR(app *App, args []string) (err error) {
37 	s := app.sessions[app.lastQueryNet]
38 	if s == nil {
+3, -0
 1@@ -183,6 +183,9 @@ _name_ is matched case-insensitively.  It can be one of the following:
 2 *QUOTE* <raw message>
 3 	Send _raw message_ verbatim.
 4 
 5+*LIST* [pattern]
 6+	List public channels, optionally matching the specified pattern.
 7+
 8 *BUFFER* <name>
 9 	Switch to the buffer containing _name_.
10 
+8, -0
 1@@ -342,6 +342,14 @@ func (s *Session) SendRaw(raw string) {
 2 	s.out <- NewMessage(raw)
 3 }
 4 
 5+func (s *Session) List(pattern string) {
 6+	if pattern != "" {
 7+		s.out <- NewMessage("LIST", pattern)
 8+	} else {
 9+		s.out <- NewMessage("LIST")
10+	}
11+}
12+
13 func (s *Session) Join(channel, key string) {
14 	channelCf := s.Casemap(channel)
15 	s.pendingChannels[channelCf] = time.Now()