From ae3a7cdecb8a267dc26fa5947e511d5030fc8b0a Mon Sep 17 00:00:00 2001 From: blackbeard420 Date: Mon, 6 Jan 2020 19:45:31 -0500 Subject: [PATCH] updateNicks --- irc.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/irc.go b/irc.go index 490b51b..8c2508d 100644 --- a/irc.go +++ b/irc.go @@ -114,6 +114,18 @@ func GetNick(name string) string { return strings.Split(name, "!")[0] } +func (c *Connection) updateNicks(channel string, names []string) { + for _, i := range names { + for _, n := range c.userList[channel] { + if n == i { + continue + } + c.userList[channel] = append(c.userList[channel], i) + log.Printf("added nick: %s to channel %s\n", channel, i) + } + } +} + //TODO: simplify this to pass gocyclo func (c *Connection) parseMessage(line string) { if line[0] == ':' { @@ -138,12 +150,7 @@ func (c *Connection) parseMessage(line string) { idx := strings.Index(args, "=") idx += 2 s := strings.Split(args[idx:], ":") - log.Printf("names: %s: %s\n", s[0], s[1]) - names := strings.Split(s[1], " ") - ch := strings.ToLower(s[0]) - for _, i := range names { - c.userList[ch] = append(c.userList[ch], i) - } + c.updateNicks(strings.ToLower(s[0]), strings.Split(s[1], " ")) } if c.NumericCallback != nil {