direct callback
and name shit
This commit is contained in:
parent
81d577aa45
commit
c208c2ff8f
18
irc.go
18
irc.go
@ -13,6 +13,7 @@ import (
|
|||||||
//Connection holds the callbacks for the client
|
//Connection holds the callbacks for the client
|
||||||
type Connection struct {
|
type Connection struct {
|
||||||
Sock net.Conn
|
Sock net.Conn
|
||||||
|
DirectCallback func(string, string)
|
||||||
PrivmsgCallback func(string, string, string)
|
PrivmsgCallback func(string, string, string)
|
||||||
JoinCallback func(string, string)
|
JoinCallback func(string, string)
|
||||||
QuitCallback 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
|
//NewConnection creates and connects an Connection
|
||||||
func NewConnection(server, nick, user, pass string, chans []string) *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)
|
sock, err := net.Dial("tcp", server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -125,6 +126,11 @@ func (c *Connection) parseMessage(line string) {
|
|||||||
idx += 2
|
idx += 2
|
||||||
s := strings.Split(args[idx:], ":")
|
s := strings.Split(args[idx:], ":")
|
||||||
log.Printf("names: %s: %s\n", s[0], s[1])
|
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 {
|
if c.NumericCallback != nil {
|
||||||
@ -141,8 +147,14 @@ func (c *Connection) parseMessage(line string) {
|
|||||||
|
|
||||||
switch strings.ToLower(cmd) {
|
switch strings.ToLower(cmd) {
|
||||||
case "privmsg":
|
case "privmsg":
|
||||||
if c.PrivmsgCallback != nil {
|
if target != c.curNick {
|
||||||
c.PrivmsgCallback(target, from, msg)
|
if c.PrivmsgCallback != nil {
|
||||||
|
c.PrivmsgCallback(target, from, msg)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if c.DirectCallback != nil {
|
||||||
|
c.DirectCallback(from, msg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case "join":
|
case "join":
|
||||||
if c.JoinCallback != nil {
|
if c.JoinCallback != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user