summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/SevereCloud/vksdk/v2/longpoll-bot/longpoll.go
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2022-01-28 23:48:40 +0100
committerGitHub <noreply@github.com>2022-01-28 23:48:40 +0100
commit5a1fd7daddbb07b93e3611d023ea48e1991fc0c6 (patch)
treee592a99163702c4c6214c9519a7983fa58fab13c /vendor/github.com/SevereCloud/vksdk/v2/longpoll-bot/longpoll.go
parentac06a268096285a9f795bd19df950075a930c9d6 (diff)
downloadmatterbridge-msglm-5a1fd7daddbb07b93e3611d023ea48e1991fc0c6.tar.gz
matterbridge-msglm-5a1fd7daddbb07b93e3611d023ea48e1991fc0c6.tar.bz2
matterbridge-msglm-5a1fd7daddbb07b93e3611d023ea48e1991fc0c6.zip
Bump github.com/SevereCloud/vksdk/v2 from 2.11.0 to 2.13.0 (#1698)
Bumps [github.com/SevereCloud/vksdk/v2](https://github.com/SevereCloud/vksdk) from 2.11.0 to 2.13.0. - [Release notes](https://github.com/SevereCloud/vksdk/releases) - [Commits](https://github.com/SevereCloud/vksdk/compare/v2.11.0...v2.13.0) --- updated-dependencies: - dependency-name: github.com/SevereCloud/vksdk/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/SevereCloud/vksdk/v2/longpoll-bot/longpoll.go')
-rw-r--r--vendor/github.com/SevereCloud/vksdk/v2/longpoll-bot/longpoll.go58
1 files changed, 57 insertions, 1 deletions
diff --git a/vendor/github.com/SevereCloud/vksdk/v2/longpoll-bot/longpoll.go b/vendor/github.com/SevereCloud/vksdk/v2/longpoll-bot/longpoll.go
index c4a3efec..6cde105a 100644
--- a/vendor/github.com/SevereCloud/vksdk/v2/longpoll-bot/longpoll.go
+++ b/vendor/github.com/SevereCloud/vksdk/v2/longpoll-bot/longpoll.go
@@ -8,8 +8,11 @@ package longpoll // import "github.com/SevereCloud/vksdk/v2/longpoll-bot"
import (
"context"
"encoding/json"
+ "errors"
"fmt"
+ "io"
"net/http"
+ "strconv"
"github.com/SevereCloud/vksdk/v2"
"github.com/SevereCloud/vksdk/v2/api"
@@ -117,7 +120,7 @@ func (lp *LongPoll) check(ctx context.Context) (response Response, err error) {
}
defer resp.Body.Close()
- err = json.NewDecoder(resp.Body).Decode(&response)
+ response, err = parseResponse(resp.Body)
if err != nil {
return response, err
}
@@ -127,6 +130,59 @@ func (lp *LongPoll) check(ctx context.Context) (response Response, err error) {
return response, err
}
+func parseResponse(reader io.Reader) (response Response, err error) {
+ decoder := json.NewDecoder(reader)
+ for decoder.More() {
+ token, err := decoder.Token()
+ if err != nil {
+ if errors.Is(err, io.EOF) {
+ break
+ }
+
+ return response, err
+ }
+
+ t, ok := token.(string)
+ if !ok {
+ continue
+ }
+
+ switch t {
+ case "failed":
+ raw, err := decoder.Token()
+ if err != nil {
+ return response, err
+ }
+
+ response.Failed = int(raw.(float64))
+ case "updates":
+ var updates []events.GroupEvent
+
+ err = decoder.Decode(&updates)
+ if err != nil {
+ return response, err
+ }
+
+ response.Updates = updates
+ case "ts":
+ // can be a number in the response with "failed" field: {"ts":8,"failed":1}
+ // or string, e.g. {"ts":"8","updates":[]}
+ rawTs, err := decoder.Token()
+ if err != nil {
+ return response, err
+ }
+
+ if ts, isNumber := rawTs.(float64); isNumber {
+ response.Ts = strconv.Itoa(int(ts))
+ } else {
+ response.Ts = rawTs.(string)
+ }
+ }
+ }
+
+ return response, err
+}
+
func (lp *LongPoll) checkResponse(response Response) (err error) {
switch response.Failed {
case 0: