func (gw *SlackGateway) Open(c chan *message.Message) error { rtmStart, err := gw.client.RTMStart() if err != nil { return err } gw.broker = slacker.NewRTMBroker(rtmStart) gw.broker.Connect() go func() { for { event := <-gw.broker.Events() if event.Type == SlackEventTypeMessage { msg, err := event.Message() if err != nil { gw.logger.Log("err", err, "event", event) panic(err) } m := message.FromGateway( gw.id, msg.Channel, msg.Text, ) c <- m } } }() return nil }
func (gw *IRCGateway) Open(c chan *message.Message) error { gw.msgChannel = c if err := gw.ircConn.Connect(); err != nil { gw.logger.Log("err", err, "conn", false) return err } gw.ircConn.HandleFunc("connected", func(conn *irc.Conn, line *irc.Line) { for _, c := range gw.cfg.Channels { conn.Join(c) gw.logger.Log("join", true, "channel", c) } }) gw.ircConn.HandleFunc(irc.PRIVMSG, func(conn *irc.Conn, line *irc.Line) { text := line.Text() channel := line.Target() m := message.FromGateway( gw.id, channel, text, ) c <- m }) gw.logger.Log("connecting", "irc") return nil }