-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoodlestbot.ldpl
More file actions
246 lines (223 loc) · 7.62 KB
/
doodlestbot.ldpl
File metadata and controls
246 lines (223 loc) · 7.62 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
INCLUDE "ltb/ltb.ldpl"
INCLUDE "token.ldpl"
PROCEDURE:
tg bot init with token token
# Get the current games of a chat in a list
sub getGamesList
parameters:
gamesList is text list
chatId is number
local data:
gamesFile is text
games is text
procedure:
clear gamesList
in gamesFile join "games/" chatId
load file gamesFile in games
if errorcode is equal to 0 then
split games by crlf in gamesList
delete last element of gamesList # File ends in newline, ignore last ""
end if
end sub
# Adds a game to the chat's games list by play URL, increments new games counter
sub addGame
parameters:
gameURL is text
chatId is number
newGames is number
local data:
id is text
i is number
j is number
gamesList is text list
game is text
gamesFile is text
procedure:
get length of "https://www.doodlest.com/play/" in i
get length of gameURL in j
in j solve j - i
substring gameURL from i length j in id
store id in i
if i is equal to 0 then
return # id is not a number (or it's 0, lets hope it's not a valid id)
end if
call getGamesList with gamesList chatId
for each game in gamesList do
if game is equal to id then
return # repeated game
end if
repeat
in newGames solve newGames + 1
in id join id crlf
in gamesFile join "games/" chatId
append id to file gamesFile
end sub
# /games command
sub displayGames
parameters:
chatId is number
local data:
i is number
games is text
gamesList is text list
game is text
endedGames is text list
currentGames is text list
gamesPlayers is text list # (total0, played0, remaining0, total1, ...)
totalPlayers is number
playedPlayers is number
remainingPlayers is number
totalPlayersL is number list
playedPlayersL is number list
response is text
length is number
gamesFile is text
keyboard is text
procedure:
store 1 in ltb.send.options:"disable_preview"
call getGamesList with gamesList chatId
get length of gamesList in length
if length is equal to 0 then
in response join "😱 No games in progress, create one now:" crlf "https://www.doodlest.com/create/"
store 1 in errorcode
while errorcode is equal to 1 do
tg bot send message response to chatId
repeat
return
end if
# Get games players status
store "https://www.doodlest.com/include/gamesleft.php?id=" in ltb.curl.in.url
for each game in gamesList do
in ltb.curl.in.url join ltb.curl.in.url game ","
repeat
get length of ltb.curl.in.url in length
in length solve length - 1
substring ltb.curl.in.url from 0 length length in ltb.curl.in.url # Delete last ',' (just in case)
clear ltb.curl.in.argNames
clear ltb.curl.in.argValues
store 1 in errorcode
while errorcode is equal to 1 do
call external ltb.curl.request
repeat
split ltb.curl.out.response by " " in gamesPlayers
# Classify games
store 0 in i
for each game in gamesList do
store gamesPlayers:i in totalPlayers
in i solve i + 1
store gamesPlayers:i in playedPlayers
in i solve i + 1
store gamesPlayers:i in remainingPlayers
in i solve i + 1
if remainingPlayers is equal to 0 then
push game to endedGames
else if remainingPlayers is greater than 0 then
push game to currentGames
push totalPlayers to totalPlayersL
push playedPlayers to playedPlayersL
end if
repeat
# Display completed games
get length of endedGames in length
if length is greater than 0 then
store "🖼️ New #CompletedGames:" in response
for each game in endedGames do
in response join response crlf "https://www.doodlest.com/gallery/" game
repeat
end if
# Display games in progress
get length of currentGames in length
if length is greater than 0 then
if response is not equal to "" then
in response join response crlf crlf # New line after ended games
end if
in response join response "✏️ Games in progress:"
for i from 0 to length step 1 do
in response join response crlf "[" playedPlayersL:i "/" totalPlayersL:i "] " "https://www.doodlest.com/play/" currentGames:i
in games join games currentGames:i crlf
repeat
end if
# Random public game button
tg bot create inline keyboard in keyboard
tg bot add button with text "🎲 Random public game" and url "https://www.doodlest.com/waitgame" to inline keyboard keyboard
store 1 in errorcode
while errorcode is equal to 1 do
tg bot send message response to chatId with inline keyboard keyboard
repeat
# Update games file
in gamesFile join "games/" chatId
write games to file gamesFile
end sub
# This sub-procedure is called each time a new text message arrives.
# Captions in animation, audio, document, photo, video or voice are captured too.
sub ltb.onMessage
parameters:
messageId is number # id of the sent message
chatId is number # id of the chat where is was sent
userData is text map # user data from sender
messageText is text # content of the message
local data:
i is number
lines is text list
words is text list
line is text
word is text
newGames is number
response is text
procedure:
get index of "/games" from messageText in i
if i is equal to 0 then
call displayGames with chatId
return
end if
split messageText by "\\n" in lines
for each line in lines do
split line by " " in words
for each word in words do
get index of "https://www.doodlest.com/play/" from word in i
if i is equal to 0 then
call addGame with word chatId newGames
end if
repeat
repeat
if newGames is greater than 0 then
if newGames is equal to 1 then
in response join "💥 New Doodlest game added!" crlf
else
in response join "💥 " newGames " new Doodlest games added!" crlf
end if
store 1 in errorcode
while errorcode is equal to 1 do
tg bot send message response to chatId
repeat
end if
end sub
# This sub-procedure is called each time a user joins a chat.
sub ltb.onJoin
parameters:
messageId is number # id of the sent message announcing the user join
chatId is number # id of the chat the user joined
userData is text map # user data from the user who joined the chat
procedure:
# I don't use this sub-procedure :)
end sub
# This sub-procedure is called each time a user leaves a chat.
sub ltb.onDeparture
parameters:
messageId is number # id of the sent message announcing the user departure
chatId is number # id of the chat the user left
userData is text map # user data from the user who left the chat
procedure:
# I don't use this sub-procedure :)
end sub
# This sub-procedure is called each time a user press a button with callback data.
sub ltb.onCallbackQuery
parameters:
chatId is number # id of the chat from the message of the button that was pressed
userData is text map # user data from the user who pressed the button
callbackData is text # callback data from the pressed button
answerText is text # store a text here to display a notification to the user
answerAlert is number # store 1 here to show answerText as an alert instead of a notification at the top of the chat screen
procedure:
# I don't use this sub-procedure :)
end sub