aboutsummaryrefslogtreecommitdiff
path: root/connector/irc
diff options
context:
space:
mode:
Diffstat (limited to 'connector/irc')
-rw-r--r--connector/irc/irc.go43
1 files changed, 28 insertions, 15 deletions
diff --git a/connector/irc/irc.go b/connector/irc/irc.go
index b9c58ad..671d19a 100644
--- a/connector/irc/irc.go
+++ b/connector/irc/irc.go
@@ -12,11 +12,11 @@ import (
)
// User id format: nickname@server
+
// Room id format: #room_name@server
type IRC struct {
handler Handler
- config Configuration
connected bool
timeout int
@@ -40,17 +40,26 @@ func (irc *IRC) Configure(c Configuration) error {
irc.Close()
}
- irc.config = c
+ var err error
- irc.nick = c.GetString("nick")
- irc.server = c.GetString("server")
+ irc.nick, err = c.GetString("nick")
+ if err != nil {
+ return err
+ }
- port, err := c.GetInt("port")
+ irc.server, err = c.GetString("server")
if err != nil {
return err
}
- if port == 0 {
- port = 6667
+
+ port, err := c.GetInt("port", 6666)
+ if err != nil {
+ return err
+ }
+
+ ssl, err := c.GetBool("ssl", true)
+ if err != nil {
+ return err
}
client := girc.New(girc.Config{
@@ -59,7 +68,7 @@ func (irc *IRC) Configure(c Configuration) error {
Nick: irc.nick,
User: irc.nick,
Out: os.Stderr,
- SSL: true,
+ SSL: ssl,
})
client.Handlers.Add(girc.CONNECTED, irc.ircConnected)
@@ -83,7 +92,7 @@ func (irc *IRC) Configure(c Configuration) error {
return nil
}
}
- return fmt.Errorf("Failed to conncect after 42s attempting")
+ return fmt.Errorf("Failed to connect after 42s attempting")
}
func (irc *IRC) User() UserID {
@@ -184,9 +193,9 @@ func (irc *IRC) Send(event *Event) error {
}
if event.Type == EVENT_MESSAGE {
- irc.conn.Cmd.Message(dest, event.Message)
+ irc.conn.Cmd.Message(dest, event.Text)
} else if event.Type == EVENT_ACTION {
- irc.conn.Cmd.Action(dest, event.Message)
+ irc.conn.Cmd.Action(dest, event.Text)
} else {
return fmt.Errorf("Invalid event type")
}
@@ -194,8 +203,9 @@ func (irc *IRC) Send(event *Event) error {
}
func (irc *IRC) Close() {
- irc.conn.Close()
+ conn := irc.conn
irc.conn = nil
+ conn.Close()
}
func (irc *IRC) connectLoop(c *girc.Client) {
@@ -206,10 +216,13 @@ func (irc *IRC) connectLoop(c *girc.Client) {
}
if err := c.Connect(); err != nil {
irc.connected = false
- fmt.Printf("IRC failed to connect / disconnected: %s", err)
- fmt.Printf("Retrying in %ds", irc.timeout)
+ fmt.Printf("IRC failed to connect / disconnected: %s\n", err)
+ fmt.Printf("Retrying in %ds\n", irc.timeout)
time.Sleep(time.Duration(irc.timeout) * time.Second)
irc.timeout *= 2
+ if irc.timeout > 600 {
+ irc.timeout = 600
+ }
} else {
return
}
@@ -226,7 +239,7 @@ func (irc *IRC) ircPrivmsg(c *girc.Client, e girc.Event) {
ev := &Event{
Type: EVENT_MESSAGE,
Author: UserID(e.Source.Name + "@" + irc.server),
- Message: e.Last(),
+ Text: e.Last(),
}
if e.IsFromChannel() {
ev.Room = RoomID(e.Params[0] + "@" + irc.server)