-
Notifications
You must be signed in to change notification settings - Fork 3
/
core.clj
147 lines (124 loc) · 5.25 KB
/
core.clj
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
(ns telegrambot-lib.games.core
"Telegram Bot API Games - function implementations.
- <https://core.telegram.org/bots/api#games>
Most functions are multi-arity with the following options:
- Send all parameters in a 'content' map.
- Send only the required parameters as simple values.
- Send the required paraemters as simple values and then 'optional' parameters in a map."
(:gen-class)
(:require [telegrambot-lib.http :as http]))
(defn send-game
"Use this method to send a game.
On success, the sent Message is returned.
Required
- this ; a bot instance
- chat_id ; target chat id
- game_short_name ; serves as unique id for the game
Optional
- disable_notification ; send message silently
- reply_to_message_id ; id of original message
- allow_sending_without_reply ; true to send message even if replied-to message is not found
- reply_markup ; inline keyboard markup"
([this content]
(http/request this "sendGame" content))
([this chat_id game_short_name]
(let [content {:chat_id chat_id
:game_short_name game_short_name}]
(send-game this content)))
([this chat_id game_short_name & optional]
(let [content (merge (first optional)
{:chat_id chat_id
:game_short_name game_short_name})]
(send-game this content))))
(defn set-game-score
"Use this method to 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.
Required
- this ; a bot instance
- chat_id ; id of target chat
- message_id ; id of the sent message
- user_id ; user identifier
- score ; new score, non-negative
Optional
- force ; true if high score is allowed to decrease
- disable_edit_message ; true if game msg should not be auto edited to include the scoreboard"
([this content]
(http/request this "setGameScore" content))
([this chat_id message_id user_id score]
(let [content {:chat_id chat_id
:message_id message_id
:user_id user_id
:score score}]
(set-game-score this content)))
([this chat_id message_id user_id score & optional]
(let [content (merge (first optional)
{:chat_id chat_id
:message_id message_id
:user_id user_id
:score score})]
(set-game-score this content))))
(defn set-game-score-inline
"Use this method to set the inline 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.
Required
- this ; a bot instance
- inline_message_id ; id of the inline message
- user_id ; user identifier
- score ; new score, non-negative
Optional
- force ; true if high score is allowed to decrease
- disable_edit_message ; true if game msg should not be auto edited to include the scoreboard"
([this content]
(http/request this "setGameScore" content))
([this inline_message_id user_id score]
(let [content {:inline_message_id inline_message_id
:user_id user_id
:score score}]
(set-game-score-inline this content)))
([this inline_message_id user_id score & optional]
(let [content (merge (first optional)
{:inline_message_id inline_message_id
:user_id user_id
:score score})]
(set-game-score-inline this content))))
(defn get-game-high-scores
"Use this method to get data for high score tables.
Will return the score of the specified user and several of their neighbors in a game.
On success, returns an Array of GameHighScore objects.
Required
- this ; a bot instance
- chat_id ; id of the target chat
- message_id ; id of the sent message
- user_id ; target user"
([this content]
(http/request this "getGameHighScores" content))
([this chat_id message_id user_id]
(let [content {:chat_id chat_id
:message_id message_id
:user_id user_id}]
(get-game-high-scores this content))))
(defn get-game-high-scores-inline
"Use this method to get data for inline high score tables.
Will return the score of the specified user and several of their neighbors in a game.
On success, returns an Array of GameHighScore objects.
Required
- this ; a bot instance
- inline_message_id ; id of the sent message
- user_id ; target user"
([this content]
(http/request this "getGameHighScores" content))
([this inline_message_id user_id]
(let [content {:inline_message_id inline_message_id
:user_id user_id}]
(get-game-high-scores-inline this content))))
(def behavior
"Map for extending the core TBot record with functions."
{:send-game send-game
:set-game-score set-game-score
:set-game-score-inline set-game-score-inline
:get-game-high-scores get-game-high-scores
:get-game-high-scores-inline get-game-high-scores-inline})