/
game_sendables.go
120 lines (103 loc) · 3.46 KB
/
game_sendables.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package ext
import (
"encoding/json"
"net/url"
"strconv"
)
type sendableGame struct {
bot Bot
ChatId int
GameShortName string
DisableNotification bool
ReplyToMessageId int
AllowSendingWithoutReply bool
ReplyMarkup *InlineKeyboardMarkup
}
func (b Bot) NewSendableGame(chatId int, gameShortName string) *sendableGame {
return &sendableGame{
bot: b,
ChatId: chatId,
GameShortName: gameShortName,
AllowSendingWithoutReply: b.AllowSendingWithoutReply,
}
}
func (g *sendableGame) Send() (*Message, error) {
var replyMarkupBytes []byte
if g.ReplyMarkup != nil {
var err error
replyMarkupBytes, err = g.ReplyMarkup.Marshal()
if err != nil {
return nil, err
}
}
v := url.Values{}
v.Add("chat_id", strconv.Itoa(g.ChatId))
v.Add("game_short_name", g.GameShortName)
v.Add("disable_notification", strconv.FormatBool(g.DisableNotification))
v.Add("reply_to_message_id", strconv.Itoa(g.ReplyToMessageId))
v.Add("allow_sending_without_reply", strconv.FormatBool(g.AllowSendingWithoutReply))
v.Add("reply_markup", string(replyMarkupBytes))
r, err := g.bot.Get("sendGame", v)
if err != nil {
return nil, err
}
return g.bot.ParseMessage(r)
}
type sendableSetGameScore struct {
bot Bot
UserId int
Score int
Force bool
DisableEditMessage bool
ChatId int
MessageId int
InlineMessageId string
}
func (b Bot) NewSendableSetGameScore(userId int, score int, chatId int, messageId int) *sendableSetGameScore {
return &sendableSetGameScore{bot: b, UserId: userId, Score: score, ChatId: chatId, MessageId: messageId}
}
func (b Bot) NewSendableSetGameScoreInline(userId int, score int, inlineMessageId string) *sendableSetGameScore {
return &sendableSetGameScore{bot: b, UserId: userId, Score: score, InlineMessageId: inlineMessageId}
}
func (sgs *sendableSetGameScore) Send() (bool, error) {
v := url.Values{}
v.Add("user_id", strconv.Itoa(sgs.UserId))
v.Add("score", strconv.Itoa(sgs.Score))
v.Add("force", strconv.FormatBool(sgs.Force))
v.Add("disable_edit_message", strconv.FormatBool(sgs.DisableEditMessage))
v.Add("chat_id", strconv.Itoa(sgs.ChatId))
v.Add("message_id", strconv.Itoa(sgs.MessageId))
v.Add("inline_message_id", sgs.InlineMessageId)
r, err := sgs.bot.Get("setGameScore", v)
if err != nil {
return false, err
}
var bb bool
return bb, json.Unmarshal(r, &bb)
}
type sendableGetGameHighScores struct {
bot Bot
UserId int
ChatId int
MessageId int
InlineMessageId string
}
func (b Bot) NewSendableGetGameHighScore(userId int, chatId int, messageId int) *sendableGetGameHighScores {
return &sendableGetGameHighScores{bot: b, UserId: userId, ChatId: chatId, MessageId: messageId}
}
func (b Bot) NewSendableGetGameHighScoreInline(userId int, inlineMessageId string) *sendableGetGameHighScores {
return &sendableGetGameHighScores{bot: b, UserId: userId, InlineMessageId: inlineMessageId}
}
func (gghs *sendableGetGameHighScores) Send() ([]GameHighScore, error) {
v := url.Values{}
v.Add("user_id", strconv.Itoa(gghs.UserId))
v.Add("chat_id", strconv.Itoa(gghs.ChatId))
v.Add("message_id", strconv.Itoa(gghs.MessageId))
v.Add("inline_message_id", gghs.InlineMessageId)
r, err := gghs.bot.Get("getGameHighScores", v)
if err != nil {
return nil, err
}
var ghs []GameHighScore
return ghs, json.Unmarshal(r, &ghs)
}