2020-01-09 15:27:00 +00:00
|
|
|
|
package telegram
|
|
|
|
|
|
|
|
|
|
type (
|
2020-11-05 08:28:32 +00:00
|
|
|
|
// Game represents a game. Use BotFather to create and edit games, their short names will act as unique
|
|
|
|
|
// identifiers.
|
2020-01-09 15:27:00 +00:00
|
|
|
|
Game struct {
|
|
|
|
|
// Title of the game
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
|
|
|
|
|
// Description of the game
|
|
|
|
|
Description string `json:"description"`
|
|
|
|
|
|
2020-11-05 08:28:32 +00:00
|
|
|
|
// Brief description of the game or high scores included in the game message. Can be automatically
|
|
|
|
|
// edited to include current high scores for the game when the bot calls setGameScore, or manually
|
|
|
|
|
// edited using editMessageText. 0-4096 characters.
|
2020-01-09 15:27:00 +00:00
|
|
|
|
Text string `json:"text,omitempty"`
|
|
|
|
|
|
|
|
|
|
// Photo that will be displayed in the game message in chats.
|
2020-01-28 08:30:47 +00:00
|
|
|
|
Photo Photo `json:"photo"`
|
2020-01-09 15:27:00 +00:00
|
|
|
|
|
|
|
|
|
// Special entities that appear in text, such as usernames, URLs, bot commands, etc.
|
|
|
|
|
TextEntities []*MessageEntity `json:"text_entities,omitempty"`
|
|
|
|
|
|
|
|
|
|
// Animation that will be displayed in the game message in chats. Upload via BotFather
|
|
|
|
|
Animation *Animation `json:"animation,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CallbackGame a placeholder, currently holds no information. Use BotFather to set up your game.
|
|
|
|
|
CallbackGame struct{}
|
|
|
|
|
|
|
|
|
|
// GameHighScore represents one row of the high scores table for a game.
|
|
|
|
|
GameHighScore struct {
|
|
|
|
|
// Position in high score table for the game
|
|
|
|
|
Position int `json:"position"`
|
|
|
|
|
|
|
|
|
|
// Score
|
|
|
|
|
Score int `json:"score"`
|
|
|
|
|
|
|
|
|
|
// User
|
|
|
|
|
User *User `json:"user"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SendGameParameters represents data for SendGame method.
|
|
|
|
|
SendGame struct {
|
|
|
|
|
// Unique identifier for the target chat
|
|
|
|
|
ChatID int64 `json:"chat_id"`
|
|
|
|
|
|
2020-11-05 08:28:32 +00:00
|
|
|
|
// Short name of the game, serves as the unique identifier for the game. Set up your games via
|
|
|
|
|
// BotFather.
|
2020-01-09 15:27:00 +00:00
|
|
|
|
GameShortName string `json:"game_short_name"`
|
|
|
|
|
|
|
|
|
|
// Sends the message silently. Users will receive a notification with no sound.
|
|
|
|
|
DisableNotification bool `json:"disable_notification,omitempty"`
|
|
|
|
|
|
|
|
|
|
// If the message is a reply, ID of the original message.
|
2021-03-09 14:15:28 +00:00
|
|
|
|
ReplyToMessageID int64 `json:"reply_to_message_id,omitempty"`
|
2020-01-09 15:27:00 +00:00
|
|
|
|
|
2020-11-05 08:28:32 +00:00
|
|
|
|
// Pass True, if the message should be sent even if the specified replied-to message is not found
|
|
|
|
|
AllowSendingWithoutReply bool `json:"allow_sending_without_reply,omitempty"`
|
|
|
|
|
|
|
|
|
|
// A JSON-serialized object for an inline keyboard. If empty, one ‘Play game_title’ button will be
|
|
|
|
|
// shown. If not empty, the first button must launch the game.
|
2020-01-09 15:27:00 +00:00
|
|
|
|
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetGameScoreParameters represents data for SetGameScore method.
|
|
|
|
|
SetGameScore struct {
|
|
|
|
|
// User identifier
|
2021-03-09 14:15:28 +00:00
|
|
|
|
UserID int64 `json:"user_id"`
|
2020-01-09 15:27:00 +00:00
|
|
|
|
|
|
|
|
|
// New score, must be non-negative
|
|
|
|
|
Score int `json:"score"`
|
|
|
|
|
|
|
|
|
|
// Required if inline_message_id is not specified. Identifier of the sent message
|
2021-03-09 14:15:28 +00:00
|
|
|
|
MessageID int64 `json:"message_id,omitempty"`
|
2020-01-09 15:27:00 +00:00
|
|
|
|
|
2020-11-05 08:28:32 +00:00
|
|
|
|
// Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or
|
|
|
|
|
// banning cheaters
|
2020-01-09 15:27:00 +00:00
|
|
|
|
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"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetGameHighScoresParameters represents data for GetGameHighScores method.
|
|
|
|
|
GetGameHighScores struct {
|
|
|
|
|
// Target user id
|
2021-03-09 14:15:28 +00:00
|
|
|
|
UserID int64 `json:"user_id"`
|
2020-01-09 15:27:00 +00:00
|
|
|
|
|
|
|
|
|
// Required if inline_message_id is not specified. Identifier of the sent message
|
2021-03-09 14:15:28 +00:00
|
|
|
|
MessageID int64 `json:"message_id,omitempty"`
|
2020-01-09 15:27:00 +00:00
|
|
|
|
|
|
|
|
|
// 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"`
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
2020-01-28 08:30:47 +00:00
|
|
|
|
func NewGame(chatID int64, gameShortName string) SendGame {
|
|
|
|
|
return SendGame{
|
|
|
|
|
ChatID: chatID,
|
|
|
|
|
GameShortName: gameShortName,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-09 15:27:00 +00:00
|
|
|
|
// SendGame send a game. On success, the sent Message is returned.
|
2020-01-10 05:23:55 +00:00
|
|
|
|
func (b Bot) SendGame(p SendGame) (*Message, error) {
|
2020-01-09 15:27:00 +00:00
|
|
|
|
src, err := b.Do(MethodSendGame, p)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result := new(Message)
|
2020-06-05 21:57:29 +00:00
|
|
|
|
if err = parseResponseError(b.marshler, src, result); err != nil {
|
2020-01-09 15:27:00 +00:00
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-09 14:15:28 +00:00
|
|
|
|
func NewGameScore(userID int64, score int) SetGameScore {
|
2020-01-28 08:30:47 +00:00
|
|
|
|
return SetGameScore{
|
|
|
|
|
UserID: userID,
|
|
|
|
|
Score: score,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-05 08:28:32 +00:00
|
|
|
|
// 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.
|
2020-01-10 05:23:55 +00:00
|
|
|
|
func (b Bot) SetGameScore(p SetGameScore) (*Message, error) {
|
2020-01-09 15:27:00 +00:00
|
|
|
|
src, err := b.Do(MethodSetGameScore, p)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result := new(Message)
|
2020-06-05 21:57:29 +00:00
|
|
|
|
if err = parseResponseError(b.marshler, src, result); err != nil {
|
2020-01-09 15:27:00 +00:00
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-05 08:28:32 +00:00
|
|
|
|
// GetGameHighScores get data for high score tables. Will return the score of the specified user and several of his
|
|
|
|
|
// neighbors in a game. On success, returns an Array of GameHighScore objects.
|
2020-01-10 05:23:55 +00:00
|
|
|
|
func (b Bot) GetGameHighScores(p GetGameHighScores) ([]*GameHighScore, error) {
|
2020-01-09 15:27:00 +00:00
|
|
|
|
src, err := b.Do(MethodGetGameHighScores, p)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result := make([]*GameHighScore, 0)
|
2020-06-05 21:57:29 +00:00
|
|
|
|
if err = parseResponseError(b.marshler, src, &result); err != nil {
|
2020-01-09 15:27:00 +00:00
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|