-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.awk
More file actions
executable file
·49 lines (44 loc) · 1.22 KB
/
Copy pathmain.awk
File metadata and controls
executable file
·49 lines (44 loc) · 1.22 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
#!/bin/awk -f
@include "config.awk"
@include "telegram.awk"
BEGIN {
seeded = 0
while (1) {
resp = poll()
if (resp == "error") {
print("Failed to poll new updates")
exit(1)
}
else if (resp == "empty") {
print("No new updates")
continue
}
if (seeded == 0) {
srand(TG_RT_OFFSET)
seeded = 1
}
text = MSG_TEXT
if (text == "/start") {
print("Got a start command")
if (send_message(MSG_CHAT_ID, "👋 Hello! I'm an <b>awk-powered</b> bot. Here's what I can do:\n\n/chat_id — show current chat_id\n/random — generate a random number\n/start — show this message") == "false") {
print("Failed to respond")
exit(2)
}
}
else if (text == "/random") {
if (send_message(MSG_CHAT_ID, sprintf("🎲 Here's your random number: <code>%d</code>", rand() * 1000000000)) == "false") {
print("Failed to respond")
exit(2)
}
}
else if (text == "/chat_id") {
if (send_message(MSG_CHAT_ID, sprintf("🪪 Current chat_id: <code>%d</code>", MSG_CHAT_ID)) == "false") {
print("Failed to respond")
exit(2)
}
}
else {
printf("Got an unknown command: %s", text)
}
}
}