aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaria Lisina <sekoohaka.sarisan@gmail.com>2026-02-07 06:29:44 +0300
committerMaria Lisina <sekoohaka.sarisan@gmail.com>2026-02-07 06:29:44 +0300
commitaa1ca9fa3c7680fc9157003ab7b1e47fa0ee799a (patch)
tree640f352152cec982c4ea867efe90f442f22a9f14
parent0671dc134a9e122ce2c0348f3f4deeb2d274d524 (diff)
*/*: Reimplement help command
Signed-off-by: Maria Lisina <sekoohaka.sarisan@gmail.com>
-rw-r--r--README.md3
-rwxr-xr-xbot.zsh190
-rw-r--r--files/donate.txt.default6
-rw-r--r--files/help.txt.default94
-rw-r--r--handlers/callback.zsh3
-rw-r--r--handlers/commands.zsh3
-rw-r--r--handlers/inline.zsh3
-rw-r--r--operators/callback_help.zsh47
-rw-r--r--operators/command_donate.zsh10
-rw-r--r--operators/command_help.zsh3
-rw-r--r--operators/inline_donate.zsh22
-rw-r--r--operators/inline_help.zsh14
-rw-r--r--units/help.zsh21
13 files changed, 307 insertions, 112 deletions
diff --git a/README.md b/README.md
index aa760f6..2acb94e 100644
--- a/README.md
+++ b/README.md
@@ -42,12 +42,15 @@ For distribution specific installation commands follow [command-not-found](https
* cut
* find
* grep
+* head
* ls
* sed
* sha1sum
* sleep
+* tail
* tar
* tr
+* wc
## Deployment
diff --git a/bot.zsh b/bot.zsh
index 85b9876..9e0fd03 100755
--- a/bot.zsh
+++ b/bot.zsh
@@ -71,12 +71,15 @@ busybox=(
cut
find
grep
+ head
ls
sed
sha1sum
sleep
+ tail
tar
tr
+ wc
)
if [[ -n "${1}" ]]
@@ -480,7 +483,7 @@ source "${units}/log.zsh"
log_text="Running files age check..."
source "${units}/log.zsh"
-for file in aliases blacklist donate help whitelist
+for file in aliases blacklist help whitelist
do
log_text="files/${file}.txt"
source "${units}/log.zsh"
@@ -497,49 +500,6 @@ do
fi
done
-log_text="Running files length check..."
-source "${units}/log.zsh"
-
-for file in donate help
-do
- log_text="files/${file}.txt"
- source "${units}/log.zsh"
-
- file_content="$(< "${files}/${file}.txt")"
-
- if [[ ${#file_content} -gt 4096 ]]
- then
- log_text="Error: File ${file}.txt exceeds 4096 characters limit"
- source "${units}/log.zsh"
- fi
-done
-
-log_text="Running help command check..."
-source "${units}/log.zsh"
-
-help_content="$(sed "s/{version_placeholder}/${version}/" "${files}/help.txt")"
-
-if [[ ${#help_content} -lt 1 ]]
-then
- log_text="Error: File help.txt must be at least 1 character long"
- source "${units}/log.zsh"
-
- exit 1
-fi
-
-log_text="Running donate command check..."
-source "${units}/log.zsh"
-
-donate_content="$(< "${files}/donate.txt")"
-
-if [[ ${#donate_content} -lt 1 ]]
-then
- nocommand_donate=0
-
- log_text="Warning: File donate.txt is empty, donate command is disabled"
- source "${units}/log.zsh"
-fi
-
log_text="Running source command check..."
source "${units}/log.zsh"
@@ -750,14 +710,148 @@ then
esac
fi
-if [[ -n "${nocommand_donate}" ]]
+log_text="Running help command check..."
+source "${units}/log.zsh"
+
+file="${files}/help.txt"
+file_content="$(sed "s/{version_placeholder}/${version}/" "${file}")"
+
+if [[ -n "${nocommand_source}" ]]
then
- help_content="$(sed -e '/^<code>donate.*$/d' -e '/^\/donate.*$/d' <<< "${help_content}")"
+ file_content="$(sed -e '/^\[snkey\].*$/d' -e '/^\/source.*$/d' <<< "${file_content}")"
fi
-if [[ -n "${nocommand_source}" ]]
+help_line_counter=1
+help_max_line=$(($(wc -l <<< "${file_content}" | cut -d ' ' -f 1) + 1))
+
+until [[ ${help_line_counter} -eq $((help_max_line + 1)) ]]
+do
+ help_line="$(sed "${help_line_counter}!d" <<< "${file_content}")"
+
+ if [[ -z "${help_line}" ]]
+ then
+ help_line_counter=$((help_line_counter + 1))
+ continue
+ fi
+
+ if ! help_header="$(grep -x ".*::.*" <<< "${help_line}")"
+ then
+ help_line_counter=$((help_line_counter + 1))
+ continue
+ fi
+
+ help_data="$(cut -d ':' -f 1 <<< "${help_header}")"
+
+ if [[ -z "${help_data}" ]]
+ then
+ log_text="Error: Missing header data at ${file}:${help_line_counter}"
+ source "${units}/log.zsh"
+
+ exit 1
+ fi
+
+ if grep -q ' ' <<< "${help_data}"
+ then
+ log_text="Error: Header data at ${file}:${help_line_counter} contains spaces"
+ source "${units}/log.zsh"
+
+ exit 1
+ fi
+
+ if [[ ${#help_data} -gt 64 ]]
+ then
+ log_text="Error: Header data at ${file}:${help_line_counter} exceeds 64 characters limit"
+ source "${units}/log.zsh"
+
+ exit 1
+ fi
+
+ help_name="$(cut -d ':' -f 3 <<< "${help_header}")"
+
+ if [[ -z "${help_name}" ]]
+ then
+ log_text="Error: Missing header name at ${file}:${help_line_counter}"
+ source "${units}/log.zsh"
+
+ exit 1
+ fi
+
+ if [[ ${#help_name} -gt 32 ]]
+ then
+ log_text="Error: Header name at ${file}:${help_line_counter} exceeds 32 characters limit"
+ source "${units}/log.zsh"
+
+ exit 1
+ fi
+
+ help_line_counter=$((help_line_counter + 1))
+
+ if [[ "$(sed "${help_line_counter}!d" <<< "${file_content}")" != ">>>>>>>>" ]]
+ then
+ log_text="Error: Missing '>>>>>>>>' after '${help_data}' at ${file}:${help_line_counter}"
+ source "${units}/log.zsh"
+
+ exit 1
+ fi
+
+ start_line=${help_line_counter}
+ help_line_counter=$((help_line_counter + 1))
+
+ until [[ ${help_line_counter} -eq $((help_max_line + 1)) ]]
+ do
+ help_line="$(sed "${help_line_counter}!d" <<< "${file_content}")"
+
+ if [[ "${help_line}" = "<<<<<<<<" ]]
+ then
+ end_line=${help_line_counter}
+ break
+ fi
+
+ if [[ ${help_line_counter} -eq ${help_max_line} ]]
+ then
+ log_text="Error: Missing '<<<<<<<<' after '${help_data}' at ${file}:${help_line_counter}"
+ source "${units}/log.zsh"
+
+ exit 1
+ fi
+
+ help_line_counter=$((help_line_counter + 1))
+ done
+
+ help_content="$(tail -n +$((start_line + 1)) <<< "${file_content}" | head -n $((end_line - start_line - 1)))"
+
+ if [[ -z ${help_content} ]]
+ then
+ log_text="Error: Empty content after '${help_data}' at ${file}:$((start_line + 1))"
+ source "${units}/log.zsh"
+
+ exit 1
+ fi
+
+ if [[ ${#help_content} -gt 2048 ]]
+ then
+ log_text="Error: Content exceeds 2048 characters limit after '${help_data}' at ${file}:$((start_line + 1))"
+ source "${units}/log.zsh"
+
+ exit 1
+ fi
+
+ if [[ "${help_data}" == "general" ]]
+ then
+ help_general="${help_content}"
+ else
+ help_table+=("${help_data}" "${help_name}" "${help_content}")
+ fi
+
+ help_line_counter=$((help_line_counter + 1))
+done
+
+if [[ ${#help_general} -eq 0 ]]
then
- help_content="$(sed -e '/^\[snkey\].*$/d' -e '/^\/source.*$/d' <<< "${help_content}")"
+ log_text="Error: No 'general' header found in ${file}"
+ source "${units}/log.zsh"
+
+ exit 1
fi
strftime %s > "${cache}.timer"
diff --git a/files/donate.txt.default b/files/donate.txt.default
deleted file mode 100644
index fdf5429..0000000
--- a/files/donate.txt.default
+++ /dev/null
@@ -1,6 +0,0 @@
-If you want to support this bot development you can donate any amount of these cryptocurrencies
-
-<b>BTC:</b> <code>bc1qqr8yryvx43y6p3kg7y2cw32w6tv748el7k38ff</code>
-<b>ETH:</b> <code>0x8993D744dF7183e112E2A4489991890f6a143104</code>
-<b>BNB:</b> <code>0x8993D744dF7183e112E2A4489991890f6a143104</code>
-<b>TON:</b> <code>UQBdoPQq3akozSLiWqt6x2Rizv0TrxHzRjczoztFN-LMCwGO</code>
diff --git a/files/help.txt.default b/files/help.txt.default
index 00b5b26..f586a81 100644
--- a/files/help.txt.default
+++ b/files/help.txt.default
@@ -1,6 +1,18 @@
+
+general::General
+>>>>>>>>
<b>Sekoohaka Bot v{version_placeholder}</b>
+<b>GitHub:</b> https://github.com/Sarisan/Sekoohaka
+
+Select interesting topic to learn more
+<<<<<<<<
+
+
+fields::Fields Descriptions
+>>>>>>>>
+<b>Fields Descriptions</b>
+Used in commands and inline syntax
-<b>Fields descriptions:</b>
[command] - Inline command
[b] - Image Board
[page] - Search page number
@@ -13,29 +25,69 @@
[login] - Image Board login or username
[key] - Image Board API key or password
[snkey] - SauceNAO API key
+<<<<<<<<
+
+
+inline_search::Inline Search
+>>>>>>>>
+<b>Inline Search</b>
+Inline search syntax
-<b>Inline search:</b>
<code>pools</code> [b] [page] [options] [name] - Pools search
<code>posts</code> [b] [page] [options] [tags] - Posts search
<code>tags</code> [b] [page] [options] [name] - Tags search
<code>shorts</code> [page] [options] [query] - Shortcuts search
-<b>Search options:</b>
+<b>Inline Aliases</b>
+Shortened search commands for compact queries
+
+<code>l</code> - <code>pools</code>
+<code>p</code> - <code>posts</code>
+<code>t</code> - <code>tags</code>
+<code>s</code> - <code>shorts</code>
+
+<b>Search Options</b>
+Inline search unix-like options,
+Aliases inside brackets indicate option support
+
<code>a</code> - Enable autopaging (lpts)
<code>m</code> - Show more metadata (p)
<code>p</code> - Show previews only (p)
<code>q</code> - Add quick buttons (lpts)
<code>r</code> - Reverse search order (s)
<code>w</code> - Match full words only (s)
+<<<<<<<<
+
+
+inline_commands::Inline Commands
+>>>>>>>>
+<b>Inline Commands</b>
+Same as normal commands but used in inline for quicker access
-<b>Inline commands:</b>
<code>help</code> - Send this message
<code>original</code> [b] [id/md5] - Get original file of post
<code>post</code> [b] [id/md5] - Get information of post
<code>short</code> [query] - Create inline shortcut
-<code>donate</code> - Send donation details
+<<<<<<<<
+
+
+inline_examples::Inline Examples
+>>>>>>>>
+<b>Inline Examples</b>
+Several inline search and commands examples to let you get started
+
+<code>p d 1 -a rating:g</code>
+<code>t d *arknights*</code>
+<code>original d 4507929</code>
+<code>short p d -mq ringouulu</code>
+<<<<<<<<
+
+
+commands::Bot Commands
+>>>>>>>>
+<b>Bot Commands</b>
+In-chat bot commands
-<b>Commands:</b>
/help - Send this message
/authorize [b] [login] [key] - Authorize to Image Board
/original [b] [id/md5] - Get original file of post
@@ -45,23 +97,16 @@
/short [query] - Create inline shortcut
/shorts - Manage saved shortcuts
/ping - Measure bot latency
-/donate - Send donation details
/export - Export all your data
/stop - Remove all your data
+<<<<<<<<
-<b>Inline aliases:</b>
-<code>l</code> - <code>pools</code>
-<code>p</code> - <code>posts</code>
-<code>t</code> - <code>tags</code>
-<code>s</code> - <code>shorts</code>
-<b>Inline examples:</b>
-<code>p d 1 -a rating:g</code>
-<code>t d *genshin*</code>
-<code>original d 4507929</code>
-<code>short p d -mq ringouulu</code>
+sib::Supported Image Boards
+>>>>>>>>
+<b>Supported Image Boards</b>
+List of currently supported booru-like Image Boards
-<b>Supported Image Boards:</b>
<code>a</code> - <a href="https://safebooru.donmai.us/">Safebooru</a>
<code>d</code> - <a href="https://danbooru.donmai.us/">Danbooru</a>
<code>g</code> - <a href="https://gelbooru.com/">Gelbooru</a>
@@ -69,3 +114,16 @@
<code>k</code> - <a href="https://konachan.com/">Konachan.com</a>
<code>s</code> - <a href="https://www.sankakucomplex.com/">Sankaku Channel</a>
<code>y</code> - <a href="https://yande.re/">yande.re</a>
+<<<<<<<<
+
+
+donate::Donation Details
+>>>>>>>>
+<b>Donation Details</b>
+If you want to support this bot development you can donate any amount of these cryptocurrencies
+
+<b>BTC:</b> <code>bc1qqr8yryvx43y6p3kg7y2cw32w6tv748el7k38ff</code>
+<b>ETH:</b> <code>0x8993D744dF7183e112E2A4489991890f6a143104</code>
+<b>BNB:</b> <code>0x8993D744dF7183e112E2A4489991890f6a143104</code>
+<b>TON:</b> <code>UQBdoPQq3akozSLiWqt6x2Rizv0TrxHzRjczoztFN-LMCwGO</code>
+<<<<<<<<
diff --git a/handlers/callback.zsh b/handlers/callback.zsh
index 8c879fa..10a8250 100644
--- a/handlers/callback.zsh
+++ b/handlers/callback.zsh
@@ -22,6 +22,9 @@ case "${command}" in
("delete")
source "${operators}/callback_delete.zsh"
;;
+ ("help")
+ source "${operators}/callback_help.zsh"
+ ;;
("post")
source "${operators}/callback_post.zsh"
;;
diff --git a/handlers/commands.zsh b/handlers/commands.zsh
index bc88137..e72a54c 100644
--- a/handlers/commands.zsh
+++ b/handlers/commands.zsh
@@ -36,9 +36,6 @@ case "${command}" in
("/authorize" | "/authorize@${username}")
source "${operators}/command_authorize.zsh"
;;
- ("/donate" | "/donate@${username}")
- source "${operators}/command_donate.zsh"
- ;;
("/export" | "/export@${username}")
source "${operators}/command_export.zsh"
;;
diff --git a/handlers/inline.zsh b/handlers/inline.zsh
index 79bfaa7..2bb16e1 100644
--- a/handlers/inline.zsh
+++ b/handlers/inline.zsh
@@ -27,9 +27,6 @@ else
fi
case "${command}" in
- ("donate")
- source "${operators}/inline_donate.zsh"
- ;;
("help")
source "${operators}/inline_help.zsh"
;;
diff --git a/operators/callback_help.zsh b/operators/callback_help.zsh
new file mode 100644
index 0000000..e1a3cce
--- /dev/null
+++ b/operators/callback_help.zsh
@@ -0,0 +1,47 @@
+# Copyright (C) 2024-2026 Maria Lisina
+# Copyright (C) 2024-2026 Danil Lisin
+# SPDX-License-Identifier: Apache-2.0
+
+if [[ -n "${1}" ]]
+then
+ data_name="${1}"
+ check_table=(${help_table[@]})
+ shift
+fi
+
+while [[ ${#check_table} -ge 3 ]]
+do
+ if [[ "${data_name}" == "${check_table[1]}" ]]
+ then
+ break
+ elif [[ "${check_table[1]}" == "${check_table[-3]}" ]]
+ then
+ notification_text="No requested topic found"
+ return
+ fi
+
+ shift 3 check_table
+done
+
+link_preview_options="$(
+ jq --null-input --compact-output \
+ '{"is_disabled": true}'
+)"
+
+if [[ -n "${data_name}" ]]
+then
+ output_text="${check_table[3]}"
+
+ keyboard_text1="Back"
+ keyboard_data1="help"
+
+ reply_markup="$(
+ jq --null-input --compact-output \
+ --arg text1 "${keyboard_text1}" \
+ --arg data1 "${keyboard_data1}" \
+ '{"inline_keyboard": [[{"text": $text1, "callback_data": $data1}]]}'
+ )"
+else
+ output_text="${help_general}"
+ . "${units}/help.zsh"
+fi
diff --git a/operators/command_donate.zsh b/operators/command_donate.zsh
deleted file mode 100644
index fa7518c..0000000
--- a/operators/command_donate.zsh
+++ /dev/null
@@ -1,10 +0,0 @@
-# Copyright (C) 2024-2026 Maria Lisina
-# Copyright (C) 2024-2026 Danil Lisin
-# SPDX-License-Identifier: Apache-2.0
-
-if [[ -n "${nocommand_donate}" ]]
-then
- exit 0
-fi
-
-output_text="${donate_content}"
diff --git a/operators/command_help.zsh b/operators/command_help.zsh
index 2d86678..ec298bc 100644
--- a/operators/command_help.zsh
+++ b/operators/command_help.zsh
@@ -2,7 +2,8 @@
# Copyright (C) 2024-2026 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-output_text="${help_content}"
+output_text="${help_general}"
+. "${units}/help.zsh"
link_preview_options="$(
jq --null-input --compact-output \
diff --git a/operators/inline_donate.zsh b/operators/inline_donate.zsh
deleted file mode 100644
index a823311..0000000
--- a/operators/inline_donate.zsh
+++ /dev/null
@@ -1,22 +0,0 @@
-# Copyright (C) 2024-2026 Maria Lisina
-# Copyright (C) 2024-2026 Danil Lisin
-# SPDX-License-Identifier: Apache-2.0
-
-if [[ -n "${nocommand_donate}" ]]
-then
- source "${operators}/inline_help.zsh"
- return
-fi
-
-output_title="Donate"
-output_text="${donate_content}"
-output_description="Click to send details"
-
-results="$(
- jq --null-input --compact-output \
- --arg id "${query_id}" \
- --arg title "${output_title}" \
- --arg text "${output_text}" \
- --arg description "${output_description}" \
- '[{"type": "article", "id": $id, "title": $title, "input_message_content": {"message_text": $text, "parse_mode": "HTML"}, "description": $description}]'
-)"
diff --git a/operators/inline_help.zsh b/operators/inline_help.zsh
index 2ac9455..a115de4 100644
--- a/operators/inline_help.zsh
+++ b/operators/inline_help.zsh
@@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
output_title="Sekoohaka Bot"
-output_text="${help_content}"
+output_text="${help_general}"
output_description="Click to send help message"
results="$(
@@ -14,3 +14,15 @@ results="$(
--arg description "${output_description}" \
'[{"type": "article", "id": $id, "title": $title, "input_message_content": {"message_text": $text, "parse_mode": "HTML", "link_preview_options": {"is_disabled": true}}, "description": $description}]'
)"
+
+. "${units}/help.zsh"
+
+if [[ -n "${reply_markup}" ]]
+then
+ results="$(
+ jq --compact-output \
+ --argjson reply_markup "${reply_markup}" \
+ '.[0] += {"reply_markup": $reply_markup}' \
+ <<< "${results}"
+ )"
+fi
diff --git a/units/help.zsh b/units/help.zsh
new file mode 100644
index 0000000..4001020
--- /dev/null
+++ b/units/help.zsh
@@ -0,0 +1,21 @@
+# Copyright (C) 2024-2026 Maria Lisina
+# Copyright (C) 2024-2026 Danil Lisin
+# SPDX-License-Identifier: Apache-2.0
+
+while [[ ${#help_table} -ge 3 ]]
+do
+ keyboard_text1="${help_table[2]}"
+ keyboard_data1="help ${help_table[1]}"
+
+ reply_markup="$(
+ jq --compact-output \
+ --argjson offset "$(printf "%u" "${keyboard_offset}")" \
+ --arg text1 "${keyboard_text1}" \
+ --arg data1 "${keyboard_data1}" \
+ '.inline_keyboard[$offset] += [{"text": $text1, "callback_data": $data1}]' \
+ <<< "${reply_markup:-"{}"}"
+ )"
+
+ keyboard_offset=$((keyboard_offset + 0.5))
+ shift 3 help_table
+done