예제 #1
0
파일: qubot.go 프로젝트: sevein/qubot
// handleEvents takes each type of event to its corresponding callback.
// A full list of events can be found in the source code: https://goo.gl/ESCO4K.
func (q *Qubot) handleEvent(event *slack.RTMEvent) error {
	switch e := event.Data.(type) {
	case *slack.ConnectingEvent:
		logger.Debug("qubot", "Connection attempt", "count", e.Attempt)
	case *slack.ConnectedEvent:
		logger.Info("qubot", "Connected to Slack!")
		return q.onConnectedEvent(e)
	case *slack.HelloEvent:
		logger.Info("qubot", "Slack sent greetings!")
	case *slack.LatencyReport:
		logger.Debug("qubot", "Latency report", "duration", e.Value)
	case *slack.MessageEvent:
		logger.Debug("qubot", "Message received")
		return q.onMessageEvent(e)
	case *slack.InvalidAuthEvent:
		panic("Unrecoverable error: InvalidAuthEvent")
	case *slack.RTMError:
	case *slack.AckErrorEvent:
	case *slack.ConnectionErrorEvent:
	case *slack.DisconnectedEvent:
	case *slack.MessageTooLongEvent:
	case *slack.OutgoingErrorEvent:
	default:
		logger.Debug("qubot", "Unknown event received", "type", event.Type)
	}
	return nil
}
예제 #2
0
파일: messenger.go 프로젝트: sevein/qubot
// startPoller creates a new goroutine for a channel.
// TODO: confirm delivery or retry instead (circuitbreaker?)
func (m *messenger) startPoller(q *queue.Queue) {
	logger.Debug("messenger", "Starting new poller goroutine")
	tb := ratelimit.NewBucketWithRate(msnRateLimit, 1)
	for {
		select {
		case <-m.ctx.Done():
			logger.Debug("messenger", "Closing poller")
			return
		default:
			res, err := q.Poll(1, msnPollWaitTime)
			if err != nil {
				if err != queue.ErrTimeout {
					logger.Warn("messenger", "startPoller", "error", err)
				}
				continue
			}
			msg := res[0].(*slack.OutgoingMessage)
			m.rtm.SendMessage(msg)
			tb.Wait(1) // and relax for a bit!
		}
	}
}
예제 #3
0
파일: taunt.go 프로젝트: sevein/qubot
func (h *tauntHandler) Handle(r qubot.Response, msg *qubot.Message) {
	logger.Debug("tauntHandler", "Received a message!")
}