diff options
author | Wim <wim@42.be> | 2021-10-23 23:13:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-23 23:13:07 +0200 |
commit | 8967f02fc9762657f755c118ce7a54acb750a53f (patch) | |
tree | 6d066bee8d6cafa32a4e5e7ba620fdbed7f629c0 /vendor | |
parent | 831ff6d0a9bb77a283cc823a953de430ad6b0f8d (diff) | |
download | matterbridge-msglm-8967f02fc9762657f755c118ce7a54acb750a53f.tar.gz matterbridge-msglm-8967f02fc9762657f755c118ce7a54acb750a53f.tar.bz2 matterbridge-msglm-8967f02fc9762657f755c118ce7a54acb750a53f.zip |
Update gozulipbot dependency (#1618)
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/github.com/matterbridge/gozulipbot/bot.go | 36 | ||||
-rw-r--r-- | vendor/github.com/matterbridge/gozulipbot/queue.go | 2 | ||||
-rw-r--r-- | vendor/modules.txt | 2 |
3 files changed, 31 insertions, 9 deletions
diff --git a/vendor/github.com/matterbridge/gozulipbot/bot.go b/vendor/github.com/matterbridge/gozulipbot/bot.go index f5644a29..ebcf015a 100644 --- a/vendor/github.com/matterbridge/gozulipbot/bot.go +++ b/vendor/github.com/matterbridge/gozulipbot/bot.go @@ -10,14 +10,15 @@ import ( ) type Bot struct { - APIKey string - APIURL string - Email string - Queues []*Queue - Streams []string - Client Doer - Backoff time.Duration - Retries int64 + APIKey string + APIURL string + Email string + Queues []*Queue + Streams []string + Client Doer + Backoff time.Duration + Retries int64 + UserAgent string } type Doer interface { @@ -117,6 +118,11 @@ func (b *Bot) Subscribe(streams []string) (*http.Response, error) { body := "subscriptions=" + string(bodyBts) req, err := b.constructRequest("POST", "users/me/subscriptions", body) + if b.UserAgent != "" { + req.Header.Set("User-Agent", b.UserAgent) + } else { + req.Header.Set("User-Agent", fmt.Sprintf("gozulipbot/%s", Release)) + } if err != nil { return nil, err } @@ -174,6 +180,20 @@ func (b *Bot) RegisterEvents(ets []EventType, n Narrow) (*Queue, error) { return nil, err } defer resp.Body.Close() + if resp.StatusCode != 200 { + // Try to parse the error out of the body + body, err := ioutil.ReadAll(resp.Body) + if err == nil { + var jsonErr map[string]string + err = json.Unmarshal(body, &jsonErr) + if err == nil { + if msg, ok := jsonErr["msg"]; ok { + return nil, fmt.Errorf("Failed to register: %s", msg) + } + } + } + return nil, fmt.Errorf("Got non-200 response code when registering: %d", resp.StatusCode) + } body, err := ioutil.ReadAll(resp.Body) if err != nil { diff --git a/vendor/github.com/matterbridge/gozulipbot/queue.go b/vendor/github.com/matterbridge/gozulipbot/queue.go index 77aef7fc..b90205c1 100644 --- a/vendor/github.com/matterbridge/gozulipbot/queue.go +++ b/vendor/github.com/matterbridge/gozulipbot/queue.go @@ -151,6 +151,8 @@ func (q *Queue) GetEvents() ([]EventMessage, error) { switch { case resp.StatusCode == 429: return nil, BackoffError + case resp.StatusCode == 401: + return nil, UnauthorizedError case resp.StatusCode == 403: return nil, UnauthorizedError case resp.StatusCode >= 400: diff --git a/vendor/modules.txt b/vendor/modules.txt index 1c1707a0..4cf2e8d0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -183,7 +183,7 @@ github.com/matterbridge/discordgo # github.com/matterbridge/go-xmpp v0.0.0-20210731150933-5702291c239f ## explicit github.com/matterbridge/go-xmpp -# github.com/matterbridge/gozulipbot v0.0.0-20200820220548-be5824faa913 +# github.com/matterbridge/gozulipbot v0.0.0-20211023205727-a19d6c1f3b75 ## explicit github.com/matterbridge/gozulipbot # github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba |