aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaria Lisina <sekoohaka.sarisan@gmail.com>2026-02-09 12:45:45 +0300
committerMaria Lisina <sekoohaka.sarisan@gmail.com>2026-02-09 12:45:45 +0300
commit691b22ecacdaa3362003aafa0a2ad0f0d3183f4d (patch)
tree813164d5e5963865ff2599149e9eba21bda8c0cd
parent76173f433c911e7cda0db25d5b6af4c47e8b591d (diff)
bot: Set bot commands on startup
Signed-off-by: Maria Lisina <sekoohaka.sarisan@gmail.com>
-rwxr-xr-xbot.zsh65
-rw-r--r--files/commands.json.default35
2 files changed, 94 insertions, 6 deletions
diff --git a/bot.zsh b/bot.zsh
index a9d0f86..1af5f4a 100755
--- a/bot.zsh
+++ b/bot.zsh
@@ -483,20 +483,20 @@ source "${units}/log.zsh"
log_text="Running files age check..."
source "${units}/log.zsh"
-for file in aliases blacklist help whitelist
+for file in aliases.txt blacklist.txt commands.json help.txt whitelist.txt
do
- log_text="files/${file}.txt"
+ log_text="files/${file}"
source "${units}/log.zsh"
- if [[ -f "${files}/${file}.txt" ]]
+ if [[ -f "${files}/${file}" ]]
then
- if [[ "${files}/${file}.txt" -ot "${files}/${file}.txt.default" ]]
+ if [[ "${files}/${file}" -ot "${files}/${file}xt.default" ]]
then
- log_text="Warning: File ${file}.txt is older than ${file}.txt.default"
+ log_text="Warning: File ${file} is older than ${file}.default"
source "${units}/log.zsh"
fi
else
- < "${files}/${file}.txt.default" > "${files}/${file}.txt"
+ < "${files}/${file}.default" > "${files}/${file}"
fi
done
@@ -854,6 +854,59 @@ then
exit 1
fi
+log_text="Setting bot commands..."
+source "${units}/log.zsh"
+
+commands_list="$(< "${files}/commands.json")"
+
+if [[ -n "${nocommand_source}" ]]
+then
+ commands_list="$(jq 'del(.[]|select(.command=="source"))' <<< "${commands_list}")"
+fi
+
+if ! input_data="$(
+ curl --connect-timeout ${connrefused_timeout} \
+ --data-urlencode "commands=${commands_list}" \
+ --get \
+ --max-time ${internal_timeout} \
+ --proxy "${internal_proxy}" \
+ --retry 1 \
+ --retry-connrefused \
+ --retry-max-time $((internal_timeout - connrefused_timeout)) \
+ --silent \
+ --user-agent "${useragent}" \
+ "${api_address}/bot${api_token}/setMyCommands"
+)"
+then
+ log_text="setMyCommands: Failed to access Telegram Bot API"
+ source "${units}/log.zsh"
+
+ exit 1
+fi
+
+if ! jq -e '.' <<< "${input_data}" > /dev/null
+then
+ log_text="setMyCommands: An unknown error occurred"
+ source "${units}/log.zsh"
+
+ exit 1
+fi
+
+if [[ "$(jq -r '.ok' <<< "${input_data}")" != "true" ]]
+then
+ error_description="$(jq -r '.description' <<< "${input_data}")"
+
+ if [[ "${error_description}" != "null" ]]
+ then
+ log_text="setMyCommands: ${error_description}"
+ else
+ log_text="setMyCommands: An unknown error occurred"
+ fi
+
+ source "${units}/log.zsh"
+ exit 1
+fi
+
strftime %s > "${cache}.timer"
log_text="Startup succeeded"
diff --git a/files/commands.json.default b/files/commands.json.default
new file mode 100644
index 0000000..516b308
--- /dev/null
+++ b/files/commands.json.default
@@ -0,0 +1,35 @@
+[
+ {
+ "command": "help", "description": "Send help message"
+ },
+ {
+ "command": "authorize", "description": "Authorize to image board"
+ },
+ {
+ "command": "original", "description": "Get original file of post"
+ },
+ {
+ "command": "post", "description": "Get information of post"
+ },
+ {
+ "command": "hash", "description": "Get posts IDs by hash lookup"
+ },
+ {
+ "command": "source", "description": "Reverse search image"
+ },
+ {
+ "command": "short", "description": "Create inline shortcut"
+ },
+ {
+ "command": "shorts", "description": "Manage saved shortcuts"
+ },
+ {
+ "command": "ping", "description": "Measure bot latency"
+ },
+ {
+ "command": "export", "description": "Export all your data"
+ },
+ {
+ "command": "stop", "description": "Remove all your data"
+ }
+]