From 5a1fd7daddbb07b93e3611d023ea48e1991fc0c6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 Jan 2022 23:48:40 +0100 Subject: 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] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .../SevereCloud/vksdk/v2/longpoll-bot/README.md | 2 +- .../SevereCloud/vksdk/v2/longpoll-bot/longpoll.go | 58 +++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) (limited to 'vendor/github.com/SevereCloud/vksdk/v2/longpoll-bot') diff --git a/vendor/github.com/SevereCloud/vksdk/v2/longpoll-bot/README.md b/vendor/github.com/SevereCloud/vksdk/v2/longpoll-bot/README.md index 94d87dba..8d8be2a0 100644 --- a/vendor/github.com/SevereCloud/vksdk/v2/longpoll-bot/README.md +++ b/vendor/github.com/SevereCloud/vksdk/v2/longpoll-bot/README.md @@ -10,7 +10,7 @@ Long Poll настраивается автоматически. Вам не т ### Версия API -Данная библиотека поддерживает версию API **5.122**. +Данная библиотека поддерживает версию API **5.131**. ### Инициализация 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: -- cgit v1.2.3