Skip to content

Commit

Permalink
context: add boost send cases, boost: fix UserBoosts (tucnak#686)
Browse files Browse the repository at this point in the history
* context: add boost send cases, boost: fix UserBoosts

* context: change method order

* boost: add error wrap

* context: update sender method
  • Loading branch information
Nash-Well authored May 27, 2024
1 parent 77f77a6 commit e0c24df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
6 changes: 4 additions & 2 deletions boost.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ func (b *Bot) UserBoosts(chat, user Recipient) ([]Boost, error) {
}

var resp struct {
Result []Boost `json:"boosts"`
Result struct {
Boosts []Boost `json:"boosts"`
}
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return resp.Result, nil
return resp.Result.Boosts, nil
}
23 changes: 15 additions & 8 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ type Context interface {
// Bot returns the bot instance.
Bot() *Bot

// Boost returns the boost instance.
Boost() *BoostUpdated

// BoostRemoved returns the boost removed from a chat instance.
BoostRemoved() *BoostRemoved

// Update returns the original update.
Update() Update

Expand Down Expand Up @@ -164,6 +158,12 @@ type Context interface {
// RespondAlert sends an alert response for the current callback query.
RespondAlert(text string) error

// Boost returns the boost instance.
Boost() *BoostUpdated

// BoostRemoved returns the boost removed from a chat instance.
BoostRemoved() *BoostRemoved

// Get retrieves data from the context.
Get(key string) interface{}

Expand Down Expand Up @@ -301,9 +301,16 @@ func (c *nativeContext) Sender() *User {
return c.u.ChatMember.Sender
case c.u.ChatJoinRequest != nil:
return c.u.ChatJoinRequest.Sender
default:
return nil
case c.u.Boost != nil:
if b := c.u.Boost.Boost; b != nil && b.Source != nil {
return b.Source.Booster
}
case c.u.BoostRemoved != nil:
if b := c.u.BoostRemoved; b.Source != nil {
return b.Source.Booster
}
}
return nil
}

func (c *nativeContext) Chat() *Chat {
Expand Down

0 comments on commit e0c24df

Please sign in to comment.