diff --git a/bot/interfaces.go b/bot/interfaces.go index e80fdb1..12aa95d 100644 --- a/bot/interfaces.go +++ b/bot/interfaces.go @@ -34,7 +34,7 @@ type Connector interface { SendAction(channel, message string) React(string, string, msg.Message) GetEmojiList() map[string]string - Serve() + Serve() error Who(string) []string } diff --git a/irc/irc.go b/irc/irc.go index 3df0015..5ff2b07 100644 --- a/irc/irc.go +++ b/irc/irc.go @@ -3,6 +3,7 @@ package irc import ( + "fmt" "io" "log" "os" @@ -107,9 +108,9 @@ func (i *Irc) GetEmojiList() map[string]string { return make(map[string]string) } -func (i *Irc) Serve() { +func (i *Irc) Serve() error { if i.eventReceived == nil || i.messageReceived == nil { - log.Fatal("Missing an event handler") + return fmt.Errorf("Missing an event handler") } var err error @@ -121,7 +122,7 @@ func (i *Irc) Serve() { true, ) if err != nil { - log.Fatal(err) + return fmt.Errorf("%s", err) } for _, c := range i.config.Channels { @@ -131,6 +132,7 @@ func (i *Irc) Serve() { i.quit = make(chan bool) go i.handleConnection() <-i.quit + return nil } func (i *Irc) handleConnection() { diff --git a/main.go b/main.go index 5805713..8c8be47 100644 --- a/main.go +++ b/main.go @@ -68,5 +68,8 @@ func main() { // catches anything left, will always return true b.AddHandler("factoid", fact.New(b)) - client.Serve() + for { + err := client.Serve() + log.Println(err) + } } diff --git a/slack/slack.go b/slack/slack.go index d6f8ace..9c21b17 100644 --- a/slack/slack.go +++ b/slack/slack.go @@ -261,7 +261,7 @@ func slackTStoTime(t string) time.Time { return time.Unix(sec, nsec) } -func (s *Slack) Serve() { +func (s *Slack) Serve() error { s.connect() s.populateEmojiList() for { @@ -269,8 +269,7 @@ func (s *Slack) Serve() { if err != nil && err == io.EOF { log.Fatalf("Slack API EOF") } else if err != nil { - log.Printf("Slack API error: %s", err) - continue + return fmt.Errorf("Slack API error: %s", err) } switch msg.Type { case "message":