2012-11-05 22:46:47 +00:00
|
|
|
// Copyright 2009 Thomas Jager <mail@jager.no> All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package irc
|
|
|
|
|
|
|
|
import (
|
2012-11-05 23:38:20 +00:00
|
|
|
"crypto/tls"
|
2012-11-05 22:46:47 +00:00
|
|
|
"log"
|
|
|
|
"net"
|
2014-05-02 22:20:51 +00:00
|
|
|
"sync"
|
2012-02-25 08:52:19 +00:00
|
|
|
"time"
|
2012-11-05 22:46:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Connection struct {
|
2014-05-02 22:20:51 +00:00
|
|
|
sync.WaitGroup
|
2013-09-26 03:37:11 +00:00
|
|
|
Debug bool
|
2012-11-05 23:38:20 +00:00
|
|
|
Error chan error
|
|
|
|
Password string
|
2012-11-07 20:55:33 +00:00
|
|
|
UseTLS bool
|
|
|
|
TLSConfig *tls.Config
|
2014-02-09 10:20:58 +00:00
|
|
|
Version string
|
|
|
|
Timeout time.Duration
|
|
|
|
PingFreq time.Duration
|
|
|
|
KeepAlive time.Duration
|
2015-07-31 06:29:20 +00:00
|
|
|
Server string
|
2012-03-22 03:57:35 +00:00
|
|
|
|
2014-08-14 01:35:37 +00:00
|
|
|
socket net.Conn
|
|
|
|
pwrite chan string
|
2015-11-14 13:51:15 +00:00
|
|
|
end chan struct{}
|
2012-03-22 04:08:21 +00:00
|
|
|
|
2012-11-05 23:38:20 +00:00
|
|
|
nick string //The nickname we want.
|
2012-03-22 03:57:35 +00:00
|
|
|
nickcurrent string //The nickname we currently have.
|
2012-11-05 23:38:20 +00:00
|
|
|
user string
|
|
|
|
registered bool
|
2014-02-11 23:35:13 +00:00
|
|
|
events map[string]map[string]func(*Event)
|
2012-11-05 22:46:47 +00:00
|
|
|
|
2015-10-28 12:58:41 +00:00
|
|
|
QuitMessage string
|
2013-04-01 13:02:37 +00:00
|
|
|
lastMessage time.Time
|
2012-11-05 22:46:47 +00:00
|
|
|
|
|
|
|
VerboseCallbackHandler bool
|
2014-02-09 13:42:14 +00:00
|
|
|
Log *log.Logger
|
2012-11-05 22:46:47 +00:00
|
|
|
|
2013-04-01 13:02:37 +00:00
|
|
|
stopped bool
|
2015-11-14 13:10:39 +00:00
|
|
|
quit bool
|
2012-11-05 22:46:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:40:25 +00:00
|
|
|
// A struct to represent an event.
|
2012-11-05 22:46:47 +00:00
|
|
|
type Event struct {
|
2014-11-03 15:21:48 +00:00
|
|
|
Code string
|
|
|
|
Raw string
|
|
|
|
Nick string //<nick>
|
|
|
|
Host string //<nick>!<usr>@<host>
|
|
|
|
Source string //<host>
|
|
|
|
User string //<usr>
|
|
|
|
Arguments []string
|
|
|
|
Connection *Connection
|
2012-11-05 22:46:47 +00:00
|
|
|
}
|
2014-02-11 17:22:13 +00:00
|
|
|
|
2014-05-02 22:20:51 +00:00
|
|
|
// Retrieve the last message from Event arguments.
|
|
|
|
// This function leaves the arguments untouched and
|
2014-02-14 16:10:06 +00:00
|
|
|
// returns an empty string if there are none.
|
2014-02-11 17:22:13 +00:00
|
|
|
func (e *Event) Message() string {
|
|
|
|
if len(e.Arguments) == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return e.Arguments[len(e.Arguments)-1]
|
|
|
|
}
|