Skip to content

Commit

Permalink
IRC: reconnect automatically.
Browse files Browse the repository at this point in the history
We can't use AutoReconnect because of thoj/go-ircevent#112.

Prevents foubot dying indefinitely as shown in commit c3038.
  • Loading branch information
cpatulea committed Sep 21, 2023
1 parent 167babd commit c5e90db
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func main() {
irccon.SASLLogin = botNick
irccon.SASLPassword = botPswd
}
irccon.Server = servertls
irccon.TLSConfig = &tls.Config{InsecureSkipVerify: true}

leds, err := ledsign.NewLEDSign()
Expand All @@ -146,15 +147,18 @@ func main() {
irccon.AddCallback("NICK", func(e *irc.Event) { handleNick(e, irccon) })
irccon.AddCallback("PART", func(e *irc.Event) { handlePart(e, irccon) })

err = irccon.Connect(servertls)
if err != nil {
fmt.Printf("Connect error: %s\n", err)
return
}

// TODO: fix topic setting
button := ledsign.NewSwitchStatus("", irccon)
defer button.CloseSwitchStatus()

irccon.Loop()
for {
err = irccon.Reconnect()
if err != nil {
fmt.Printf("Connect error: %s\n", err)
time.Sleep(60 * time.Second)
continue
}

irccon.Loop()
}
}

0 comments on commit c5e90db

Please sign in to comment.