Browse Source

list command

tags/v0.1.0
Jeremy Latt 10 years ago
parent
commit
f0fc3b492c
4 changed files with 59 additions and 0 deletions
  1. 18
    0
      irc/commands.go
  2. 1
    0
      irc/constants.go
  3. 9
    0
      irc/reply.go
  4. 31
    0
      irc/server.go

+ 18
- 0
irc/commands.go View File

@@ -24,6 +24,7 @@ var (
24 24
 		ISON:    NewIsOnCommand,
25 25
 		JOIN:    NewJoinCommand,
26 26
 		KICK:    NewKickCommand,
27
+		LIST:    NewListCommand,
27 28
 		MODE:    NewModeCommand,
28 29
 		MOTD:    NewMOTDCommand,
29 30
 		NICK:    NewNickCommand,
@@ -778,3 +779,20 @@ func NewKickCommand(args []string) (editableCommand, error) {
778 779
 	}
779 780
 	return cmd, nil
780 781
 }
782
+
783
+type ListCommand struct {
784
+	BaseCommand
785
+	channels []string
786
+	target   string
787
+}
788
+
789
+func NewListCommand(args []string) (editableCommand, error) {
790
+	cmd := &ListCommand{}
791
+	if len(args) > 0 {
792
+		cmd.channels = strings.Split(args[0], ",")
793
+	}
794
+	if len(args) > 1 {
795
+		cmd.target = args[1]
796
+	}
797
+	return cmd, nil
798
+}

+ 1
- 0
irc/constants.go View File

@@ -31,6 +31,7 @@ const (
31 31
 	ISON    StringCode = "ISON"
32 32
 	JOIN    StringCode = "JOIN"
33 33
 	KICK    StringCode = "KICK"
34
+	LIST    StringCode = "LIST"
34 35
 	MODE    StringCode = "MODE"
35 36
 	MOTD    StringCode = "MOTD"
36 37
 	NICK    StringCode = "NICK"

+ 9
- 0
irc/reply.go View File

@@ -321,6 +321,15 @@ func RplMOTDEnd(server *Server) Reply {
321 321
 		":End of MOTD command")
322 322
 }
323 323
 
324
+func RplList(channel *Channel) Reply {
325
+	return NewNumericReply(channel.server, RPL_LIST, "%s %d :%s",
326
+		channel, len(channel.members), channel.topic)
327
+}
328
+
329
+func RplListEnd(server *Server) Reply {
330
+	return NewNumericReply(server, RPL_LISTEND, ":End of LIST")
331
+}
332
+
324 333
 //
325 334
 // errors (also numeric)
326 335
 //

+ 31
- 0
irc/server.go View File

@@ -561,3 +561,34 @@ func (msg *KickCommand) HandleServer(server *Server) {
561 561
 		channel.Kick(client, target, msg.Comment())
562 562
 	}
563 563
 }
564
+
565
+func (msg *ListCommand) HandleServer(server *Server) {
566
+	client := msg.Client()
567
+
568
+	// TODO target server
569
+	if msg.target != "" {
570
+		client.Reply(ErrNoSuchServer(server, msg.target))
571
+		return
572
+	}
573
+
574
+	if len(msg.channels) == 0 {
575
+		for _, channel := range server.channels {
576
+			if channel.flags[Secret] || channel.flags[Private] {
577
+				continue
578
+			}
579
+			client.Reply(RplList(channel))
580
+		}
581
+	} else {
582
+		for _, chname := range msg.channels {
583
+			channel := server.channels[chname]
584
+			if channel == nil ||
585
+				channel.flags[Secret] ||
586
+				channel.flags[Private] {
587
+				client.Reply(ErrNoSuchChannel(server, chname))
588
+				continue
589
+			}
590
+			client.Reply(RplList(channel))
591
+		}
592
+	}
593
+	client.Reply(RplListEnd(server))
594
+}

Loading…
Cancel
Save