mirror of https://github.com/velour/catbase.git
Merge pull request #78 from velour/change_serve
bot: change serve() to return an error
This commit is contained in:
commit
a76575f976
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
5
main.go
5
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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":
|
||||
|
|
Loading…
Reference in New Issue