-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathldpldocbot.ldpl
114 lines (103 loc) · 4.69 KB
/
ldpldocbot.ldpl
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
# +-----------------------------------------------------+
# | ltb - LDPL Telegram Bot |
# +-----------------------------------------------------+
# | by Damián Garro |
# | https://github.com/dgarroDC/ltb |
# +-----------------------------------------------------+
# | LDPLDocBot example: |
# | This bot responds to the commands: |
# | * /ldpldoc <statatement>: |
# | returns information about a LDPL statement |
# | * /ldplall: |
# | shows a keyboard with LDPL statements as buttons, |
# | if you press one it displays information about it |
# +-----------------------------------------------------+
INCLUDE "../ltb.ldpl"
INCLUDE "token.ldpl"
DATA:
# Stataments information
quickinfo is text map
docurl is text map
PROCEDURE:
# Load the statements info
store "The DISPLAY statement outputs the values passed to the output stream." in quickinfo:"DISPLAY"
store "https://docs.ldpl-lang.org/i-o-statements/display" in docurl:"DISPLAY"
store "The ACCEPT command is used to gather input from the user." in quickinfo:"ACCEPT"
store "https://docs.ldpl-lang.org/i-o-statements/accept" in docurl:"ACCEPT"
store "The RETURN statement returns from a SUB-PROCEDURE." in quickinfo:"RETURN"
store "https://docs.ldpl-lang.org/control-flow-statements/return" in docurl:"RETURN"
# ...
TG BOT INIT WITH TOKEN token
# 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:
myMessage is text
i is number
statement is text
inlineKeyboard is text
key is text
keys is text list
callbackData is text
procedure:
get index of "/ldpldoc" from messageText in i
if i is equal to 0 then
get length of messageText in i
in i solve i - 8
substring messageText from 8 length i in statement
trim statement in statement
if quickinfo:statement is not equal to "" then
in myMessage join quickinfo:statement crlf "👉 More info: " docurl:statement
else
in myMessage join "I'm sorry, I don't know anything about the '" statement "' statement. :("
end if
TG BOT SEND MESSAGE myMessage TO chatId
end if
get index of "/ldplall" from messageText in i
if i is equal to 0 then
TG BOT CREATE INLINE KEYBOARD IN inlineKeyboard
store 0 in i
get keys of quickinfo in keys
for each key in keys do
TG BOT ADD BUTTON WITH TEXT key AND CALLBACK DATA key TO INLINE KEYBOARD inlineKeyboard
repeat
TG BOT ADD ROW TO INLINE KEYBOARD inlineKeyboard
TG BOT ADD BUTTON WITH TEXT "Read the docs!" AND URL "https://docs.ldpl-lang.org/" TO INLINE KEYBOARD inlineKeyboard
TG BOT SEND MESSAGE "Press a button to learn something about the statement:" TO chatId WITH INLINE KEYBOARD inlineKeyboard
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:
in answerText join "Here is the " callbackData " info, " userData:"first_name" ":\n" quickinfo:callbackData
store 1 in answerAlert
end sub