1
0
telegram/set_game_score.go

61 lines
1.8 KiB
Go
Raw Normal View History

2017-10-17 11:14:27 +00:00
package telegram
import json "github.com/pquerna/ffjson/ffjson"
2018-04-19 13:02:15 +00:00
// SetGameScoreParameters represents data for SetGameScore method.
2017-10-17 11:14:27 +00:00
type SetGameScoreParameters struct {
// User identifier
UserID int `json:"user_id"`
// New score, must be non-negative
Score int `json:"score"`
// Required if inline_message_id is not specified. Identifier of the sent
// message
MessageID int `json:"message_id,omitempty"`
2017-10-17 11:14:27 +00:00
// Pass True, if the high score is allowed to decrease. This can be useful
// when fixing mistakes or banning cheaters
Force bool `json:"force,omitempty"`
// Pass True, if the game message should not be automatically edited to
// include the current scoreboard
DisableEditMessage bool `json:"disable_edit_message,omitempty"`
// Required if inline_message_id is not specified. Unique identifier for the
// target chat
ChatID int64 `json:"chat_id,omitempty"`
// Required if chat_id and message_id are not specified. Identifier of the
// inline message
InlineMessageID string `json:"inline_message_id,omitempty"`
}
2018-04-19 13:02:15 +00:00
// NewGameScore creates SetGameScoreParameters only with required parameters.
2017-10-17 11:14:27 +00:00
func NewGameScore(userID, score int) *SetGameScoreParameters {
return &SetGameScoreParameters{
UserID: userID,
Score: score,
}
}
// SetGameScore set the score of the specified user in a game. On success, if the
// message was sent by the bot, returns the edited Message, otherwise returns
// True. Returns an error, if the new score is not greater than the user's
// current score in the chat and force is False.
func (bot *Bot) SetGameScore(params *SetGameScoreParameters) (*Message, error) {
dst, err := json.Marshal(params)
2017-10-17 11:14:27 +00:00
if err != nil {
return nil, err
}
2018-04-12 11:58:05 +00:00
resp, err := bot.request(dst, MethodSetGameScore)
2017-10-17 11:14:27 +00:00
if err != nil {
return nil, err
}
var data Message
err = json.Unmarshal(*resp.Result, &data)
return &data, err
}