summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--vendor/github.com/matterbridge/gozulipbot/bot.go4
-rw-r--r--vendor/github.com/matterbridge/gozulipbot/flag.go53
-rw-r--r--vendor/github.com/matterbridge/gozulipbot/message.go12
-rw-r--r--vendor/github.com/matterbridge/gozulipbot/queue.go18
-rw-r--r--vendor/modules.txt2
7 files changed, 70 insertions, 25 deletions
diff --git a/go.mod b/go.mod
index b1f527f3..b3c277c6 100644
--- a/go.mod
+++ b/go.mod
@@ -25,7 +25,7 @@ require (
github.com/matterbridge/emoji v2.1.1-0.20191117213217-af507f6b02db+incompatible
github.com/matterbridge/go-xmpp v0.0.0-20200418225040-c8a3a57b4050
github.com/matterbridge/gomatrix v0.0.0-20200209224845-c2104d7936a6
- github.com/matterbridge/gozulipbot v0.0.0-20190212232658-7aa251978a18
+ github.com/matterbridge/gozulipbot v0.0.0-20200820220548-be5824faa913
github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba
github.com/mattermost/mattermost-server/v5 v5.25.2
github.com/mattn/godown v0.0.0-20200217152941-afc959f6a561
diff --git a/go.sum b/go.sum
index 1d8ea962..de1929b5 100644
--- a/go.sum
+++ b/go.sum
@@ -354,8 +354,8 @@ github.com/matterbridge/go-xmpp v0.0.0-20200418225040-c8a3a57b4050 h1:kWkP1lXpkv
github.com/matterbridge/go-xmpp v0.0.0-20200418225040-c8a3a57b4050/go.mod h1:ECDRehsR9TYTKCAsRS8/wLeOk6UUqDydw47ln7wG41Q=
github.com/matterbridge/gomatrix v0.0.0-20200209224845-c2104d7936a6 h1:Kl65VJv38HjYFnnwH+MP6Z8hcJT5UHuSpHVU5vW1HH0=
github.com/matterbridge/gomatrix v0.0.0-20200209224845-c2104d7936a6/go.mod h1:+jWeaaUtXQbBRdKYWfjW6JDDYiI2XXE+3NnTjW5kg8g=
-github.com/matterbridge/gozulipbot v0.0.0-20190212232658-7aa251978a18 h1:fLhwXtWGtfTgZVxHG1lcKjv+re7dRwyyuYFNu69xdho=
-github.com/matterbridge/gozulipbot v0.0.0-20190212232658-7aa251978a18/go.mod h1:yAjnZ34DuDyPHMPHHjOsTk/FefW4JJjoMMCGt/8uuQA=
+github.com/matterbridge/gozulipbot v0.0.0-20200820220548-be5824faa913 h1:5UGr9fLsvAvhjP6i5XJmd0ZIwYVR2gZCzU1lJZ7wfLY=
+github.com/matterbridge/gozulipbot v0.0.0-20200820220548-be5824faa913/go.mod h1:yAjnZ34DuDyPHMPHHjOsTk/FefW4JJjoMMCGt/8uuQA=
github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba h1:XleOY4IjAEIcxAh+IFwT5JT5Ze3RHiYz6m+4ZfZ0rc0=
github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba/go.mod h1:iXGEotOvwI1R1SjLxRc+BF5rUORTMtE0iMZBT2lxqAU=
github.com/mattermost/go-i18n v1.11.0 h1:1hLKqn/ZvhZ80OekjVPGYcCrBfMz+YxNNgqS+beL7zE=
diff --git a/vendor/github.com/matterbridge/gozulipbot/bot.go b/vendor/github.com/matterbridge/gozulipbot/bot.go
index 24bc8768..f5644a29 100644
--- a/vendor/github.com/matterbridge/gozulipbot/bot.go
+++ b/vendor/github.com/matterbridge/gozulipbot/bot.go
@@ -186,10 +186,6 @@ func (b *Bot) RegisterEvents(ets []EventType, n Narrow) (*Queue, error) {
return nil, err
}
- if q.LastEventID < q.MaxMessageID {
- q.LastEventID = q.MaxMessageID
- }
-
b.Queues = append(b.Queues, q)
return q, nil
diff --git a/vendor/github.com/matterbridge/gozulipbot/flag.go b/vendor/github.com/matterbridge/gozulipbot/flag.go
index 6305aac1..0a263388 100644
--- a/vendor/github.com/matterbridge/gozulipbot/flag.go
+++ b/vendor/github.com/matterbridge/gozulipbot/flag.go
@@ -3,30 +3,61 @@ package gozulipbot
import (
"flag"
"fmt"
+ "os"
"time"
)
func (b *Bot) GetConfigFromFlags() error {
var (
- apiKey = flag.String("apikey", "", "bot api key")
- apiURL = flag.String("apiurl", "", "url of zulip server")
- email = flag.String("email", "", "bot email address")
- backoff = flag.Duration("backoff", 1*time.Second, "backoff base duration")
+ apiKey = flag.String("apikey", "ZULIP_APIKEY", "bot api key or env var")
+ apiURL = flag.String("apiurl", "ZULIP_APIURL", "url of zulip server or env var")
+ backoff = flag.Duration("backoff", 1*time.Second, "backoff base duration or env var")
+ email = flag.String("email", "ZULIP_EMAIL", "bot email address or env var")
+ env = flag.Bool("env", false, "get string values from environment variables")
)
flag.Parse()
- if *apiKey == "" {
+ b.APIKey = *apiKey
+ b.APIURL = *apiURL
+ b.Email = *email
+ b.Backoff = *backoff
+ if *env {
+ b.GetConfigFromEnvironment()
+ }
+ return b.checkConfig()
+}
+
+func (b *Bot) GetConfigFromEnvironment() error {
+ if apiKey, exists := os.LookupEnv(b.APIKey); !exists {
+ return fmt.Errorf("--env was set but env var %s did not exist", b.APIKey)
+ } else {
+ b.APIKey = apiKey
+ }
+ if apiURL, exists := os.LookupEnv(b.APIURL); !exists {
+ return fmt.Errorf("--env was set but env var %s did not exist", b.APIURL)
+ } else {
+ b.APIURL = apiURL
+ }
+ if email, exists := os.LookupEnv(b.Email); !exists {
+ return fmt.Errorf("--env was set but env var %s did not exist", b.Email)
+ } else {
+ b.Email = email
+ }
+ return nil
+}
+
+func (b *Bot) checkConfig() error {
+ if b.APIKey == "" {
return fmt.Errorf("--apikey is required")
}
- if *apiURL == "" {
+ if b.APIURL == "" {
return fmt.Errorf("--apiurl is required")
}
- if *email == "" {
+ if b.Email == "" {
return fmt.Errorf("--email is required")
}
- b.APIKey = *apiKey
- b.APIURL = *apiURL
- b.Email = *email
- b.Backoff = *backoff
+ if b.Backoff <= 0 {
+ return fmt.Errorf("--backoff must be greater than zero")
+ }
return nil
}
diff --git a/vendor/github.com/matterbridge/gozulipbot/message.go b/vendor/github.com/matterbridge/gozulipbot/message.go
index df963f43..16d88312 100644
--- a/vendor/github.com/matterbridge/gozulipbot/message.go
+++ b/vendor/github.com/matterbridge/gozulipbot/message.go
@@ -194,8 +194,10 @@ func (b *Bot) UpdateMessage(id string, content string) (*http.Response, error) {
// React adds an emoji reaction to an EventMessage.
func (b *Bot) React(e EventMessage, emoji string) (*http.Response, error) {
- url := fmt.Sprintf("messages/%d/emoji_reactions/%s", e.ID, emoji)
- req, err := b.constructRequest("PUT", url, "")
+ requestURL := fmt.Sprintf("messages/%d/reactions", e.ID)
+ values := url.Values{}
+ values.Set("emoji_name", emoji)
+ req, err := b.constructRequest("POST", requestURL, values.Encode())
if err != nil {
return nil, err
}
@@ -204,8 +206,10 @@ func (b *Bot) React(e EventMessage, emoji string) (*http.Response, error) {
// Unreact removes an emoji reaction from an EventMessage.
func (b *Bot) Unreact(e EventMessage, emoji string) (*http.Response, error) {
- url := fmt.Sprintf("messages/%d/emoji_reactions/%s", e.ID, emoji)
- req, err := b.constructRequest("DELETE", url, "")
+ requestURL := fmt.Sprintf("messages/%d/reactions", e.ID)
+ values := url.Values{}
+ values.Set("emoji_name", emoji)
+ req, err := b.constructRequest("DELETE", requestURL, values.Encode())
if err != nil {
return nil, err
}
diff --git a/vendor/github.com/matterbridge/gozulipbot/queue.go b/vendor/github.com/matterbridge/gozulipbot/queue.go
index d6e910ee..77aef7fc 100644
--- a/vendor/github.com/matterbridge/gozulipbot/queue.go
+++ b/vendor/github.com/matterbridge/gozulipbot/queue.go
@@ -59,6 +59,7 @@ func (q *Queue) EventsChan() (chan EventMessage, func()) {
case err == BackoffError:
time.Sleep(time.Until(backoffTime))
atomic.AddInt64(&q.Bot.Retries, 1)
+ continue
case err == UnauthorizedError:
// TODO? have error channel when ending the continuously running process?
return
@@ -81,7 +82,7 @@ func (q *Queue) EventsChan() (chan EventMessage, func()) {
return out, endFunc
}
-// EventsCallback will repeatedly call provided callback function with
+// EventsCallback will repeatedly call the provided callback function with
// the output of continual queue.GetEvents calls.
// It returns a function which can be called to end the calls.
//
@@ -107,6 +108,7 @@ func (q *Queue) EventsCallback(fn func(EventMessage, error)) func() {
case err == BackoffError:
time.Sleep(time.Until(backoffTime))
atomic.AddInt64(&q.Bot.Retries, 1)
+ continue
case err == UnauthorizedError:
// TODO? have error channel when ending the continuously running process?
return
@@ -221,9 +223,19 @@ func (q *Queue) ParseEventMessages(rawEventResponse []byte) ([]EventMessage, err
}
messages := []EventMessage{}
+ newLastEventID := 0
for _, event := range events {
- // if the event is a heartbeat, return a special error
+ // Update the lastEventID
+ var id int
+ json.Unmarshal(event["id"], &id)
+ if id > newLastEventID {
+ newLastEventID = id
+ }
+
+ // If the event is a heartbeat, there won't be any more events.
+ // So update the last event id and return a special error.
if string(event["type"]) == `"heartbeat"` {
+ q.LastEventID = newLastEventID
return nil, HeartbeatError
}
var msg EventMessage
@@ -236,5 +248,7 @@ func (q *Queue) ParseEventMessages(rawEventResponse []byte) ([]EventMessage, err
messages = append(messages, msg)
}
+ q.LastEventID = newLastEventID
+
return messages, nil
}
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 2308e7af..da0774ff 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -113,7 +113,7 @@ github.com/matterbridge/emoji
github.com/matterbridge/go-xmpp
# github.com/matterbridge/gomatrix v0.0.0-20200209224845-c2104d7936a6
github.com/matterbridge/gomatrix
-# github.com/matterbridge/gozulipbot v0.0.0-20190212232658-7aa251978a18
+# github.com/matterbridge/gozulipbot v0.0.0-20200820220548-be5824faa913
github.com/matterbridge/gozulipbot
# github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba
github.com/matterbridge/logrus-prefixed-formatter