direct callback

and name shit
This commit is contained in:
blackbeard420 2020-01-05 23:19:14 -05:00
parent 81d577aa45
commit c208c2ff8f

18
irc.go
View File

@ -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 {