From 47602972870eedfa3ea86ace1c34bc48e7e05402 Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Thu, 29 Aug 2013 21:23:52 +0100 Subject: [PATCH] /PART now accepts a reason from the client --- client.go | 8 ++++---- server.go | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index c5b2907..e341825 100644 --- a/client.go +++ b/client.go @@ -103,7 +103,7 @@ func (c *Client) joinChannel(channelName string) { c.reply(rplNames, channelName, strings.Join(nicks, " ")) } -func (c *Client) partChannel(channelName string) { +func (c *Client) partChannel(channelName, reason string) { channelKey := strings.ToLower(channelName) channel, exists := c.server.channelMap[channelKey] if exists == false { @@ -117,7 +117,7 @@ func (c *Client) partChannel(channelName string) { //Notify clients of the part for _, client := range channel.clientMap { - client.reply(rplPart, c.nick, channelName) + client.reply(rplPart, c.nick, channelName, reason) } delete(channel.clientMap, strings.ToLower(c.nick)) @@ -144,7 +144,7 @@ func (c *Client) reply(code replyCode, args ...string) { case rplJoin: c.outputChan <- fmt.Sprintf(":%s JOIN %s", args[0], args[1]) case rplPart: - c.outputChan <- fmt.Sprintf(":%s PART %s", args[0], args[1]) + c.outputChan <- fmt.Sprintf(":%s PART %s %s", args[0], args[1], args[2]) case rplTopic: c.outputChan <- fmt.Sprintf(":%s 332 %s %s :%s", c.server.name, c.nick, args[0], args[1]) case rplNoTopic: @@ -207,7 +207,7 @@ func (c *Client) clientThread() { defer func() { //Part from all channels for channelName := range c.channelMap { - c.partChannel(channelName) + c.partChannel(channelName, "Disconnecting") } delete(c.server.clientMap, strings.ToLower(c.nick)) diff --git a/server.go b/server.go index f3f54b7..d3fab30 100644 --- a/server.go +++ b/server.go @@ -112,7 +112,7 @@ func (s *Server) handleEvent(e Event) { if args[0] == "0" { //Quit all channels for channel := range e.client.channelMap { - e.client.partChannel(channel) + e.client.partChannel(channel, "Disconnecting") } return } @@ -136,11 +136,13 @@ func (s *Server) handleEvent(e Event) { return } + reason := strings.Join(args[1:], " ") + channels := strings.Split(args[0], ",") for _, channel := range channels { //Part the channel if it's valid if channelRegexp.Match([]byte(channel)) { - e.client.partChannel(channel) + e.client.partChannel(channel, reason) } }