From c208c2ff8fdc88e2f6de290fafd34248563f5f75 Mon Sep 17 00:00:00 2001 From: blackbeard420 Date: Sun, 5 Jan 2020 23:19:14 -0500 Subject: [PATCH] direct callback and name shit --- irc.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/irc.go b/irc.go index 97ce554..a674dfe 100644 --- a/irc.go +++ b/irc.go @@ -13,6 +13,7 @@ import ( //Connection holds the callbacks for the client type Connection struct { Sock net.Conn + DirectCallback func(string, string) PrivmsgCallback func(string, string, string) JoinCallback func(string, string) QuitCallback func(string, string) @@ -81,7 +82,7 @@ func (c *Connection) DelayedSend(sock net.Conn, dur time.Duration, channel, msg //NewConnection creates and connects an Connection func NewConnection(server, nick, user, pass string, chans []string) *Connection { - irc := &Connection{channels: chans} + irc := &Connection{channels: chans, userList: map[string][]string{}} sock, err := net.Dial("tcp", server) if err != nil { @@ -125,6 +126,11 @@ func (c *Connection) parseMessage(line string) { 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) + } } if c.NumericCallback != nil { @@ -141,8 +147,14 @@ func (c *Connection) parseMessage(line string) { switch strings.ToLower(cmd) { case "privmsg": - if c.PrivmsgCallback != nil { - c.PrivmsgCallback(target, from, msg) + if target != c.curNick { + if c.PrivmsgCallback != nil { + c.PrivmsgCallback(target, from, msg) + } + } else { + if c.DirectCallback != nil { + c.DirectCallback(from, msg) + } } case "join": if c.JoinCallback != nil {