-
Notifications
You must be signed in to change notification settings - Fork 26
/
games.go
73 lines (61 loc) · 2.63 KB
/
games.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Echotron
* Copyright (C) 2018 The Echotron Contributors
*
* Echotron is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Echotron is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package echotron
import "net/url"
// Game represents a game.
type Game struct {
Title string `json:"title"`
Description string `json:"description"`
Photo []PhotoSize `json:"photo"`
Text string `json:"text,omitempty"`
TextEntities []MessageEntity `json:"text_entities,omitempty"`
Animation Animation `json:"animation,omitempty"`
}
// CallbackGame is a placeholder, currently holds no information.
type CallbackGame struct{}
// GameHighScore represents one row of the high scores table for a game.
type GameHighScore struct {
User User `json:"user"`
Position int `json:"position"`
Score int `json:"score"`
}
// GameScoreOptions contains the optional parameters used in SetGameScore method.
type GameScoreOptions struct {
Force bool `query:"force"`
DisableEditMessage bool `query:"disable_edit_message"`
}
// SendGame is used to send a Game.
func (a API) SendGame(gameShortName string, chatID int64, opts *BaseOptions) (res APIResponseMessage, err error) {
var vals = make(url.Values)
vals.Set("chat_id", itoa(chatID))
vals.Set("game_short_name", gameShortName)
return res, client.get(a.base, "sendGame", addValues(vals, opts), &res)
}
// SetGameScore is used to set the score of the specified user in a game.
func (a API) SetGameScore(userID int64, score int, msgID MessageIDOptions, opts *GameScoreOptions) (res APIResponseMessage, err error) {
var vals = make(url.Values)
vals.Set("user_id", itoa(userID))
vals.Set("score", itoa(int64(score)))
return res, client.get(a.base, "setGameScore", addValues(addValues(vals, msgID), opts), &res)
}
// GetGameHighScores is used to get data for high score tables.
func (a API) GetGameHighScores(userID int64, opts MessageIDOptions) (res APIResponseGameHighScore, err error) {
var vals = make(url.Values)
vals.Set("user_id", itoa(userID))
return res, client.get(a.base, "getGameHighScores", addValues(vals, opts), &res)
}