aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaria Lisina <sekoohaka.sarisan@gmail.com>2025-05-19 18:01:39 +0500
committerMaria Lisina <sekoohaka.sarisan@gmail.com>2025-05-19 18:01:39 +0500
commit03a7c5b049ff7ba50330c77452575133f84e386e (patch)
treef79ff366d099de59631e9936ee58f01a482f08e6
parent0ff0b7f0e6b99aedc52c031e476ec85cb6702c97 (diff)
bot: Begin porting to Z Shell
Signed-off-by: Maria Lisina <sekoohaka.sarisan@gmail.com>
-rw-r--r--README.md12
-rwxr-xr-xaliases.zsh (renamed from aliases.sh)22
-rwxr-xr-xblacklist.zsh (renamed from blacklist.sh)20
-rwxr-xr-xbot.zsh (renamed from bot.sh)121
-rw-r--r--modules/callback.zsh (renamed from modules/callback.sh)63
-rw-r--r--modules/commands.zsh (renamed from modules/commands.sh)61
-rw-r--r--modules/inline.zsh (renamed from modules/inline.sh)45
-rw-r--r--modules/uncache.zsh (renamed from modules/uncache.sh)4
-rw-r--r--modules/unlock.zsh (renamed from modules/unlock.sh)0
-rw-r--r--submodules/callback_delete.zsh (renamed from submodules/callback_delete.sh)16
-rw-r--r--submodules/callback_post.zsh (renamed from submodules/callback_post.sh)10
-rw-r--r--submodules/callback_reset.zsh (renamed from submodules/callback_reset.sh)0
-rw-r--r--submodules/callback_short.zsh (renamed from submodules/callback_short.sh)9
-rw-r--r--submodules/callback_stop.zsh (renamed from submodules/callback_stop.sh)0
-rw-r--r--submodules/callback_tags.zsh (renamed from submodules/callback_tags.sh)63
-rw-r--r--submodules/command_authorize.zsh (renamed from submodules/command_authorize.sh)16
-rw-r--r--submodules/command_donate.zsh (renamed from submodules/command_donate.sh)2
-rw-r--r--submodules/command_hash.zsh (renamed from submodules/command_hash.sh)18
-rw-r--r--submodules/command_help.zsh (renamed from submodules/command_help.sh)2
-rw-r--r--submodules/command_original.zsh (renamed from submodules/command_original.sh)46
-rw-r--r--submodules/command_ping.zsh (renamed from submodules/command_ping.sh)38
-rw-r--r--submodules/command_post.zsh (renamed from submodules/command_post.sh)12
-rw-r--r--submodules/command_prpr.zsh (renamed from submodules/command_prpr.sh)0
-rw-r--r--submodules/command_short.zsh (renamed from submodules/command_short.sh)6
-rw-r--r--submodules/command_shorts.zsh (renamed from submodules/command_shorts.sh)10
-rw-r--r--submodules/command_source.zsh (renamed from submodules/command_source.sh)36
-rw-r--r--submodules/command_stop.zsh (renamed from submodules/command_stop.sh)0
-rw-r--r--submodules/inline_donate.zsh (renamed from submodules/inline_donate.sh)4
-rw-r--r--submodules/inline_help.zsh (renamed from submodules/inline_help.sh)2
-rw-r--r--submodules/inline_none.zsh (renamed from submodules/inline_none.sh)10
-rw-r--r--submodules/inline_original.zsh (renamed from submodules/inline_original.sh)10
-rw-r--r--submodules/inline_post.zsh (renamed from submodules/inline_post.sh)10
-rw-r--r--submodules/inline_search.zsh (renamed from submodules/inline_search.sh)18
-rw-r--r--submodules/inline_search_pools.zsh (renamed from submodules/inline_search_pools.sh)12
-rw-r--r--submodules/inline_search_posts.zsh (renamed from submodules/inline_search_posts.sh)26
-rw-r--r--submodules/inline_search_tags.zsh (renamed from submodules/inline_search_tags.sh)6
-rw-r--r--submodules/inline_short.zsh (renamed from submodules/inline_short.sh)4
-rw-r--r--submodules/inline_shorts.zsh (renamed from submodules/inline_shorts.sh)18
-rw-r--r--submodules/url_parser.zsh (renamed from submodules/url_parser.sh)73
-rw-r--r--units/dump.zsh (renamed from units/dump.sh)6
-rw-r--r--units/help.zsh (renamed from units/help.sh)0
-rw-r--r--units/ib_auth.zsh (renamed from units/ib_auth.sh)50
-rw-r--r--units/ib_authconfig.zsh (renamed from units/ib_authconfig.sh)0
-rw-r--r--units/ib_cache.zsh (renamed from units/ib_cache.sh)2
-rw-r--r--units/ib_common.zsh (renamed from units/ib_common.sh)18
-rw-r--r--units/ib_config.zsh (renamed from units/ib_config.sh)74
-rw-r--r--units/ib_date.zsh (renamed from units/ib_date.sh)6
-rw-r--r--units/ib_file.zsh (renamed from units/ib_file.sh)30
-rw-r--r--units/ib_hash.zsh (renamed from units/ib_hash.sh)8
-rw-r--r--units/ib_lock.zsh (renamed from units/ib_lock.sh)2
-rw-r--r--units/ib_meta.zsh (renamed from units/ib_meta.sh)36
-rw-r--r--units/ib_name.zsh (renamed from units/ib_name.sh)12
-rw-r--r--units/ib_original.zsh (renamed from units/ib_original.sh)10
-rw-r--r--units/ib_post.zsh (renamed from units/ib_post.sh)45
-rw-r--r--units/ib_preview.zsh (renamed from units/ib_preview.sh)2
-rw-r--r--units/ib_sample.zsh (renamed from units/ib_sample.sh)2
-rw-r--r--units/ib_search.zsh (renamed from units/ib_search.sh)52
-rw-r--r--units/ib_size.zsh (renamed from units/ib_size.sh)4
-rw-r--r--units/ib_token.zsh (renamed from units/ib_token.sh)12
-rw-r--r--units/log.zsh (renamed from units/log.sh)2
-rw-r--r--units/shorts_search.sh110
-rw-r--r--units/shorts_search.zsh94
-rw-r--r--units/sn_auth.zsh (renamed from units/sn_auth.sh)18
-rw-r--r--units/sn_get.zsh (renamed from units/sn_get.sh)40
-rw-r--r--units/sn_search.zsh (renamed from units/sn_search.sh)14
-rw-r--r--units/user.sh27
-rw-r--r--units/user.zsh24
-rwxr-xr-xwhitelist.zsh (renamed from whitelist.sh)20
68 files changed, 739 insertions, 806 deletions
diff --git a/README.md b/README.md
index b7b7705..b596a86 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Sekoohaka
-Telegram Image Board Bot written in POSIX Shell (dash)
+Telegram Image Board Bot written in Z Shell (zsh)
## Features
@@ -28,9 +28,8 @@ Telegram Image Board Bot written in POSIX Shell (dash)
BusyBox is a hard-coded dependency and cannot be replaced with alternatives!
-* dash
+* zsh
* busybox
-* coreutils
* curl
* jq
* recode
@@ -40,7 +39,6 @@ For distribution specific installation commands follow [command-not-found](https
### BusyBox functions
* base64
-* bc
* cat
* cp
* cut
@@ -57,13 +55,9 @@ For distribution specific installation commands follow [command-not-found](https
* stat
* tr
-### GNU Core Utilities
-
-* date
-
## Deployment
-It is highly recommended to run it with an empty environment to avoid variable conflict: `env -i ./bot.sh` or `env -i PATH="${PATH}" ./bot.sh` for Termux.
+It is highly recommended to run it with an empty environment to avoid variable conflict: `env -i ./bot.zsh` or `env -i PATH="${PATH}" ./bot.zsh` for Termux.
For better performance, it is recommended to use a locally deployed [Telegram Bot API](https://github.com/tdlib/telegram-bot-api) server.
### Available options
diff --git a/aliases.sh b/aliases.zsh
index 786faf1..6cd2b43 100755
--- a/aliases.sh
+++ b/aliases.zsh
@@ -1,4 +1,4 @@
-#!/usr/bin/env dash
+#!/usr/bin/env zsh
#
# Copyright (C) 2024-2025 Maria Lisina
# Copyright (C) 2024-2025 Danil Lisin
@@ -14,7 +14,7 @@ dir="${0%/*}"
files="${dir}/files"
list="${files}/aliases.txt"
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
action="${1}"
@@ -36,7 +36,7 @@ else
help=0
fi
-if [ -n "${help}" ]
+if [[ -n "${help}" ]]
then
echo "Aliases Manager" \
"\n\nUsage: ${0} [action] [ID] [alias]" \
@@ -57,7 +57,7 @@ do
fi
done
-if [ -n "${missing}" ]
+if [[ -n "${missing}" ]]
then
echo "Missing dependencies:${missing}" \
"\nFor more information follow: https://command-not-found.com/"
@@ -66,7 +66,7 @@ fi
for function in cat grep mkdir sed
do
- if busybox ${function} --help
+ if busybox ${function} --help > /dev/null
then
alias ${function}="busybox ${function}"
else
@@ -74,7 +74,7 @@ do
fi
done
-if [ -n "${missing}" ]
+if [[ -n "${missing}" ]]
then
echo "Missing BusyBox functions:${missing}" \
"\nUpdate your BusyBox or get a version with all the required functions"
@@ -83,7 +83,7 @@ fi
case "${action}" in
(add | del)
- if [ -n "${1}" ]
+ if [[ -n "${1}" ]]
then
user_id="${1}"
@@ -104,13 +104,13 @@ esac
case "${action}" in
(show)
- if [ -s "${list}" ]
+ if [[ -s "${list}" ]]
then
cat "${list}"
fi
;;
(add)
- if [ -n "${1}" ]
+ if [[ -n "${1}" ]]
then
alias_name="${1}"
shift
@@ -120,7 +120,7 @@ case "${action}" in
exit 1
fi
- if [ -s "${list}" ] && alias="$(grep -xe "${user_id} .*" "${list}")"
+ if [[ -s "${list}" ]] && alias="$(grep -xe "${user_id} .*" "${list}")"
then
alias_name="$(printf "%s" "${alias}" | cut -d ' ' -f 2)"
@@ -131,7 +131,7 @@ case "${action}" in
printf "%s %s\n" "${user_id}" "${alias_name}" >> "${list}"
;;
(del)
- if [ -s "${list}" ]
+ if [[ -s "${list}" ]]
then
sed -e "s/^${user_id} .*$//" -e '/^$/d' -i "${list}"
fi
diff --git a/blacklist.sh b/blacklist.zsh
index 4b69985..6fc3129 100755
--- a/blacklist.sh
+++ b/blacklist.zsh
@@ -1,4 +1,4 @@
-#!/usr/bin/env dash
+#!/usr/bin/env zsh
#
# Copyright (C) 2024-2025 Maria Lisina
# Copyright (C) 2024-2025 Danil Lisin
@@ -14,7 +14,7 @@ dir="${0%/*}"
files="${dir}/files"
list="${files}/blacklist.txt"
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
action="${1}"
@@ -36,7 +36,7 @@ else
help=0
fi
-if [ -n "${help}" ]
+if [[ -n "${help}" ]]
then
echo "Blacklist Manager" \
"\n\nUsage: ${0} [action] [ID]" \
@@ -57,7 +57,7 @@ do
fi
done
-if [ -n "${missing}" ]
+if [[ -n "${missing}" ]]
then
echo "Missing dependencies:${missing}" \
"\nFor more information follow: https://command-not-found.com/"
@@ -66,7 +66,7 @@ fi
for function in cat grep mkdir sed
do
- if busybox ${function} --help
+ if busybox ${function} --help > /dev/null
then
alias ${function}="busybox ${function}"
else
@@ -74,7 +74,7 @@ do
fi
done
-if [ -n "${missing}" ]
+if [[ -n "${missing}" ]]
then
echo "Missing BusyBox functions:${missing}" \
"\nUpdate your BusyBox or get a version with all the required functions"
@@ -83,7 +83,7 @@ fi
case "${action}" in
(add | del)
- if [ -n "${1}" ]
+ if [[ -n "${1}" ]]
then
user_id="${1}"
@@ -104,13 +104,13 @@ esac
case "${action}" in
(show)
- if [ -s "${list}" ]
+ if [[ -s "${list}" ]]
then
cat "${list}"
fi
;;
(add)
- if [ -s "${list}" ] && grep -qxe "${user_id}" "${list}"
+ if [[ -s "${list}" ]] && grep -qxe "${user_id}" "${list}"
then
echo "User ID ${user_id} is already in the blacklist"
exit 1
@@ -119,7 +119,7 @@ case "${action}" in
printf "%s\n" "${user_id}" >> "${list}"
;;
(del)
- if [ -s "${list}" ]
+ if [[ -s "${list}" ]]
then
sed -e "s/^${user_id}$//" -e '/^$/d' -i "${list}"
fi
diff --git a/bot.sh b/bot.zsh
index 47b7a26..cca9d62 100755
--- a/bot.sh
+++ b/bot.zsh
@@ -1,4 +1,4 @@
-#!/usr/bin/env dash
+#!/usr/bin/env zsh
#
# Copyright (C) 2024-2025 Maria Lisina
# Copyright (C) 2024-2025 Danil Lisin
@@ -10,7 +10,12 @@ set -e
umask 77
exec 2> /dev/null
-version="3.0.2"
+if command -v git > /dev/null
+then
+ gitrev="$(git rev-parse --short HEAD)"
+fi
+
+version="4.0-${gitrev:-inadev}"
useragent="Sekoohaka/${version} Telegram Bot"
local_address="127.0.0.1:8081"
@@ -21,16 +26,16 @@ cache="${dir}/cache/${$}"
config="${dir}/config"
dumps="${dir}/dumps/${$}"
files="${dir}/files"
-modules="${dir}/modules"
-submodules="${dir}/submodules"
+mods="${dir}/modules"
+submods="${dir}/submodules"
units="${dir}/units"
offset=-1
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
- while getopts ha:lg:r:m:t:s:cjqui:e:d:n:x: options
+ while getopts ha:lg:r:m:t:s:cjqui:e:d:n:x: opts
do
- case "${options}" in
+ case "${opts}" in
(h)
help=0
;;
@@ -94,7 +99,7 @@ else
help=0
fi
-if [ -n "${help}" ]
+if [[ -n "${help}" ]]
then
echo "Sekoohaka Bot v${version}" \
"\n\nUsage: ${0} [options] [token]" \
@@ -131,7 +136,7 @@ then
exit 0
fi
-for required in busybox coreutils curl jq recode
+for required in busybox curl jq recode
do
if ! command -v ${required} > /dev/null
then
@@ -139,14 +144,14 @@ do
fi
done
-if [ -n "${missing}" ]
+if [[ -n "${missing}" ]]
then
echo "Missing dependencies:${missing}" \
"\nFor more information follow: https://command-not-found.com/"
exit 1
fi
-for function in base64 bc cat cp cut date find grep ls mkdir rm sed sort sha1sum sleep stat tr
+for function in base64 cat cp cut date find grep ls mkdir rm sed sort sha1sum sleep stat tr
do
if busybox ${function} --help > /dev/null
then
@@ -156,36 +161,34 @@ do
fi
done
-if [ -n "${missing}" ]
+if [[ -n "${missing}" ]]
then
echo "Missing BusyBox functions:${missing}" \
"\nUpdate your BusyBox or get a version with all the required functions"
exit 1
fi
-for function in date
+for module in zsh/datetime zsh/zutil
do
- if coreutils --coreutils-prog=${function} --help > /dev/null
+ if ! zmodload ${module}
then
- alias g${function}="coreutils --coreutils-prog=${function}"
- else
- missing="${missing} ${function}"
+ failed="${failed} ${module}"
fi
done
-if [ -n "${missing}" ]
+if [[ -n "${failed}" ]]
then
- echo "Missing GNU Core Utilities:${missing}" \
- "\nUpdate your GNU Core Utilities or get a version with all the required functions"
+ echo "Failed to load Z Shell modules:${failed}" \
+ "\nUpdate your Z Shell or get a version with all the required modules"
exit 1
fi
-if [ -z "${api_address}" ]
+if [[ -z "${api_address}" ]]
then
api_address="${default_address}"
fi
-if [ -n "${shorts_limit}" ]
+if [[ -n "${shorts_limit}" ]]
then
if ! test ${shorts_limit} -gt 0
then
@@ -194,7 +197,7 @@ then
exit 1
fi
- if [ ${shorts_limit} -gt 10000 ]
+ if [[ ${shorts_limit} -gt 10000 ]]
then
shorts_limit=10000
fi
@@ -202,7 +205,7 @@ else
shorts_limit=100
fi
-if [ -n "${inline_limit}" ]
+if [[ -n "${inline_limit}" ]]
then
if ! test ${inline_limit} -gt 0
then
@@ -211,7 +214,7 @@ then
exit 1
fi
- if [ ${inline_limit} -gt 50 ]
+ if [[ ${inline_limit} -gt 50 ]]
then
inline_limit=50
fi
@@ -219,7 +222,7 @@ else
inline_limit=10
fi
-if [ -n "${caching_mode}" ]
+if [[ -n "${caching_mode}" ]]
then
case "${caching_mode}" in
(none | normal | advanced)
@@ -234,7 +237,7 @@ else
caching_mode=normal
fi
-if [ -n "${caching_time}" ]
+if [[ -n "${caching_time}" ]]
then
if ! test ${caching_time} -gt 0
then
@@ -243,7 +246,7 @@ then
exit 1
fi
- if [ ${caching_time} -gt 1000 ]
+ if [[ ${caching_time} -gt 1000 ]]
then
caching_time=1000
fi
@@ -251,7 +254,7 @@ else
caching_time=300
fi
-if [ -n "${sleeping_time}" ]
+if [[ -n "${sleeping_time}" ]]
then
if ! test ${sleeping_time} -gt 0
then
@@ -260,7 +263,7 @@ then
exit 1
fi
- if [ ${sleeping_time} -gt 100 ]
+ if [[ ${sleeping_time} -gt 100 ]]
then
sleeping_time=100
fi
@@ -268,7 +271,7 @@ else
sleeping_time=10
fi
-if [ -n "${internal_timeout}" ]
+if [[ -n "${internal_timeout}" ]]
then
if ! test ${internal_timeout} -gt 0
then
@@ -277,7 +280,7 @@ then
exit 1
fi
- if [ ${internal_timeout} -gt 10 ]
+ if [[ ${internal_timeout} -gt 10 ]]
then
internal_timeout=10
fi
@@ -285,7 +288,7 @@ else
internal_timeout=10
fi
-if [ -n "${external_timeout}" ]
+if [[ -n "${external_timeout}" ]]
then
if ! test ${external_timeout} -gt 0
then
@@ -294,7 +297,7 @@ then
exit 1
fi
- if [ ${external_timeout} -gt 10 ]
+ if [[ ${external_timeout} -gt 10 ]]
then
external_timeout=10
fi
@@ -302,7 +305,7 @@ else
external_timeout=5
fi
-if [ -n "${head_timeout}" ]
+if [[ -n "${head_timeout}" ]]
then
if ! test ${head_timeout} -gt 0
then
@@ -311,7 +314,7 @@ then
exit 1
fi
- if [ ${head_timeout} -gt 10 ]
+ if [[ ${head_timeout} -gt 10 ]]
then
head_timeout=10
fi
@@ -319,20 +322,20 @@ else
head_timeout=2
fi
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
api_token="${1}"
shift
fi
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
echo "Unrecognized action ${1}" \
"\nSee '${0} -h'"
exit 1
fi
-until [ -n "${api_token}" ]
+until [[ -n "${api_token}" ]]
do
read -p "Telegram Bot API Token: " -r api_token
done
@@ -348,15 +351,15 @@ mkdir -p "${config}"
for file in aliases blacklist donate help whitelist
do
- if [ -f "${files}/${file}.txt" ]
+ if [[ -f "${files}/${file}.txt" ]]
then
file_ctime=$(stat -c %Y "${files}/${file}.txt.default")
file_mtime=$(stat -c %Y "${files}/${file}.txt")
- if [ ${file_ctime} -gt ${file_mtime} ]
+ if [[ ${file_ctime} -gt ${file_mtime} ]]
then
log_text="Warning: ${file}.txt is older than ${file}.txt.default"
- . "${units}/log.sh"
+ . "${units}/log.zsh"
fi
else
cat "${files}/${file}.txt.default" > "${files}/${file}.txt"
@@ -364,7 +367,7 @@ do
done
log_text="PID: ${$}"
-. "${units}/log.sh"
+. "${units}/log.zsh"
if ! curl --get \
--max-time ${internal_timeout} \
@@ -376,7 +379,7 @@ if ! curl --get \
"${api_address}/bot${api_token}/getMe"
then
log_text="getMe: Failed to access Telegram Bot API"
- . "${units}/log.sh"
+ . "${units}/log.zsh"
exit 1
fi
@@ -384,38 +387,38 @@ fi
if ! jq -e '.' "${cache}/getMe.json" > /dev/null
then
log_text="getMe: An unknown error occurred"
- . "${units}/log.sh"
+ . "${units}/log.zsh"
exit 1
fi
-if [ "$(jq -r '.ok' "${cache}/getMe.json")" != "true" ]
+if [[ "$(jq -r '.ok' "${cache}/getMe.json")" != "true" ]]
then
error_description="$(jq -r '.description' "${cache}/getMe.json")"
- if [ "${error_description}" != "null" ]
+ if [[ "${error_description}" != "null" ]]
then
log_text="getMe: ${error_description}"
else
log_text="getMe: An unknown error occurred"
fi
- . "${units}/log.sh"
+ . "${units}/log.zsh"
exit 1
fi
username="$(jq -r '.result.username' "${cache}/getMe.json")"
-if [ "${username}" = "null" ]
+if [[ "${username}" = "null" ]]
then
log_text="Failed to get bot username"
- . "${units}/log.sh"
+ . "${units}/log.zsh"
exit 1
fi
log_text="Bot: ${username}"
-. "${units}/log.sh"
+. "${units}/log.zsh"
while trap 'wait && exit 0' INT TERM
do
@@ -428,7 +431,7 @@ do
"${api_address}/bot${api_token}/getUpdates"
then
log_text="getUpdates: Failed to access Telegram Bot API, sleeping for ${sleeping_time} seconds"
- . "${units}/log.sh"
+ . "${units}/log.zsh"
sleep ${sleeping_time}
continue
@@ -437,24 +440,24 @@ do
if ! jq -e '.' "${cache}/getUpdates.json" > /dev/null
then
log_text="getUpdates: An unknown error occurred, sleeping for ${sleeping_time} seconds"
- . "${units}/log.sh"
+ . "${units}/log.zsh"
sleep ${sleeping_time}
continue
fi
- if [ "$(jq -r '.ok' "${cache}/getUpdates.json")" != "true" ]
+ if [[ "$(jq -r '.ok' "${cache}/getUpdates.json")" != "true" ]]
then
error_description="$(jq -r '.description' "${cache}/getUpdates.json")"
- if [ "${error_description}" != "null" ]
+ if [[ "${error_description}" != "null" ]]
then
log_text="getUpdates: ${error_description}, sleeping for ${sleeping_time} seconds"
else
log_text="getUpdates: An unknown error occurred, sleeping for ${sleeping_time} seconds"
fi
- . "${units}/log.sh"
+ . "${units}/log.zsh"
sleep ${sleeping_time}
continue
@@ -462,7 +465,7 @@ do
update_id="$(jq -r '.result.[0].update_id' "${cache}/getUpdates.json")"
- if [ "${update_id}" = "null" ]
+ if [[ "${update_id}" = "null" ]]
then
continue
fi
@@ -474,11 +477,11 @@ do
then
log_text="Failed to write update file ${update_id}.json"
- . "${units}/log.sh"
+ . "${units}/log.zsh"
continue
fi
- for module in "${modules}"/*
+ for module in "${mods}"/*
do
. "${module}" &
done
diff --git a/modules/callback.sh b/modules/callback.zsh
index b5ce241..39bde44 100644
--- a/modules/callback.sh
+++ b/modules/callback.zsh
@@ -2,52 +2,53 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-set -- $(jq -r '.callback_query.data' "${update}")
+callback_query=($(jq -r '.callback_query.data' "${update}"))
-if [ "${1}" = "null" ]
+if [[ "${callback_query}" = "null" ]]
then
exit 0
fi
-command="${1}"
-shift
-
user_id="$(jq -r '.callback_query.from.id' "${update}")"
query_id="$(jq -r '.callback_query.id' "${update}")"
-. "${units}/user.sh"
+. "${units}/user.zsh"
+set -- ${callback_query[@]}
+
+command="${1}"
+shift
case "${command}" in
("delete")
- . "${submodules}/callback_delete.sh"
+ . "${submods}/callback_delete.zsh"
;;
("post")
- . "${submodules}/callback_post.sh"
+ . "${submods}/callback_post.zsh"
;;
("reset")
- . "${submodules}/callback_reset.sh"
+ . "${submods}/callback_reset.zsh"
;;
("short")
- . "${submodules}/callback_short.sh"
+ . "${submods}/callback_short.zsh"
;;
("stop")
- . "${submodules}/callback_stop.sh"
+ . "${submods}/callback_stop.zsh"
;;
("tags")
- . "${submodules}/callback_tags.sh"
+ . "${submods}/callback_tags.zsh"
;;
(*)
exit 0
;;
esac
-if [ -z "${notification_text}" ] && [ -n "${output_text}" ]
+if [[ -z "${notification_text}" && -n "${output_text}" ]]
then
chat_id="$(jq -r '.callback_query.message.chat.id' "${update}")"
message_id="$(jq -r '.callback_query.message.message_id' "${update}")"
inline_message_id="$(jq -r '.callback_query.inline_message_id' "${update}")"
- if [ "${inline_message_id}" != "null" ]
+ if [[ "${inline_message_id}" != "null" ]]
then
unset chat_id
unset message_id
@@ -74,33 +75,33 @@ then
notification_text="Failed to update message"
log_text="editMessageText (${update_id}): Failed to access Telegram Bot API"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
fi
- if [ -z "${notification_text}" ] && ! jq -e '.' "${output_file}" > /dev/null
+ if [[ -z "${notification_text}" ]] && ! jq -e '.' "${output_file}" > /dev/null
then
notification_text="An unknown error occurred"
log_text="editMessageText (${update_id}): An unknown error occurred"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
fi
- if [ -z "${notification_text}" ] && [ "$(jq -r '.ok' "${output_file}")" != "true" ]
+ if [[ -z "${notification_text}" && "$(jq -r '.ok' "${output_file}")" != "true" ]]
then
notification_text="Failed to update message"
error_description="$(jq -r '.description' "${output_file}")"
- if [ "${error_description}" != "null" ]
+ if [[ "${error_description}" != "null" ]]
then
log_text="editMessageText (${update_id}): ${error_description}"
else
log_text="editMessageText (${update_id}): An unknown error occurred"
fi
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
fi
fi
@@ -120,8 +121,8 @@ if ! curl --data-urlencode "callback_query_id=${query_id}" \
then
log_text="answerCallbackQuery (${update_id}): Failed to access Telegram Bot API"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
exit 0
fi
@@ -130,23 +131,23 @@ if ! jq -e '.' "${output_file}" > /dev/null
then
log_text="answerCallbackQuery (${update_id}): An unknown error occurred"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
exit 0
fi
-if [ "$(jq -r '.ok' "${output_file}")" != "true" ]
+if [[ "$(jq -r '.ok' "${output_file}")" != "true" ]]
then
error_description="$(jq -r '.description' "${output_file}")"
- if [ "${error_description}" != "null" ]
+ if [[ "${error_description}" != "null" ]]
then
log_text="answerCallbackQuery (${update_id}): ${error_description}"
else
log_text="answerCallbackQuery (${update_id}): An unknown error occurred"
fi
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
fi
diff --git a/modules/commands.sh b/modules/commands.zsh
index 82bd66c..3d8cc54 100644
--- a/modules/commands.sh
+++ b/modules/commands.zsh
@@ -2,75 +2,76 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-set -- $(jq -r '.message.text' "${update}")
+command_query=($(jq -r '.message.text' "${update}"))
-if [ "${1}" = "null" ]
+if [[ "${command_query}" = "null" ]]
then
exit 0
fi
-command="${1}"
-shift
-
user_id="$(jq -r '.message.from.id' "${update}")"
chat_id="$(jq -r '.message.chat.id' "${update}")"
message_id="$(jq -r '.message.message_id' "${update}")"
is_topic="$(jq -r '.message.is_topic_message' "${update}")"
message_thread_id="$(jq -r '.message.message_thread_id' "${update}")"
-. "${units}/user.sh"
-
reply_parameters="$(jq --null-input --compact-output \
--arg message_id "${message_id}" \
'{"message_id": $message_id, "allow_sending_without_reply": true}')"
-if [ "${is_topic}" = "null" ]
+. "${units}/user.zsh"
+set -- ${command_query[@]}
+
+command="${1}"
+shift
+
+if [[ "${is_topic}" = "null" ]]
then
unset message_thread_id
fi
case "${command}" in
("/authorize" | "/authorize@${username}")
- . "${submodules}/command_authorize.sh"
+ . "${submods}/command_authorize.zsh"
;;
("/donate" | "/donate@${username}")
- . "${submodules}/command_donate.sh"
+ . "${submods}/command_donate.zsh"
;;
("/hash" | "/hash@${username}")
- . "${submodules}/command_hash.sh"
+ . "${submods}/command_hash.zsh"
;;
("/help" | "/help@${username}")
- . "${submodules}/command_help.sh"
+ . "${submods}/command_help.zsh"
;;
("/original" | "/original@${username}")
- . "${submodules}/command_original.sh"
+ . "${submods}/command_original.zsh"
;;
("/ping" | "/ping@${username}")
- . "${submodules}/command_ping.sh"
+ . "${submods}/command_ping.zsh"
;;
("/post" | "/post@${username}")
- . "${submodules}/command_post.sh"
+ . "${submods}/command_post.zsh"
;;
("/prpr" | "/prpr@${username}")
- . "${submodules}/command_prpr.sh"
+ . "${submods}/command_prpr.zsh"
;;
("/short" | "/short@${username}")
- . "${submodules}/command_short.sh"
+ . "${submods}/command_short.zsh"
;;
("/shorts" | "/shorts@${username}")
- . "${submodules}/command_shorts.sh"
+ . "${submods}/command_shorts.zsh"
;;
("/source" | "/source@${username}")
- . "${submodules}/command_source.sh"
+ . "${submods}/command_source.zsh"
;;
("/start" | "/start@${username}")
- . "${submodules}/command_help.sh"
+ . "${submods}/command_help.zsh"
;;
("/stop" | "/stop@${username}")
- . "${submodules}/command_stop.sh"
+ . "${submods}/command_stop.zsh"
;;
(*)
- . "${submodules}/url_parser.sh"
+ . "${submods}/url_parser.zsh"
;;
esac
@@ -94,8 +95,8 @@ if ! curl --data-urlencode "chat_id=${chat_id}" \
then
log_text="sendMessage (${update_id}): Failed to access Telegram Bot API"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
exit 0
fi
@@ -104,23 +105,23 @@ if ! jq -e '.' "${output_file}" > /dev/null
then
log_text="sendMessage (${update_id}): An unknown error occurred"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
exit 0
fi
-if [ "$(jq -r '.ok' "${output_file}")" != "true" ]
+if [[ "$(jq -r '.ok' "${output_file}")" != "true" ]]
then
error_description="$(jq -r '.description' "${output_file}")"
- if [ "${error_description}" != "null" ]
+ if [[ "${error_description}" != "null" ]]
then
log_text="sendMessage (${update_id}): ${error_description}"
else
log_text="sendMessage (${update_id}): An unknown error occurred"
fi
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
fi
diff --git a/modules/inline.sh b/modules/inline.zsh
index 1dca16c..56c51e2 100644
--- a/modules/inline.sh
+++ b/modules/inline.zsh
@@ -2,50 +2,51 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-set -- $(jq -r '.inline_query.query' "${update}")
+inline_query=($(jq -r '.inline_query.query' "${update}"))
-if [ "${1}" = "null" ]
+if [[ "${inline_query}" = "null" ]]
then
exit 0
fi
-command="${1}"
-
user_id="$(jq -r '.inline_query.from.id' "${update}")"
query_id="$(jq -r '.inline_query.id' "${update}")"
chat_type="$(jq -r '.inline_query.chat_type' "${update}")"
offset="$(jq -r '.inline_query.offset' "${update}")"
-. "${units}/user.sh"
+. "${units}/user.zsh"
+set -- ${inline_query[@]}
+
+command="${1}"
-if [ -n "${command}" ]
+if [[ -n "${command}" ]]
then
shift
else
- . "${submodules}/inline_none.sh"
+ . "${submods}/inline_none.zsh"
fi
case "${command}" in
("donate")
- . "${submodules}/inline_donate.sh"
+ . "${submods}/inline_donate.zsh"
;;
("help")
- . "${submodules}/inline_help.sh"
+ . "${submods}/inline_help.zsh"
;;
("original")
- . "${submodules}/inline_original.sh"
+ . "${submods}/inline_original.zsh"
;;
("post")
- . "${submodules}/inline_post.sh"
+ . "${submods}/inline_post.zsh"
;;
("short")
- . "${submodules}/inline_short.sh"
+ . "${submods}/inline_short.zsh"
;;
("shorts" | s)
- . "${submodules}/inline_shorts.sh"
+ . "${submods}/inline_shorts.zsh"
;;
(*)
- . "${submodules}/inline_search.sh"
+ . "${submods}/inline_search.zsh"
;;
esac
@@ -66,8 +67,8 @@ if ! curl --data-urlencode "inline_query_id=${query_id}" \
then
log_text="answerInlineQuery (${update_id}): Failed to access Telegram Bot API"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
exit 0
fi
@@ -76,23 +77,23 @@ if ! jq -e '.' "${output_file}" > /dev/null
then
log_text="answerInlineQuery (${update_id}): An unknown error occurred"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
exit 0
fi
-if [ "$(jq -r '.ok' "${output_file}")" != "true" ]
+if [[ "$(jq -r '.ok' "${output_file}")" != "true" ]]
then
error_description="$(jq -r '.description' "${output_file}")"
- if [ "${error_description}" != "null" ]
+ if [[ "${error_description}" != "null" ]]
then
log_text="answerInlineQuery (${update_id}): ${error_description}"
else
log_text="answerInlineQuery (${update_id}): An unknown error occurred"
fi
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
fi
diff --git a/modules/uncache.sh b/modules/uncache.zsh
index b02c120..0e6df74 100644
--- a/modules/uncache.sh
+++ b/modules/uncache.zsh
@@ -2,7 +2,7 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ -z "${clear_cache}" ]
+if [[ -z "${clear_cache}" ]]
then
exit 0
fi
@@ -22,7 +22,7 @@ do
cache_ctime=$(date +%s)
cache_mtime=$(stat -c %Y "${cache}/${file}")
- if [ $((cache_ctime - cache_mtime)) -gt $((caching_time + 15)) ]
+ if [[ $((cache_ctime - cache_mtime)) -gt $((caching_time + 15)) ]]
then
rm -f "${cache}/${file}"
fi
diff --git a/modules/unlock.sh b/modules/unlock.zsh
index 99a4bb2..99a4bb2 100644
--- a/modules/unlock.sh
+++ b/modules/unlock.zsh
diff --git a/submodules/callback_delete.sh b/submodules/callback_delete.zsh
index 0b0fe02..91867a9 100644
--- a/submodules/callback_delete.sh
+++ b/submodules/callback_delete.zsh
@@ -21,8 +21,8 @@ then
notification_text="Failed to delete message"
log_text="deleteMessage (${update_id}): Failed to access Telegram Bot API"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
@@ -32,24 +32,24 @@ then
notification_text="An unknown error occurred"
log_text="deleteMessage (${update_id}): An unknown error occurred"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
-if [ "$(jq -r '.ok' "${output_file}")" != "true" ]
+if [[ "$(jq -r '.ok' "${output_file}")" != "true" ]]
then
notification_text="Failed to delete message"
error_description="$(jq -r '.description' "${output_file}")"
- if [ "${error_description}" != "null" ]
+ if [[ "${error_description}" != "null" ]]
then
log_text="deleteMessage (${update_id}): ${error_description}"
else
log_text="deleteMessage (${update_id}): An unknown error occurred"
fi
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
fi
diff --git a/submodules/callback_post.sh b/submodules/callback_post.zsh
index 28004ad..78708f4 100644
--- a/submodules/callback_post.sh
+++ b/submodules/callback_post.zsh
@@ -3,14 +3,14 @@
# SPDX-License-Identifier: Apache-2.0
ib_lock=0
-. "${units}/ib_common.sh"
+. "${units}/ib_common.zsh"
-if [ -n "${notification_text}" ]
+if [[ -n "${notification_text}" ]]
then
return 0
fi
-. "${units}/ib_post.sh"
+. "${units}/ib_post.zsh"
link_preview_options="$(jq --null-input --compact-output \
--arg url "${ib_sample_url}" \
@@ -24,9 +24,9 @@ reply_markup="$(jq --null-input --compact-output \
--arg url1 "${keyboard_url1}" \
'{"inline_keyboard": [[{"text": $text1, "url": $url1}]]}')"
-if [ ${ib_tags_count} -gt 0 ]
+if [[ ${#ib_tags} -gt 0 ]]
then
- keyboard_text1="Tags (${ib_tags_count})"
+ keyboard_text1="Tags (${#ib_tags})"
keyboard_data1="tags ${ib_board} ${ib_post_id}"
reply_markup="$(printf "%s" "${reply_markup}" | jq --compact-output \
diff --git a/submodules/callback_reset.sh b/submodules/callback_reset.zsh
index 6d1194e..6d1194e 100644
--- a/submodules/callback_reset.sh
+++ b/submodules/callback_reset.zsh
diff --git a/submodules/callback_short.sh b/submodules/callback_short.zsh
index a7c8ace..12b46d0 100644
--- a/submodules/callback_short.sh
+++ b/submodules/callback_short.zsh
@@ -7,7 +7,7 @@ do
sleep 1
done
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
short_query="${@}"
shift ${#}
@@ -30,14 +30,13 @@ fi
short_hash="$(printf "%s" "${short_query}" | enhash)"
short="${short_config}/${short_hash}"
+shorts=($(ls -x "${short_config}"))
-set -- $(ls -x "${short_config}")
-
-if [ -f "${short}" ]
+if [[ -f "${short}" ]]
then
rm -f "${short}"
notification_text="Removed shortcut"
-elif [ ${#} -le ${shorts_limit} ]
+elif [[ ${#shorts} -le ${shorts_limit} ]]
then
printf "%s" "${short_query}" > "${short}"
notification_text="Saved shortcut"
diff --git a/submodules/callback_stop.sh b/submodules/callback_stop.zsh
index dc3e9c5..dc3e9c5 100644
--- a/submodules/callback_stop.sh
+++ b/submodules/callback_stop.zsh
diff --git a/submodules/callback_tags.sh b/submodules/callback_tags.zsh
index ae9c6e9..f7f24c3 100644
--- a/submodules/callback_tags.sh
+++ b/submodules/callback_tags.zsh
@@ -3,9 +3,9 @@
# SPDX-License-Identifier: Apache-2.0
ib_lock=0
-. "${units}/ib_common.sh"
+. "${units}/ib_common.zsh"
-if [ -n "${notification_text}" ]
+if [[ -n "${notification_text}" ]]
then
return 0
fi
@@ -13,60 +13,44 @@ fi
ib_created_at="$(jq -r ".${ib_iarray}[${array_count}].${ib_icreated}" "${ib_file}")"
ib_file_size="$(jq -r ".${ib_iarray}[0].${ib_isize}" "${ib_file}")"
ib_file_url="$(jq -r ".${ib_iarray}[0].${ib_ifile}" "${ib_file}")"
-ib_tags="$(jq -r ".${ib_iarray}[0].${ib_itags}" "${ib_file}" | htmlescape)"
+ib_tags=($(jq -r ".${ib_iarray}[0].${ib_itags}" "${ib_file}" | htmlescape))
+ib_groups_offset=${1:-0}
ib_tags_offset=${1:-0}
-ib_tags_total=0
ib_tags_count=0
-. "${units}/ib_size.sh"
-. "${units}/ib_meta.sh"
+. "${units}/ib_size.zsh"
+. "${units}/ib_meta.zsh"
-if [ -n "${ib_tags}" ] && [ "${ib_tags}" != "null" ]
+if [[ -z "${ib_tags}" || "${ib_tags}" = "null" ]]
then
- set -- ${ib_tags}
- ib_tags_total=${#}
-else
notification_text="Failed to get tags"
return 0
fi
-set -- ${ib_groups}
-ib_groups_offset=${ib_tags_offset}
-
-while [ ${#} -ge 2 ]
+while [[ ${#ib_groups} -ge 2 ]]
do
- ib_group_tags="$(jq -r ".${ib_iarray}[0].${1}" "${ib_file}" | htmlescape)"
- ib_group_name="${2}"
- ib_groups_saved="${@}"
+ ib_group_tags=($(jq -r ".${ib_iarray}[0].${ib_groups[1]}" "${ib_file}" | htmlescape))
+ ib_group_name="${ib_groups[2]}"
- if [ -n "${ib_group_tags}" ] && [ "${ib_group_tags}" != "null" ]
+ if [[ -n "${ib_group_tags}" && "${ib_group_tags}" != "null" ]]
then
- set -- ${ib_group_tags}
- ib_group_count=${#}
-
- if [ ${ib_group_count} -gt ${ib_groups_offset} ]
+ if [[ ${#ib_group_tags} -gt ${ib_groups_offset} ]]
then
- shift ${ib_groups_offset}
+ ib_group_tags=(${ib_group_tags[@]:${ib_groups_offset}})
ib_groups_offset=0
else
- ib_groups_offset=$((ib_groups_offset - ib_group_count))
-
- set -- ${ib_groups_saved}
- shift 2
-
+ ib_groups_offset=$((ib_groups_offset - $#ib_group_tags))
+ ib_groups=(${ib_groups[@]:2})
continue
fi
ib_group_text="$(printf "%s\n<b>%s:</b>" "${output_text}" "${ib_group_name}")"
- while [ ${#} -gt 0 ]
+ while [[ ${#ib_group_tags} -gt 0 ]]
do
- ib_tag="<code>${1}</code>"
-
- ib_tags_length=${#ib_group_text}
- ib_tag_length=${#ib_tag}
+ ib_tag="<code>${ib_group_tags[1]}</code>"
- if [ $((ib_tags_length + ib_tag_length)) -gt 2048 ]
+ if [[ $(($#ib_group_text + $#ib_tag)) -gt 2048 ]]
then
break 2
fi
@@ -75,15 +59,14 @@ do
ib_tags_count=$((ib_tags_count + 1))
output_text="${ib_group_text}"
- shift
+ ib_group_tags=(${ib_group_tags[@]:1})
done
fi
- set -- ${ib_groups_saved}
- shift 2
+ ib_groups=(${ib_groups[@]:2})
done
-if [ -z "${output_text}" ]
+if [[ -z "${output_text}" ]]
then
notification_text="No tags found"
return 0
@@ -101,7 +84,7 @@ reply_markup="$(jq --null-input --compact-output \
--arg data1 "${keyboard_data1}" \
'{"inline_keyboard": [[{"text": $text1, "callback_data": $data1}]]}')"
-if [ ${ib_tags_offset} -gt 0 ]
+if [[ ${ib_tags_offset} -gt 0 ]]
then
keyboard_text1="Over"
keyboard_data1="tags ${ib_board} ${ib_post_id}"
@@ -112,7 +95,7 @@ then
'.inline_keyboard.[0] += [{"text": $text1, "callback_data": $data1}]')"
fi
-if [ $((ib_tags_total - ib_tags_offset - ib_tags_count)) -gt 0 ]
+if [[ $(($#ib_tags - ib_tags_offset - ib_tags_count)) -gt 0 ]]
then
keyboard_text1="Next"
keyboard_data1="tags ${ib_board} ${ib_post_id} $((ib_tags_offset + ib_tags_count))"
diff --git a/submodules/command_authorize.sh b/submodules/command_authorize.zsh
index 726b3ea..8790904 100644
--- a/submodules/command_authorize.sh
+++ b/submodules/command_authorize.zsh
@@ -2,12 +2,12 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
ib_board="${1}"
- . "${units}/ib_authconfig.sh"
+ . "${units}/ib_authconfig.zsh"
- if [ -z "${ib_config}" ]
+ if [[ -z "${ib_config}" ]]
then
output_text="Unsupported image board"
return 0
@@ -19,23 +19,23 @@ else
return 0
fi
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
ib_login="${1}"
shift
fi
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
ib_key="${1}"
shift
fi
-. "${units}/ib_lock.sh"
+. "${units}/ib_lock.zsh"
-if [ -z "${output_text}" ]
+if [[ -z "${output_text}" ]]
then
- if [ -n "${ib_noauth}" ]
+ if [[ -n "${ib_noauth}" ]]
then
output_text="Authorization cannot be verified, make sure you provided the correct credentials"
else
diff --git a/submodules/command_donate.sh b/submodules/command_donate.zsh
index 75af973..4bdc9d9 100644
--- a/submodules/command_donate.sh
+++ b/submodules/command_donate.zsh
@@ -2,7 +2,7 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if ! [ -s "${files}/donate.txt" ]
+if ! [[ -s "${files}/donate.txt" ]]
then
exit 0
fi
diff --git a/submodules/command_hash.sh b/submodules/command_hash.zsh
index db4135f..66a13c1 100644
--- a/submodules/command_hash.sh
+++ b/submodules/command_hash.zsh
@@ -4,18 +4,18 @@
board_table="a d g i k s y"
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
- ib_post_md5="${@}"
- shift ${#}
+ ib_post_md5="${1}"
+ shift
else
- output_text="You must specify the MD5 hash"
+ output_text="You must specify the MD5 h.zsh"
return 0
fi
-if ! [ ${#ib_post_md5} -eq 32 ]
+if ! [[ ${#ib_post_md5} -eq 32 ]]
then
- output_text="Invalid MD5 hash"
+ output_text="Invalid MD5 h.zsh"
return 0
fi
@@ -30,18 +30,18 @@ for ib_board in ${board_table}
do
. "${units}/ib_hash.sh" &
- if [ -z "${threaded_hash}" ]
+ if [[ -z "${threaded_hash}" ]]
then
wait
fi
done
-if [ -n "${threaded_hash}" ]
+if [[ -n "${threaded_hash}" ]]
then
wait
fi
-if [ -s "${ib_posts}" ]
+if [[ -s "${ib_posts}" ]]
then
output_text="$(cat "${ib_posts}" | sort)"
else
diff --git a/submodules/command_help.sh b/submodules/command_help.zsh
index 25685e5..29ee848 100644
--- a/submodules/command_help.sh
+++ b/submodules/command_help.zsh
@@ -2,7 +2,7 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-. "${units}/help.sh"
+. "${units}/help.zsh"
link_preview_options="$(jq --null-input --compact-output \
'{"is_disabled": true}')"
diff --git a/submodules/command_original.sh b/submodules/command_original.zsh
index e432b3f..4eec34b 100644
--- a/submodules/command_original.sh
+++ b/submodules/command_original.zsh
@@ -2,17 +2,17 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-. "${units}/ib_name.sh"
-. "${units}/ib_common.sh"
+. "${units}/ib_name.zsh"
+. "${units}/ib_common.zsh"
-if [ -n "${output_text}" ]
+if [[ -n "${output_text}" ]]
then
return 0
fi
-. "${units}/ib_original.sh"
+. "${units}/ib_original.zsh"
-if [ -n "${ib_file_url}" ] && [ "${ib_file_url}" != "null" ]
+if [[ -n "${ib_file_url}" && "${ib_file_url}" != "null" ]]
then
keyboard_text1="Original file link"
keyboard_url1="${ib_file_url}"
@@ -23,7 +23,7 @@ then
'{"inline_keyboard": [[{"text": $text1, "url": $url1}]]}')"
fi
-if [ -n "${output_text}" ]
+if [[ -n "${output_text}" ]]
then
return 0
fi
@@ -44,31 +44,31 @@ if ! curl --data-urlencode "chat_id=${chat_id}" \
then
log_text="sendChatAction (${update_id}): Failed to access Telegram Bot API"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
fi
-if [ -z "${log_text}" ] && ! jq -e '.' "${output_file}" > /dev/null
+if [[ -z "${log_text}" ]] && ! jq -e '.' "${output_file}" > /dev/null
then
log_text="sendChatAction (${update_id}): An unknown error occurred"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
fi
-if [ -z "${log_text}" ] && [ "$(jq -r '.ok' "${output_file}")" != "true" ]
+if [[ -z "${log_text}" && "$(jq -r '.ok' "${output_file}")" != "true" ]]
then
error_description="$(jq -r '.description' "${output_file}")"
- if [ "${error_description}" != "null" ]
+ if [[ "${error_description}" != "null" ]]
then
log_text="sendChatAction (${update_id}): ${error_description}"
else
log_text="sendChatAction (${update_id}): An unknown error occurred"
fi
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
fi
output_file="${cache}/${update_id}_sendDocument.json"
@@ -91,8 +91,8 @@ then
output_text="Failed to send the original file"
log_text="sendDocument (${update_id}): Failed to access Telegram Bot API"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
@@ -102,26 +102,26 @@ then
output_text="An unknown error occurred"
log_text="sendDocument (${update_id}): An unknown error occurred"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
-if [ "$(jq -r '.ok' "${output_file}")" != "true" ]
+if [[ "$(jq -r '.ok' "${output_file}")" != "true" ]]
then
output_text="Failed to send the original file"
error_description="$(jq -r '.description' "${output_file}")"
- if [ "${error_description}" != "null" ]
+ if [[ "${error_description}" != "null" ]]
then
log_text="sendDocument (${update_id}): ${error_description}"
else
log_text="sendDocument (${update_id}): An unknown error occurred"
fi
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
diff --git a/submodules/command_ping.sh b/submodules/command_ping.zsh
index de72667..8d6497d 100644
--- a/submodules/command_ping.sh
+++ b/submodules/command_ping.zsh
@@ -6,7 +6,7 @@ output_text="Measuring..."
output_file="${cache}/${update_id}_sendMessage.json"
dump="${dump} ${output_file##*/}"
-latency_init="$(gdate +%s%3N)"
+latency_init="$(strftime %s%N)"
if ! curl --data-urlencode "chat_id=${chat_id}" \
--data-urlencode "message_thread_id=${message_thread_id}" \
@@ -23,39 +23,39 @@ then
output_text="Failed to measure latency"
log_text="sendMessage (${update_id}): Failed to access Telegram Bot API"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
-latency_fin="$(gdate +%s%3N)"
+latency_fin="$(strftime +%s%N)"
if ! jq -e '.' "${output_file}" > /dev/null
then
output_text="An unknown error occurred"
log_text="sendMessage (${update_id}): An unknown error occurred"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
-if [ "$(jq -r '.ok' "${output_file}")" != "true" ]
+if [[ "$(jq -r '.ok' "${output_file}")" != "true" ]]
then
output_text="Failed to measure latency"
error_description="$(jq -r '.description' "${output_file}")"
- if [ "${error_description}" != "null" ]
+ if [[ "${error_description}" != "null" ]]
then
log_text="sendMessage (${update_id}): ${error_description}"
else
log_text="sendMessage (${update_id}): An unknown error occurred"
fi
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
@@ -63,7 +63,7 @@ fi
chat_id="$(jq -r '.result.chat.id' "${output_file}")"
message_id="$(jq -r '.result.message_id' "${output_file}")"
-latency=$((latency_fin - latency_init- 5))
+latency=$(((latency_fin - latency_init) / 1000000 - 5))
output_text="$(printf "<b>Latency:</b> %ums" "${latency}")"
output_file="${cache}/${update_id}_editMessageText.json"
@@ -83,8 +83,8 @@ if ! curl --data-urlencode "chat_id=${chat_id}" \
then
log_text="editMessageText (${update_id}): Failed to access Telegram Bot API"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
exit 0
fi
@@ -93,25 +93,25 @@ if ! jq -e '.' "${output_file}" > /dev/null
then
log_text="editMessageText (${update_id}): An unknown error occurred"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
exit 0
fi
-if [ "$(jq -r '.ok' "${output_file}")" != "true" ]
+if [[ "$(jq -r '.ok' "${output_file}")" != "true" ]]
then
error_description="$(jq -r '.description' "${output_file}")"
- if [ "${error_description}" != "null" ]
+ if [[ "${error_description}" != "null" ]]
then
log_text="editMessageText (${update_id}): ${error_description}"
else
log_text="editMessageText (${update_id}): An unknown error occurred"
fi
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
fi
exit 0
diff --git a/submodules/command_post.sh b/submodules/command_post.zsh
index bc0a02c..c02d44d 100644
--- a/submodules/command_post.sh
+++ b/submodules/command_post.zsh
@@ -2,15 +2,15 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-. "${units}/ib_name.sh"
-. "${units}/ib_common.sh"
+. "${units}/ib_name.zsh"
+. "${units}/ib_common.zsh"
-if [ -n "${output_text}" ]
+if [[ -n "${output_text}" ]]
then
return 0
fi
-. "${units}/ib_post.sh"
+. "${units}/ib_post.zsh"
link_preview_options="$(jq --null-input --compact-output \
--arg url "${ib_sample_url}" \
@@ -24,9 +24,9 @@ reply_markup="$(jq --null-input --compact-output \
--arg url1 "${keyboard_url1}" \
'{"inline_keyboard": [[{"text": $text1, "url": $url1}]]}')"
-if [ ${ib_tags_count} -gt 0 ]
+if [[ ${#ib_tags} -gt 0 ]]
then
- keyboard_text1="Tags (${ib_tags_count})"
+ keyboard_text1="Tags (${#ib_tags})"
keyboard_data1="tags ${ib_board} ${ib_post_id}"
reply_markup="$(printf "%s" "${reply_markup}" | jq --compact-output \
diff --git a/submodules/command_prpr.sh b/submodules/command_prpr.zsh
index 09eedbd..09eedbd 100644
--- a/submodules/command_prpr.sh
+++ b/submodules/command_prpr.zsh
diff --git a/submodules/command_short.sh b/submodules/command_short.zsh
index d608d84..06db275 100644
--- a/submodules/command_short.sh
+++ b/submodules/command_short.zsh
@@ -2,7 +2,7 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
short_query="${@}"
shift ${#}
@@ -11,7 +11,7 @@ else
return 0
fi
-if [ ${#short_query} -gt 256 ]
+if [[ ${#short_query} -gt 256 ]]
then
output_text="Query is too long"
return 0
@@ -29,7 +29,7 @@ reply_markup="$(jq --null-input --compact-output \
short_query="short ${short_query}"
-if [ ${#short_query} -le 64 ]
+if [[ ${#short_query} -le 64 ]]
then
keyboard_text1="Manage"
keyboard_data1="${short_query}"
diff --git a/submodules/command_shorts.sh b/submodules/command_shorts.zsh
index 2fee2fd..6c9a33c 100644
--- a/submodules/command_shorts.sh
+++ b/submodules/command_shorts.zsh
@@ -9,16 +9,14 @@ done
short_config="${user_config}/short"
-if [ -d "${short_config}" ]
+if [[ -d "${short_config}" ]]
then
- shorts="$(ls -x "${short_config}")"
+ shorts=($(ls -x "${short_config}"))
fi
-set -- ${shorts}
-
-if [ ${#} -gt 0 ]
+if [[ ${#shorts} -gt 0 ]]
then
- output_text="<b>Saved shortcuts:</b> ${#} / ${shorts_limit}"
+ output_text="<b>Saved shortcuts:</b> ${#shorts} / ${shorts_limit}"
keyboard_text1="Open inline"
keyboard_query1="shorts"
diff --git a/submodules/command_source.sh b/submodules/command_source.zsh
index 4f04999..2b5c324 100644
--- a/submodules/command_source.sh
+++ b/submodules/command_source.zsh
@@ -2,7 +2,7 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ "${api_address}" != "${local_address}" ] && [ "${api_address}" != "${default_address}" ]
+if [[ "${api_address}" != "${local_address}" && "${api_address}" != "${default_address}" ]]
then
output_text="This command is not available, please contact bot deployer"
return 0
@@ -13,37 +13,37 @@ do
sleep 1
done
-. "${units}/sn_auth.sh"
+. "${units}/sn_auth.zsh"
rm -fr "${user_config}_saucenao.lock"
-if [ -n "${output_text}" ]
+if [[ -n "${output_text}" ]]
then
return 0
fi
-. "${units}/sn_get.sh"
+. "${units}/sn_get.zsh"
-if [ -n "${output_text}" ]
+if [[ -n "${output_text}" ]]
then
return 0
fi
-minimum_similarity="$(jq -r ".header.minimum_similarity" "${sn_file}" | sed 's/\.//')"
+minimum_similarity="$(jq -r ".header.minimum_similarity" "${sn_file}")"
highest_similarity=0
highest_index=0
array_count=0
-while [ -n "${array_count}" ]
+while [[ -n "${array_count}" ]]
do
- similarity="$(jq -r ".results.[${array_count}].header.similarity" "${sn_file}" | sed 's/\.//')"
+ similarity="$(jq -r ".results.[${array_count}].header.similarity" "${sn_file}")"
- if [ "${similarity}" = "null" ]
+ if [[ "${similarity}" = "null" ]]
then
break
fi
- if [ ${highest_similarity} -lt ${similarity} ]
+ if [[ ${highest_similarity} -lt ${similarity} ]]
then
highest_similarity=${similarity}
highest_index=${array_count}
@@ -52,14 +52,14 @@ do
array_count=$((array_count + 1))
done
-if [ ${highest_similarity} -lt ${minimum_similarity} ] || [ ${highest_similarity} -lt 7000 ]
+if [[ ${highest_similarity} -lt ${minimum_similarity} || ${highest_similarity} -lt 70.00 ]]
then
output_text="No results found"
return 0
fi
thumbnail="$(jq -r ".results.[${highest_index}].header.thumbnail" "${sn_file}")"
-similarity="$(printf "%.2f" "$(printf "%s" "${highest_similarity} / 100" | bc -l)")"
+similarity="$(printf "%.2f" "$((highest_similarity} / 100)"))"
link_preview_options="$(jq --null-input --compact-output \
--arg url "${thumbnail}" \
@@ -75,17 +75,17 @@ yandere_id="$(jq -r ".results.[${highest_index}].data.yandere_id" "${sn_file}")"
output_text="<b>SauceNAO</b>"
output_text="$(printf "%s\n<b>Similarity:</b> %s%%" "${output_text}" "${similarity}")"
-if [ "${danbooru_id}" != "null" ]
+if [[ "${danbooru_id}" != "null" ]]
then
output_text="$(printf "%s\n<b>Danbooru ID:</b> <code>%s</code>" "${output_text}" "${danbooru_id}")"
fi
-if [ "${gelbooru_id}" != "null" ]
+if [[ "${gelbooru_id}" != "null" ]]
then
output_text="$(printf "%s\n<b>Gelbooru ID:</b> <code>%s</code>" "${output_text}" "${gelbooru_id}")"
fi
-if [ "${idol_id}" != "null" ]
+if [[ "${idol_id}" != "null" ]]
then
idol_md5="$(jq -r ".results.[${highest_index}].header.index_name" "${sn_file}" | parameter 6 | cut -d '_' -f 1)"
@@ -93,17 +93,17 @@ then
output_text="$(printf "%s\n<b>Idol Complex MD5:</b> <code>%s</code>" "${output_text}" "${idol_md5}")"
fi
-if [ "${konachan_id}" != "null" ]
+if [[ "${konachan_id}" != "null" ]]
then
output_text="$(printf "%s\n<b>Konachan.com ID:</b> <code>%s</code>" "${output_text}" "${konachan_id}")"
fi
-if [ "${sankaku_id}" != "null" ]
+if [[ "${sankaku_id}" != "null" ]]
then
output_text="$(printf "%s\n<b>Sankaku Channel ID:</b> <code>%s</code>" "${output_text}" "${sankaku_id}")"
fi
-if [ "${yandere_id}" != "null" ]
+if [[ "${yandere_id}" != "null" ]]
then
output_text="$(printf "%s\n<b>yande.re ID:</b> <code>%s</code>" "${output_text}" "${yandere_id}")"
fi
diff --git a/submodules/command_stop.sh b/submodules/command_stop.zsh
index a957691..a957691 100644
--- a/submodules/command_stop.sh
+++ b/submodules/command_stop.zsh
diff --git a/submodules/inline_donate.sh b/submodules/inline_donate.zsh
index d1a241d..9d36021 100644
--- a/submodules/inline_donate.sh
+++ b/submodules/inline_donate.zsh
@@ -2,9 +2,9 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if ! [ -s "${files}/donate.txt" ]
+if ! [[ -s "${files}/donate.txt" ]]
then
- . "${submodules}/inline_help.sh"
+ . "${submods}/inline_help.zsh"
return 0
fi
diff --git a/submodules/inline_help.sh b/submodules/inline_help.zsh
index 79687c4..1ef1911 100644
--- a/submodules/inline_help.sh
+++ b/submodules/inline_help.zsh
@@ -2,7 +2,7 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-. "${units}/help.sh"
+. "${units}/help.zsh"
output_title="Sekoohaka Bot"
output_description="Click to send the help message"
diff --git a/submodules/inline_none.sh b/submodules/inline_none.zsh
index 93e7124..329c2d3 100644
--- a/submodules/inline_none.sh
+++ b/submodules/inline_none.zsh
@@ -9,20 +9,16 @@ done
short_config="${user_config}/short"
-if [ -d "${short_config}" ]
+if [[ -d "${short_config}" ]]
then
- shorts="$(ls -x "${short_config}")"
+ shorts=($(ls -x "${short_config}"))
fi
-set -- ${shorts}
-
-if [ ${#} -gt 0 ]
+if [[ ${#shorts} -gt 0 ]]
then
command="shorts"
else
command="help"
fi
-shift ${#}
-
rm -fr "${user_config}_short.lock"
diff --git a/submodules/inline_original.sh b/submodules/inline_original.zsh
index 615d744..5000ea8 100644
--- a/submodules/inline_original.sh
+++ b/submodules/inline_original.zsh
@@ -3,9 +3,9 @@
# SPDX-License-Identifier: Apache-2.0
ib_lock=0
-. "${units}/ib_common.sh"
+. "${units}/ib_common.zsh"
-if [ -n "${output_text}" ]
+if [[ -n "${output_text}" ]]
then
results="$(jq --null-input --compact-output \
--arg id "${query_id}" \
@@ -17,9 +17,9 @@ then
return 0
fi
-. "${units}/ib_original.sh"
+. "${units}/ib_original.zsh"
-if [ -n "${output_text}" ]
+if [[ -n "${output_text}" ]]
then
output_title="An error occurred"
@@ -42,7 +42,7 @@ else
'[{"type": "document", "id": $id, "title": $title, "document_url": $document_url, "mime_type": "application/zip", "description": $description, "thumbnail_url", $thumbnail_url}]')"
fi
-if [ -n "${ib_file_url}" ] && [ "${ib_file_url}" != "null" ]
+if [[ -n "${ib_file_url}" && "${ib_file_url}" != "null" ]]
then
keyboard_text1="Original file link"
keyboard_url1="${ib_file_url}"
diff --git a/submodules/inline_post.sh b/submodules/inline_post.zsh
index 2fe1001..8bf3f9a 100644
--- a/submodules/inline_post.sh
+++ b/submodules/inline_post.zsh
@@ -3,9 +3,9 @@
# SPDX-License-Identifier: Apache-2.0
ib_lock=0
-. "${units}/ib_common.sh"
+. "${units}/ib_common.zsh"
-if [ -n "${output_text}" ]
+if [[ -n "${output_text}" ]]
then
results="$(jq --null-input --compact-output \
--arg id "${query_id}" \
@@ -17,7 +17,7 @@ then
return 0
fi
-. "${units}/ib_post.sh"
+. "${units}/ib_post.zsh"
output_title="Information of post ${ib_post_id}"
output_description="Click to send the post information"
@@ -36,9 +36,9 @@ results="$(jq --null-input --compact-output \
--arg thumbnail_url "${ib_preview_url}" \
'[{"type": "article", "id": $id, "title": $title, "input_message_content": {"message_text": $text, "parse_mode": "HTML", "link_preview_options": {"url": $url, "prefer_small_media": true, "show_above_text": true}}, "reply_markup": {"inline_keyboard": [[{"text": $text1, "url": $url1}]]}, "description": $description, "thumbnail_url": $thumbnail_url}]')"
-if [ ${ib_tags_count} -gt 0 ]
+if [[ ${#ib_tags} -gt 0 ]]
then
- keyboard_text1="Tags (${ib_tags_count})"
+ keyboard_text1="Tags (${#ib_tags})"
keyboard_data1="tags ${ib_board} ${ib_post_id}"
results="$(printf "%s" "${results}" | jq --compact-output \
diff --git a/submodules/inline_search.sh b/submodules/inline_search.zsh
index 56a1d5d..df9d88f 100644
--- a/submodules/inline_search.sh
+++ b/submodules/inline_search.zsh
@@ -16,15 +16,15 @@ case "${command}" in
inline_options="aq"
;;
(*)
- . "${submodules}/inline_help.sh"
+ . "${submods}/inline_help.zsh"
return 0
;;
esac
ib_lock=0
-. "${units}/ib_search.sh"
+. "${units}/ib_search.zsh"
-if [ -n "${output_text}" ]
+if [[ -n "${output_text}" ]]
then
results="$(jq --null-input --compact-output \
--arg id "${query_id}" \
@@ -39,24 +39,24 @@ fi
results="[]"
array_count=0
-while [ -n "${array_count}" ]
+while [[ -n "${array_count}" ]]
do
ib_id="$(jq -r ".${ib_iarray}[${array_count}].${ib_iid}" "${ib_file}")"
- if [ "${ib_id}" = "null" ]
+ if [[ "${ib_id}" = "null" ]]
then
break
fi
case "${ib_mode}" in
(l)
- . "${submodules}/inline_search_pools.sh"
+ . "${submods}/inline_search_pools.zsh"
;;
(p)
- . "${submodules}/inline_search_posts.sh"
+ . "${submods}/inline_search_posts.zsh"
;;
(t)
- . "${submodules}/inline_search_tags.sh"
+ . "${submods}/inline_search_tags.zsh"
;;
esac
@@ -64,7 +64,7 @@ do
array_count=$((array_count + 1))
done
-if [ -n "${ib_autopaging}" ]
+if [[ -n "${ib_autopaging}" ]]
then
next_offset=$((inline_page + 1))
fi
diff --git a/submodules/inline_search_pools.sh b/submodules/inline_search_pools.zsh
index 7b298a3..d58e67c 100644
--- a/submodules/inline_search_pools.sh
+++ b/submodules/inline_search_pools.zsh
@@ -7,9 +7,9 @@ ib_pool="$(jq -r ".${ib_iarray}[${array_count}].${ib_ipool}" "${ib_file}")"
ib_count="$(jq -r ".${ib_iarray}[${array_count}].${ib_icount}" "${ib_file}")"
unset ib_date_text
-. "${units}/ib_date.sh"
+. "${units}/ib_date.zsh"
-if [ -n "${ib_ispace}" ]
+if [[ -n "${ib_ispace}" ]]
then
ib_pool="$(printf "%s" "${ib_pool}" | tr "${ib_ispace}" ' ')"
fi
@@ -17,7 +17,7 @@ fi
output_title="${ib_pool:- }"
output_text="$(printf "<b>%s</b>\n<b>ID:</b> <code>%s</code>" "${ib_name}" "${ib_id}")"
-if [ -n "${ib_date_text}" ]
+if [[ -n "${ib_date_text}" ]]
then
output_text="$(printf "%s\n<b>Date:</b> <code>%s</code>" "${output_text}" "${ib_date_text}")"
fi
@@ -31,7 +31,7 @@ keyboard_url1="${ib_url}$(printf "%s" "${ib_id}" | urlencode)"
keyboard_text2="Resume"
keyboard_query2="${command} ${ib_board} ${inline_page}"
-if [ -n "${inline_query}" ]
+if [[ -n "${inline_query}" ]]
then
keyboard_query2="${keyboard_query2} ${inline_query}"
fi
@@ -47,12 +47,12 @@ result="$(jq --null-input --compact-output \
--arg query2 "${keyboard_query2}" \
'{"type": "article", "id": $id, "title": $title, "input_message_content": {"message_text": $text, "parse_mode": "HTML"}, "description": $description, "reply_markup": {"inline_keyboard": [[{"text": $text1, "url": $url1}, {"text": $text2, "switch_inline_query_current_chat": $query2}]]}}')"
-if [ -n "${ib_quick}" ]
+if [[ -n "${ib_quick}" ]]
then
keyboard_text1="Search posts"
keyboard_query1="p ${ib_board} pool:${ib_id}"
- if [ -n "${ib_iorder}" ]
+ if [[ -n "${ib_iorder}" ]]
then
keyboard_query1="${keyboard_query1} ${ib_iorder}"
fi
diff --git a/submodules/inline_search_posts.sh b/submodules/inline_search_posts.zsh
index 729a140..1d6f5c0 100644
--- a/submodules/inline_search_posts.sh
+++ b/submodules/inline_search_posts.zsh
@@ -7,10 +7,10 @@ ib_file_size="$(jq -r ".${ib_iarray}[${array_count}].${ib_isize}" "${ib_file}")"
ib_file_url="$(jq -r ".${ib_iarray}[${array_count}].${ib_ifile}" "${ib_file}")"
unset ib_date_text ib_resolution_text ib_type_text ib_size_text
-. "${units}/ib_date.sh"
-. "${units}/ib_meta.sh"
+. "${units}/ib_date.zsh"
+. "${units}/ib_meta.zsh"
-if [ -n "${ib_preview}" ]
+if [[ -n "${ib_preview}" ]]
then
case "${ib_type}" in
(gif | video)
@@ -22,34 +22,34 @@ fi
output_text="$(printf "<b>%s</b>\n<b>ID:</b> <code>%s</code>" "${ib_name}" "${ib_id}")"
-if [ -n "${ib_date_text}" ]
+if [[ -n "${ib_date_text}" ]]
then
output_text="$(printf "%s\n<b>Date:</b> <code>%s</code>" "${output_text}" "${ib_date_text}")"
fi
-if [ -n "${ib_metadata}" ]
+if [[ -n "${ib_metadata}" ]]
then
- if [ -n "${ib_resolution_text}" ]
+ if [[ -n "${ib_resolution_text}" ]]
then
output_text="$(printf "%s\n<b>Resolution:</b> %s" "${output_text}" "${ib_resolution_text}")"
fi
- if [ -n "${ib_size_text}" ]
+ if [[ -n "${ib_size_text}" ]]
then
output_text="$(printf "%s\n<b>Size:</b> %s" "${output_text}" "${ib_size_text}")"
fi
- if [ -n "${ib_type_text}" ]
+ if [[ -n "${ib_type_text}" ]]
then
output_text="$(printf "%s\n<b>Type:</b> %s" "${output_text}" "${ib_type_text}")"
fi
fi
-if [ "${ib_name}" = "Idol Complex" ]
+if [[ "${ib_name}" = "Idol Complex" ]]
then
ib_md5="$(jq -r ".${ib_iarray}[${array_count}].${ib_imd5}" "${ib_file}")"
- if [ -n "${ib_md5}" ] && [ "${ib_md5}" != "null" ]
+ if [[ -n "${ib_md5}" && "${ib_md5}" != "null" ]]
then
ib_id="${ib_md5}"
output_text="$(printf "%s\n<b>MD5:</b> <code>%s</code>" "${output_text}" "${ib_md5}")"
@@ -61,7 +61,7 @@ keyboard_url1="${ib_url}$(printf "%s" "${ib_id}" | urlencode)"
keyboard_text2="Resume"
keyboard_query2="${command} ${ib_board} ${inline_page}"
-if [ -n "${inline_query}" ]
+if [[ -n "${inline_query}" ]]
then
keyboard_query2="${keyboard_query2} ${inline_query}"
fi
@@ -111,7 +111,7 @@ case "${ib_type}" in
;;
esac
-if [ -n "${ib_quick}" ]
+if [[ -n "${ib_quick}" ]]
then
keyboard_text1="Original"
keyboard_query1="original ${ib_board} ${ib_id}"
@@ -126,7 +126,7 @@ then
'.reply_markup.inline_keyboard += [[{"text": $text1, "switch_inline_query_current_chat": $query1}, {"text": $text2, "switch_inline_query_current_chat": $query2}]]')"
fi
-if [ "${caching_mode}" = "advanced" ]
+if [[ "${caching_mode}" = "advanced" ]]
then
ib_hash="$(printf "%s%s%s" "${user_id}" "${ib_board}" "${ib_id}" | enhash)"
. "${units}/ib_cache.sh" &
diff --git a/submodules/inline_search_tags.sh b/submodules/inline_search_tags.zsh
index d1f5627..ae4f35a 100644
--- a/submodules/inline_search_tags.sh
+++ b/submodules/inline_search_tags.zsh
@@ -5,7 +5,7 @@
ib_tag="$(jq -r ".${ib_iarray}[${array_count}].${ib_itag}" "${ib_file}")"
ib_count="$(jq -r ".${ib_iarray}[${array_count}].${ib_icount}" "${ib_file}")"
-if [ -n "${ib_irecode}" ] && ib_tag_recode="$(printf "%s" "${ib_tag}" | recode ${ib_irecode}..ASCII)"
+if [[ -n "${ib_irecode}" ]] && ib_tag_recode="$(printf "%s" "${ib_tag}" | recode ${ib_irecode}..ASCII)"
then
ib_tag="${ib_tag_recode}"
fi
@@ -21,7 +21,7 @@ keyboard_url1="${ib_url}$(printf "%s" "${ib_tag}" | urlencode)"
keyboard_text2="Resume"
keyboard_query2="${command} ${ib_board} ${inline_page}"
-if [ -n "${inline_query}" ]
+if [[ -n "${inline_query}" ]]
then
keyboard_query2="${keyboard_query2} ${inline_query}"
fi
@@ -37,7 +37,7 @@ result="$(jq --null-input --compact-output \
--arg query2 "${keyboard_query2}" \
'{"type": "article", "id": $id, "title": $title, "input_message_content": {"message_text": $text, "parse_mode": "HTML"}, "description": $description, "reply_markup": {"inline_keyboard": [[{"text": $text1, "url": $url1}, {"text": $text2, "switch_inline_query_current_chat": $query2}]]}}')"
-if [ -n "${ib_quick}" ]
+if [[ -n "${ib_quick}" ]]
then
keyboard_text1="Search posts"
keyboard_query1="p ${ib_board} ${ib_tag}"
diff --git a/submodules/inline_short.sh b/submodules/inline_short.zsh
index d812375..88a77c0 100644
--- a/submodules/inline_short.sh
+++ b/submodules/inline_short.zsh
@@ -2,7 +2,7 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
short_query="${@}"
shift ${#}
@@ -38,7 +38,7 @@ results="$(jq --null-input --compact-output \
short_query="short ${short_query}"
-if [ ${#short_query} -le 64 ]
+if [[ ${#short_query} -le 64 ]]
then
keyboard_text1="Manage"
keyboard_data1="${short_query}"
diff --git a/submodules/inline_shorts.sh b/submodules/inline_shorts.zsh
index 0563cc7..8207389 100644
--- a/submodules/inline_shorts.sh
+++ b/submodules/inline_shorts.zsh
@@ -8,9 +8,9 @@ do
done
short_config="${user_config}/short"
-. "${units}/shorts_search.sh"
+. "${units}/shorts_search.zsh"
-if [ -n "${output_text}" ]
+if [[ -n "${output_text}" ]]
then
results="$(jq --null-input --compact-output \
--arg id "${query_id}" \
@@ -23,10 +23,10 @@ then
return 0
fi
-results=[]
+results="[]"
array_count=0
-for short in ${@}
+for short in ${shorts[@]}
do
short_query="$(cat "${short_config}/${short}")"
@@ -46,12 +46,12 @@ do
--arg description "${output_description}" \
'{"type": "article", "id": $id, "title": $title, "input_message_content": {"message_text": $text, "parse_mode": "HTML"}, "reply_markup": {"inline_keyboard": [[{"text": $text1, "switch_inline_query_current_chat": $query1}]]}, "description": $description}')"
- if [ "${chat_type}" = "sender" ]
+ if [[ "${chat_type}" = "sender" ]]
then
keyboard_text1="Resume"
keyboard_query1="${command} ${inline_page}"
- if [ -n "${inline_query}" ]
+ if [[ -n "${inline_query}" ]]
then
keyboard_query1="${keyboard_query1} ${inline_query}"
fi
@@ -62,7 +62,7 @@ do
'.reply_markup.inline_keyboard.[0] += [{"text": $text1, "switch_inline_query_current_chat": $query1}]')"
fi
- if [ -n "${shorts_quick}" ]
+ if [[ -n "${shorts_quick}" ]]
then
keyboard_text1="Manage"
keyboard_data1="short ${short_query}"
@@ -76,13 +76,13 @@ do
results="$(printf "%s" "${results}" | jq -c ".[${array_count}] += ${result}")"
array_count=$((array_count + 1))
- if [ ${array_count} -eq ${inline_limit} ]
+ if [[ ${array_count} -eq ${inline_limit} ]]
then
break
fi
done
-if [ -n "${shorts_autopaging}" ]
+if [[ -n "${shorts_autopaging}" ]]
then
next_offset=$((inline_page + 1))
fi
diff --git a/submodules/url_parser.sh b/submodules/url_parser.zsh
index f144f85..501febf 100644
--- a/submodules/url_parser.sh
+++ b/submodules/url_parser.zsh
@@ -2,58 +2,57 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-url_table="
- https://safebooru.donmai.us/posts/.* a / 5
- safebooru.donmai.us/posts/.* a / 3
- https://danbooru.donmai.us/posts/.* d / 5
- danbooru.donmai.us/posts/.* d / 3
- https://gelbooru.com/index.php?page=post&s=view&id=.* g = 4
- gelbooru.com/index.php?page=post&s=view&id=.* g = 4
- https://idol.sankakucomplex.com/.*/posts/.* i / 6
- idol.sankakucomplex.com/.*/posts/.* i / 4
- https://idol.sankakucomplex.com/posts/.* i / 5
- idol.sankakucomplex.com/posts/.* i / 3
- https://konachan.com/post/show/.* k / 6
- konachan.com/post/show/.* k / 4
- https://chan.sankakucomplex.com/.*/posts/.* s / 6
- chan.sankakucomplex.com/.*/posts/.* s / 4
- https://chan.sankakucomplex.com/posts/.* s / 5
- chan.sankakucomplex.com/posts/.* s / 3
- https://yande.re/post/show/.* y / 6
- yande.re/post/show/.* y / 4
-"
+url_table=(
+ "https://safebooru.donmai.us/posts/.*" a / 5
+ "safebooru.donmai.us/posts/.*" a / 3
+ "https://danbooru.donmai.us/posts/.*" d / 5
+ "danbooru.donmai.us/posts/.*" d / 3
+ "https://gelbooru.com/index.php?page=post&s=view&id=.*" g = 4
+ "gelbooru.com/index.php?page=post&s=view&id=.*" g = 4
+ "https://idol.sankakucomplex.com/.*/posts/.*" i / 6
+ "idol.sankakucomplex.com/.*/posts/.*" i / 4
+ "https://idol.sankakucomplex.com/posts/.*" i / 5
+ "idol.sankakucomplex.com/posts/.*" i / 3
+ "https://konachan.com/post/show/.*" k / 6
+ "konachan.com/post/show/.*" k / 4
+ "https://chan.sankakucomplex.com/.*/posts/.*" s / 6
+ "chan.sankakucomplex.com/.*/posts/.*" s / 4
+ "https://chan.sankakucomplex.com/posts/.*" s / 5
+ "chan.sankakucomplex.com/posts/.*" s / 3
+ "https://yande.re/post/show/.*" y / 6
+ "yande.re/post/show/.*" y / 4
+)
ib_mode="p"
-set -- ${url_table}
-while [ ${#} -ge 4 ]
+while [[ ${#url_table} -ge 4 ]]
do
- if echo ${command} | grep -qx "${1}"
+ if echo ${command} | grep -qx "${url_table[1]}"
then
- ib_board="${2}"
- ib_post_id="$(printf "%s" ${command} | cut -d ${3} -f ${4} | cut -d '?' -f 1)"
+ ib_board="${url_table[2]}"
+ ib_post_id="$(printf "%s" ${command} | cut -d ${url_table[3]} -f ${url_table[4]} | cut -d '?' -f 1)"
break
fi
- shift 4
+ url_table=(${url_table[@]:4})
done
-if [ -z "${ib_post_id}" ]
+if [[ -z "${ib_post_id}" ]]
then
exit 0
fi
-. "${units}/ib_config.sh"
-. "${units}/ib_authconfig.sh"
+. "${units}/ib_config.zsh"
+. "${units}/ib_authconfig.zsh"
-if [ ${#ib_post_id} -gt 32 ]
+if [[ ${#ib_post_id} -gt 32 ]]
then
exit 0
-elif [ ${#ib_post_id} -eq 32 ]
+elif [[ ${#ib_post_id} -eq 32 ]]
then
ib_query="md5:${ib_post_id}"
-elif [ "${ib_name}" = "Idol Complex" ]
+elif [[ "${ib_name}" = "Idol Complex" ]]
then
ib_query="id_range:${ib_post_id}"
else
@@ -61,9 +60,9 @@ else
fi
ib_hash="$(printf "%s%s%s" "${user_id}" "${ib_board}" "${ib_post_id}" | enhash)"
-. "${units}/ib_file.sh"
+. "${units}/ib_file.zsh"
-if [ -n "${output_text}" ]
+if [[ -n "${output_text}" ]]
then
keyboard_text1="Delete"
keyboard_data1="delete"
@@ -76,7 +75,7 @@ then
return 0
fi
-. "${units}/ib_post.sh"
+. "${units}/ib_post.zsh"
link_preview_options="$(jq --null-input --compact-output \
--arg url "${ib_sample_url}" \
@@ -94,9 +93,9 @@ reply_markup="$(jq --null-input --compact-output \
--arg data2 "${keyboard_data2}" \
'{"inline_keyboard": [[{"text": $text1, "url": $url1}], [{"text": $text2, "callback_data": $data2}]]}')"
-if [ ${ib_tags_count} -gt 0 ]
+if [[ ${#ib_tags} -gt 0 ]]
then
- keyboard_text1="Tags (${ib_tags_count})"
+ keyboard_text1="Tags (${#ib_tags})"
keyboard_data1="tags ${ib_board} ${ib_post_id}"
reply_markup="$(printf "%s" "${reply_markup}" | jq --compact-output \
diff --git a/units/dump.sh b/units/dump.zsh
index 904d012..8c857da 100644
--- a/units/dump.sh
+++ b/units/dump.zsh
@@ -2,19 +2,19 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ -z "${collect_dumps}" ]
+if [[ -z "${collect_dumps}" ]]
then
return 0
fi
-if [ -n "${dump}" ]
+if [[ -n "${dump}" ]]
then
mkdir -p "${dumps}/${update_id}"
fi
for cache_dump in ${dump}
do
- if [ -f "${cache}/${cache_dump}" ]
+ if [[ -f "${cache}/${cache_dump}" ]]
then
cp "${cache}/${cache_dump}" "${dumps}/${update_id}"
fi
diff --git a/units/help.sh b/units/help.zsh
index ffc9de0..ffc9de0 100644
--- a/units/help.sh
+++ b/units/help.zsh
diff --git a/units/ib_auth.sh b/units/ib_auth.zsh
index 20c16dc..444e746 100644
--- a/units/ib_auth.sh
+++ b/units/ib_auth.zsh
@@ -2,9 +2,9 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ -z "${ib_login}" ]
+if [[ -z "${ib_login}" ]]
then
- if [ -f "${user_config}/${ib_config}/${ib_login_file}" ]
+ if [[ -f "${user_config}/${ib_config}/${ib_login_file}" ]]
then
ib_login="$(cat "${user_config}/${ib_config}/${ib_login_file}")"
else
@@ -13,9 +13,9 @@ then
fi
fi
-if [ -z "${ib_key}" ]
+if [[ -z "${ib_key}" ]]
then
- if [ -f "${user_config}/${ib_config}/${ib_key_file}" ]
+ if [[ -f "${user_config}/${ib_config}/${ib_key_file}" ]]
then
ib_key="$(cat "${user_config}/${ib_config}/${ib_key_file}")"
else
@@ -47,8 +47,8 @@ case "${ib_board}" in
output_text="Failed to process request"
log_text="ib_auth (${update_id}): ${output_text}"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
@@ -58,30 +58,30 @@ case "${ib_board}" in
output_text="An unknown error occurred"
log_text="ib_auth (${update_id}): ${output_text}"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
- if [ "$(jq -r '.success' "${ib_auth_file}")" = "false" ]
+ if [[ "$(jq -r '.success' "${ib_auth_file}")" = "false" ]]
then
output_text="Error: <code>$(jq -r '.message' "${ib_auth_file}" | htmlescape)</code>"
log_text="ib_auth (${update_id}): $(jq -r '.message' "${ib_auth_file}")"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
- if [ "$(jq -r '.name' "${ib_auth_file}")" != "${ib_login}" ]
+ if [[ "$(jq -r '.name' "${ib_auth_file}")" != "${ib_login}" ]]
then
output_text="An unexpected error occurred"
log_text="ib_auth (${update_id}): ${output_text}"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
@@ -125,8 +125,8 @@ case "${ib_board}" in
output_text="Failed to process request"
log_text="ib_auth (${update_id}): ${output_text}"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
@@ -136,19 +136,19 @@ case "${ib_board}" in
output_text="An unknown error occurred"
log_text="ib_auth (${update_id}): ${output_text}"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
- if [ "$(jq -r '.success' "${ib_auth_file}")" != "true" ]
+ if [[ "$(jq -r '.success' "${ib_auth_file}")" != "true" ]]
then
output_text="Error: <code>$(jq -r '.error' "${ib_auth_file}" | htmlescape)</code>"
log_text="ib_auth (${update_id}): $(jq -r '.error' "${ib_auth_file}")"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
@@ -173,8 +173,8 @@ case "${ib_board}" in
output_text="Failed to process request"
log_text="ib_auth (${update_id}): ${output_text}"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
@@ -184,8 +184,8 @@ case "${ib_board}" in
output_text="Invalid username or API key"
log_text="ib_auth (${update_id}): ${output_text}"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
diff --git a/units/ib_authconfig.sh b/units/ib_authconfig.zsh
index 31dc7ba..31dc7ba 100644
--- a/units/ib_authconfig.sh
+++ b/units/ib_authconfig.zsh
diff --git a/units/ib_cache.sh b/units/ib_cache.zsh
index cd6946c..0f4c604 100644
--- a/units/ib_cache.sh
+++ b/units/ib_cache.zsh
@@ -10,7 +10,7 @@ done
ib_post="$(jq -c ".${ib_iarray}[${array_count}]" "${ib_file}")"
ib_file="${cache}/${ib_hash}.json"
-if [ -n "${ib_iarray}" ]
+if [[ -n "${ib_iarray}" ]]
then
printf '{"%s":[%s]}' "${ib_iarray}" "${ib_post}" | jq -c > "${ib_file}"
else
diff --git a/units/ib_common.sh b/units/ib_common.zsh
index 43ad6e9..9ee1b09 100644
--- a/units/ib_common.sh
+++ b/units/ib_common.zsh
@@ -2,15 +2,15 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
ib_board="${1}"
ib_mode="p"
- . "${units}/ib_config.sh"
- . "${units}/ib_authconfig.sh"
+ . "${units}/ib_config.zsh"
+ . "${units}/ib_authconfig.zsh"
- if [ -z "${ib_data_url}" ]
+ if [[ -z "${ib_data_url}" ]]
then
output_title="Invalid arguments"
output_text="Unsupported image board"
@@ -28,22 +28,22 @@ else
return 0
fi
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
ib_post_id="${1}"
shift
else
output_title="Invalid arguments"
- output_text="You must specify the post ID or the MD5 hash"
+ output_text="You must specify the post ID or the MD5 h.zsh"
notification_text="${output_text}"
return 0
fi
-if [ ${#ib_post_id} -eq 32 ]
+if [[ ${#ib_post_id} -eq 32 ]]
then
ib_query="md5:${ib_post_id}"
-elif [ "${ib_name}" = "Idol Complex" ]
+elif [[ "${ib_name}" = "Idol Complex" ]]
then
ib_query="id_range:${ib_post_id}"
else
@@ -51,4 +51,4 @@ else
fi
ib_hash="$(printf "%s%s%s" "${user_id}" "${ib_board}" "${ib_post_id}" | enhash)"
-. "${units}/ib_file.sh"
+. "${units}/ib_file.zsh"
diff --git a/units/ib_config.sh b/units/ib_config.zsh
index fcd0bcf..070ae20 100644
--- a/units/ib_config.sh
+++ b/units/ib_config.zsh
@@ -21,20 +21,20 @@ case "${ib_board}" in
;;
esac
- ib_ratings="
+ ib_ratings=(
g general
s sensitive
q questionable
e explicit
- "
+ )
- ib_groups="
+ ib_groups=(
tag_string_artist Artist
tag_string_copyright Copyright
tag_string_character Character
tag_string_general General
tag_string_meta Meta
- "
+ )
case "${ib_mode}" in
(l)
@@ -92,17 +92,17 @@ case "${ib_board}" in
ib_api="https://gelbooru.com"
ib_url="https://gelbooru.com"
- ib_ratings="
+ ib_ratings=(
safe safe
general general
sensitive sensitive
questionable questionable
explicit explicit
- "
+ )
- ib_groups="
+ ib_groups=(
tags Tags
- "
+ )
case "${ib_mode}" in
(p)
@@ -160,23 +160,23 @@ case "${ib_board}" in
ib_api="https://iapi.sankakucomplex.com"
ib_url="https://idol.sankakucomplex.com"
- ib_ratings="
+ ib_ratings=(
s safe
q questionable
e explicit
- "
+ )
- ib_groups="
- tags[]|select(.type==1)|.name Idol
- tags[]|select(.type==2)|.name Studio
- tags[]|select(.type==3)|.name Copyright
- tags[]|select(.type==4)|.name Character
- tags[]|select(.type==6)|.name Genre
- tags[]|select(.type==5)|.name Set
- tags[]|select(.type==0)|.name General
- tags[]|select(.type==8)|.name Medium
- tags[]|select(.type==9)|.name Meta
- "
+ ib_groups=(
+ "tags[]|select(.type==1)|.name" Idol
+ "tags[]|select(.type==2)|.name" Studio
+ "tags[]|select(.type==3)|.name" Copyright
+ "tags[]|select(.type==4)|.name" Character
+ "tags[]|select(.type==6)|.name" Genre
+ "tags[]|select(.type==5)|.name" Set
+ "tags[]|select(.type==0)|.name" General
+ "tags[]|select(.type==8)|.name" Medium
+ "tags[]|select(.type==9)|.name" Meta
+ )
case "${ib_mode}" in
(l)
@@ -233,22 +233,22 @@ case "${ib_board}" in
ib_api="https://sankakuapi.com"
ib_url="https://chan.sankakucomplex.com"
- ib_ratings="
+ ib_ratings=(
s safe
q questionable
e explicit
- "
+ )
- ib_groups="
- tags[]|select(.type==1)|.tagName Artist
- tags[]|select(.type==2)|.tagName Studio
- tags[]|select(.type==3)|.tagName Copyright
- tags[]|select(.type==4)|.tagName Character
- tags[]|select(.type==5)|.tagName Genre
- tags[]|select(.type==0)|.tagName General
- tags[]|select(.type==8)|.tagName Medium
- tags[]|select(.type==9)|.tagName Meta
- "
+ ib_groups=(
+ "tags[]|select(.type==1)|.tagName" Artist
+ "tags[]|select(.type==2)|.tagName" Studio
+ "tags[]|select(.type==3)|.tagName" Copyright
+ "tags[]|select(.type==4)|.tagName" Character
+ "tags[]|select(.type==5)|.tagName" Genre
+ "tags[]|select(.type==0)|.tagName" General
+ "tags[]|select(.type==8)|.tagName" Medium
+ "tags[]|select(.type==9)|.tagName" Meta
+ )
case "${ib_mode}" in
(l)
@@ -311,15 +311,15 @@ case "${ib_board}" in
;;
esac
- ib_ratings="
+ ib_ratings=(
s safe
q questionable
e explicit
- "
+ )
- ib_groups="
+ ib_groups=(
tags Tags
- "
+ )
case "${ib_mode}" in
(l)
diff --git a/units/ib_date.sh b/units/ib_date.zsh
index e674238..803a386 100644
--- a/units/ib_date.sh
+++ b/units/ib_date.zsh
@@ -2,14 +2,14 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ -n "${ib_created_at}" ] && [ "${ib_created_at}" != "null" ]
+if [[ -n "${ib_created_at}" && "${ib_created_at}" != "null" ]]
then
- if [ -n "${ib_itzfield}" ]
+ if [[ -n "${ib_itzfield}" ]]
then
ib_created_at="$(printf "%s" "${ib_created_at}" | parameter ${ib_itzfield})"
fi
- if [ -n "${ib_idate}" ]
+ if [[ -n "${ib_idate}" ]]
then
ib_date_text="$(date -ud "${ib_created_at}" -D "${ib_idate}" +"%Y-%m-%d %H:%M")"
else
diff --git a/units/ib_file.sh b/units/ib_file.zsh
index 4009f52..0dff7fb 100644
--- a/units/ib_file.sh
+++ b/units/ib_file.zsh
@@ -10,40 +10,40 @@ done
ib_file="${cache}/${ib_hash}.json"
dump="${dump} ${ib_file##*/}"
-if [ -f "${ib_file}" ] && [ "${caching_mode}" != "none" ]
+if [[ -f "${ib_file}" && "${caching_mode}" != "none" ]]
then
ib_ctime=$(date +%s)
ib_mtime=$(stat -c %Y "${ib_file}")
- if [ $((ib_ctime - ib_mtime)) -le $((caching_time - 15)) ]
+ if [[ $((ib_ctime - ib_mtime)) -le $((caching_time - 15)) ]]
then
rm -fr "${cache}/${ib_hash}.lock"
return 0
fi
fi
-if [ -n "${ib_config}" ]
+if [[ -n "${ib_config}" ]]
then
- . "${units}/ib_token.sh"
+ . "${units}/ib_token.zsh"
- if [ -n "${output_text}" ]
+ if [[ -n "${output_text}" ]]
then
rm -fr "${cache}/${ib_hash}.lock"
return 0
fi
fi
-if [ -n "${ib_limit}" ]
+if [[ -n "${ib_limit}" ]]
then
ib_limit="${ib_dlimit}=${ib_limit}"
fi
-if [ -n "${ib_page}" ]
+if [[ -n "${ib_page}" ]]
then
ib_page="${ib_dpage}=$((ib_page + ib_ioffset))"
fi
-if [ -n "${ib_query}" ]
+if [[ -n "${ib_query}" ]]
then
ib_query="${ib_dquery}=${ib_query}"
fi
@@ -75,8 +75,8 @@ then
next_offset=${inline_page:-0}
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
rm -fr "${ib_file}" "${cache}/${ib_hash}.lock"
return 0
@@ -89,8 +89,8 @@ then
notification_text="${output_text}"
log_text="ib_file (${update_id}): ${output_text}"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
rm -fr "${ib_file}" "${cache}/${ib_hash}.lock"
return 0
@@ -98,14 +98,14 @@ fi
if ! jq -e ".${ib_iarray}[0]|has(\"${ib_iid}\")" "${ib_file}" > /dev/null
then
- if [ -n "${inline_options}" ] && [ -n "${offset}" ]
+ if [[ -n "${inline_options}" && -n "${offset}" ]]
then
output_title="End of results"
else
output_title="No results found"
fi
- if [ -n "${inline_options}" ]
+ if [[ -n "${inline_options}" ]]
then
case "${ib_mode}" in
(l)
@@ -119,7 +119,7 @@ then
;;
esac
else
- output_text="Try different post ID or MD5 hash"
+ output_text="Try different post ID or MD5 h.zsh"
fi
notification_text="${output_text}"
diff --git a/units/ib_hash.sh b/units/ib_hash.zsh
index 22bfe95..f579180 100644
--- a/units/ib_hash.sh
+++ b/units/ib_hash.zsh
@@ -4,15 +4,15 @@
ib_mode="p"
-. "${units}/ib_config.sh"
-. "${units}/ib_authconfig.sh"
+. "${units}/ib_config.zsh"
+. "${units}/ib_authconfig.zsh"
ib_query="md5:${ib_post_md5}"
ib_hash="$(printf "%s%s%s" "${user_id}" "${ib_board}" "${ib_post_md5}" | enhash)"
-. "${units}/ib_file.sh"
+. "${units}/ib_file.zsh"
-if [ -z "${output_text}" ]
+if [[ -z "${output_text}" ]]
then
ib_id="$(jq -r ".${ib_iarray}[0].${ib_iid}" "${ib_file}")"
printf "<b>%s ID:</b> <code>%s</code>\n" "${ib_name}" "${ib_id}" >> "${ib_posts}"
diff --git a/units/ib_lock.sh b/units/ib_lock.zsh
index a8897bc..e80df6c 100644
--- a/units/ib_lock.sh
+++ b/units/ib_lock.zsh
@@ -7,6 +7,6 @@ do
sleep 1
done
-. "${units}/ib_auth.sh"
+. "${units}/ib_auth.zsh"
rm -fr "${user_config}_auth.lock"
diff --git a/units/ib_meta.sh b/units/ib_meta.zsh
index a845a25..0484b5e 100644
--- a/units/ib_meta.sh
+++ b/units/ib_meta.zsh
@@ -2,7 +2,7 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ -n "${ib_file_url}" ] && [ "${ib_file_url}" != "null" ]
+if [[ -n "${ib_file_url}" && "${ib_file_url}" != "null" ]]
then
ib_sample_url="$(jq -r ".${ib_iarray}[${array_count}].${ib_isample}" "${ib_file}")"
ib_preview_url="$(jq -r ".${ib_iarray}[${array_count}].${ib_ipreview}" "${ib_file}")"
@@ -10,33 +10,33 @@ then
ib_height="$(jq -r ".${ib_iarray}[${array_count}].${ib_iheight}" "${ib_file}")"
ib_type="$(printf "%s" "${ib_file_url}" | eval ${ib_ifilename} | cut -d '.' -f 2)"
- if [ "${ib_name}" = "Idol Complex" ]
+ if [[ "${ib_name}" = "Idol Complex" ]]
then
ib_file_url="https:${ib_file_url}"
fi
- if [ -z "${ib_sample_url}" ] || [ "${ib_sample_url}" = "null" ]
+ if [[ -z "${ib_sample_url}" || "${ib_sample_url}" = "null" ]]
then
ib_sample_url=${ib_file_url}
- elif [ "${ib_name}" = "Idol Complex" ]
+ elif [[ "${ib_name}" = "Idol Complex" ]]
then
ib_sample_url="https:${ib_sample_url}"
fi
- if [ -z "${ib_preview_url}" ] || [ "${ib_preview_url}" = "null" ]
+ if [[ -z "${ib_preview_url}" || "${ib_preview_url}" = "null" ]]
then
ib_preview_url=${ib_error_url}
- elif [ "${ib_name}" = "Idol Complex" ] || [ "${ib_name}" = "Sankaku Channel" ]
+ elif [[ "${ib_name}" = "Idol Complex" || "${ib_name}" = "Sankaku Channel" ]]
then
ib_preview_url="${ib_sample_url}"
fi
- if [ -n "${ib_width}" ] && [ "${ib_width}" != "null" ] && [ ${ib_width} -gt 0 ]
+ if [[ -n "${ib_width}" && "${ib_width}" != "null" && ${ib_width} -gt 0 ]]
then
ib_resolution_text="${ib_width}x${ib_height}"
fi
- if [ -n "${ib_type}" ]
+ if [[ -n "${ib_type}" ]]
then
ib_type_text="$(printf "%s" "${ib_type}" | tr '[:lower:]' '[:upper:]')"
fi
@@ -46,15 +46,15 @@ then
ib_type="photo"
;;
(gif)
- . "${units}/ib_preview.sh"
+ . "${units}/ib_preview.zsh"
ib_type="gif"
;;
(mp4)
- . "${units}/ib_preview.sh"
+ . "${units}/ib_preview.zsh"
ib_type="video"
;;
(zip | webm)
- . "${units}/ib_sample.sh"
+ . "${units}/ib_sample.zsh"
;;
(*)
ib_sample_url="${ib_error_url}"
@@ -74,30 +74,30 @@ else
ib_type="photo"
fi
-if [ -n "${ib_file_size}" ] && [ "${ib_file_size}" != "null" ] && [ ${ib_file_size} -gt 0 ]
+if [[ -n "${ib_file_size}" && "${ib_file_size}" != "null" && ${ib_file_size} -gt 0 ]]
then
- if [ ${ib_file_size} -gt 20971520 ] && [ "${ib_sample_url}" = "${ib_file_url}" ]
+ if [[ ${ib_file_size} -gt 20971520 && "${ib_sample_url}" = "${ib_file_url}" ]]
then
- . "${units}/ib_sample.sh"
+ . "${units}/ib_sample.zsh"
fi
unit_offset=0
- size_offset=1
+ size_offset=1.0
for unit in B KiB MiB GiB TiB PiB
do
unit_offset=${size_offset}
size_offset=$((size_offset * 1024))
- if [ ${ib_file_size} -lt ${size_offset} ]
+ if [[ ${ib_file_size} -lt ${size_offset} ]]
then
break
fi
done
- if [ ${ib_file_size} -ge 1024 ]
+ if [[ ${ib_file_size} -ge 1024 ]]
then
- ib_size_text="$(printf "%.2f %s" "$(printf "%s" "${ib_file_size} / ${unit_offset}" | bc -l)" "${unit}")"
+ ib_size_text="$(printf "%.2f %s" "$((ib_file_size / unit_offset))" "${unit}")"
else
ib_size_text="$(printf "%u %s" "${ib_file_size}" "${unit}")"
fi
diff --git a/units/ib_name.sh b/units/ib_name.zsh
index cd5f180..c6a0e16 100644
--- a/units/ib_name.sh
+++ b/units/ib_name.zsh
@@ -4,31 +4,31 @@
board_table="a d g i k s y"
-if [ -z "${1}" ]
+if [[ -z "${1}" ]]
then
reply_text="$(jq -r '.message.reply_to_message.text' "${update}")"
- if [ "${reply_text}" = "null" ]
+ if [[ "${reply_text}" = "null" ]]
then
reply_text="$(jq -r '.message.reply_to_message.caption' "${update}")"
fi
- if [ "${reply_text}" != "null" ]
+ if [[ "${reply_text}" != "null" ]]
then
ib_reply_name="$(printf "%s" "${reply_text}" | sed '1!d')"
ib_post_id="$(printf "%s" "${reply_text}" | grep 'ID' | parameter 2)"
for ib_board in ${board_table}
do
- . "${units}/ib_config.sh"
+ . "${units}/ib_config.zsh"
- if [ "${ib_reply_name}" = "${ib_name}" ]
+ if [[ "${ib_reply_name}" = "${ib_name}" ]]
then
break
fi
done
- if [ "${ib_name}" = "Idol Complex" ] && echo "${reply_text}" | grep -q 'MD5'
+ if [[ "${ib_name}" = "Idol Complex" ]] && echo "${reply_text}" | grep -q 'MD5'
then
ib_post_id="$(printf "%s" "${reply_text}" | grep 'MD5' | parameter 2)"
fi
diff --git a/units/ib_original.sh b/units/ib_original.zsh
index 1f2fbf1..6229bba 100644
--- a/units/ib_original.sh
+++ b/units/ib_original.zsh
@@ -5,19 +5,19 @@
ib_file_size="$(jq -r ".${ib_iarray}[0].${ib_isize}" "${ib_file}")"
ib_file_url="$(jq -r ".${ib_iarray}[0].${ib_ifile}" "${ib_file}")"
-. "${units}/ib_size.sh"
+. "${units}/ib_size.zsh"
-if [ -n "${ib_file_url}" ] && [ "${ib_file_url}" != "null" ]
+if [[ -n "${ib_file_url}" && "${ib_file_url}" != "null" ]]
then
- . "${units}/ib_meta.sh"
+ . "${units}/ib_meta.zsh"
else
output_text="No original file found"
return 0
fi
-if [ -n "${ib_file_size}" ] && [ "${ib_file_size}" != "null" ] && [ ${ib_file_size} -gt 0 ]
+if [[ -n "${ib_file_size}" && "${ib_file_size}" != "null" && ${ib_file_size} -gt 0 ]]
then
- if [ ${ib_file_size} -gt 20971520 ]
+ if [[ ${ib_file_size} -gt 20971520 ]]
then
output_text="File size is too large"
fi
diff --git a/units/ib_post.sh b/units/ib_post.zsh
index af85126..ad8a5a0 100644
--- a/units/ib_post.sh
+++ b/units/ib_post.zsh
@@ -11,81 +11,72 @@ ib_parent_id="$(jq -r ".${ib_iarray}[0].${ib_iparent}" "${ib_file}")"
ib_has_children="$(jq -r ".${ib_iarray}[0].${ib_ichildren}" "${ib_file}")"
ib_md5="$(jq -r ".${ib_iarray}[0].${ib_imd5}" "${ib_file}")"
ib_source="$(jq -r ".${ib_iarray}[0].${ib_isource}" "${ib_file}" | htmlescape)"
-ib_tags="$(jq -r ".${ib_iarray}[0].${ib_itags}" "${ib_file}")"
-ib_tags_count=0
+ib_tags=($(jq -r ".${ib_iarray}[0].${ib_itags}" "${ib_file}"))
-. "${units}/ib_date.sh"
-. "${units}/ib_size.sh"
-. "${units}/ib_meta.sh"
+. "${units}/ib_date.zsh"
+. "${units}/ib_size.zsh"
+. "${units}/ib_meta.zsh"
output_text="$(printf "<b>%s</b>\n<b>ID:</b> <code>%s</code>" "${ib_name}" "${ib_id}")"
-if [ -n "${ib_date_text}" ]
+if [[ -n "${ib_date_text}" ]]
then
output_text="$(printf "%s\n<b>Date:</b> <code>%s</code>" "${output_text}" "${ib_date_text}")"
fi
-if [ -n "${ib_resolution_text}" ]
+if [[ -n "${ib_resolution_text}" ]]
then
output_text="$(printf "%s\n<b>Resolution:</b> %s" "${output_text}" "${ib_resolution_text}")"
fi
-if [ -n "${ib_size_text}" ]
+if [[ -n "${ib_size_text}" ]]
then
output_text="$(printf "%s\n<b>Size:</b> %s" "${output_text}" "${ib_size_text}")"
fi
-if [ -n "${ib_type_text}" ]
+if [[ -n "${ib_type_text}" ]]
then
output_text="$(printf "%s\n<b>Type:</b> %s" "${output_text}" "${ib_type_text}")"
fi
-if [ -n "${ib_rating}" ] && [ "${ib_rating}" != "null" ]
+if [[ -n "${ib_rating}" && "${ib_rating}" != "null" ]]
then
- set -- ${ib_ratings}
-
- while [ ${#} -ge 2 ]
+ while [[ ${#ib_ratings} -ge 2 ]]
do
- if [ "${ib_rating}" = "${1}" ]
+ if [[ "${ib_rating}" = "${ib_ratings[1]}" ]]
then
- output_text="$(printf "%s\n<b>Rating:</b> <code>%s</code>" "${output_text}" "${2}")"
+ output_text="$(printf "%s\n<b>Rating:</b> <code>%s</code>" "${output_text}" "${ib_ratings[2]}")"
break
else
- shift 2
+ ib_ratings=(${ib_ratings[@]:2})
fi
done
fi
-if [ -n "${ib_parent_id}" ] && [ "${ib_parent_id}" != "null" ] && [ "${ib_parent_id}" != "0" ]
+if [[ -n "${ib_parent_id}" && "${ib_parent_id}" != "null" && "${ib_parent_id}" != "0" ]]
then
output_text="$(printf "%s\n<b>Parent ID:</b> <code>%s</code>" "${output_text}" "${ib_parent_id}")"
fi
-if [ "${ib_has_children}" = "true" ]
+if [[ "${ib_has_children}" = "true" ]]
then
output_text="$(printf "%s\n<b>Has children:</b> yes" "${output_text}")"
fi
-if [ -n "${ib_md5}" ] && [ "${ib_md5}" != "null" ]
+if [[ -n "${ib_md5}" && "${ib_md5}" != "null" ]]
then
output_text="$(printf "%s\n<b>MD5:</b> <code>%s</code>" "${output_text}" "${ib_md5}")"
fi
-if [ -n "${ib_source}" ] && [ "${ib_source}" != "null" ]
+if [[ -n "${ib_source}" && "${ib_source}" != "null" ]]
then
if echo "${ib_source}" | grep -q -e "pixiv" -e "pximg"
then
ib_source="https://www.pixiv.net/artworks/$(printf "%s" "${ib_source##*/}" | cut -d '_' -f 1)"
fi
- if [ ${#ib_source} -le 2048 ]
+ if [[ ${#ib_source} -le 2048 ]]
then
output_text="$(printf "%s\n<b>Source:</b> %s" "${output_text}" "${ib_source}")"
fi
fi
-
-if [ -n "${ib_tags}" ] && [ "${ib_tags}" != "null" ]
-then
- set -- ${ib_tags}
- ib_tags_count=${#}
-fi
diff --git a/units/ib_preview.sh b/units/ib_preview.zsh
index b44a54c..ab70e87 100644
--- a/units/ib_preview.sh
+++ b/units/ib_preview.zsh
@@ -2,7 +2,7 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ "${ib_preview_url}" = "${ib_sample_url}" ]
+if [[ "${ib_preview_url}" = "${ib_sample_url}" ]]
then
ib_preview_url="${ib_error_url}"
ib_width="${ib_error_width}"
diff --git a/units/ib_sample.sh b/units/ib_sample.zsh
index 4e4ee94..4dede5c 100644
--- a/units/ib_sample.sh
+++ b/units/ib_sample.zsh
@@ -2,7 +2,7 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ "${ib_preview_url}" = "${ib_sample_url}" ]
+if [[ "${ib_preview_url}" = "${ib_sample_url}" ]]
then
ib_preview_url="${ib_error_url}"
ib_width="${ib_error_width}"
diff --git a/units/ib_search.sh b/units/ib_search.zsh
index 9013e2f..075da44 100644
--- a/units/ib_search.sh
+++ b/units/ib_search.zsh
@@ -2,14 +2,14 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
ib_board="${1}"
- . "${units}/ib_config.sh"
- . "${units}/ib_authconfig.sh"
+ . "${units}/ib_config.zsh"
+ . "${units}/ib_authconfig.zsh"
- if [ -z "${ib_data_url}" ]
+ if [[ -z "${ib_data_url}" ]]
then
output_title="Invalid arguments"
output_text="Unsupported image board"
@@ -34,43 +34,29 @@ else
set -- -a ${@}
fi
-if [ -n "${offset}" ]
+if [[ -n "${offset}" ]]
then
inline_page=${offset}
fi
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
inline_query="${@}"
- while getopts ${inline_options} inline_getopts
- do
- case "${inline_getopts}" in
- (a)
- ib_autopaging=0
- ;;
- (m)
- ib_metadata=0
- ;;
- (p)
- ib_preview=0
- ;;
- (q)
- ib_quick=0
- ;;
- (*)
- output_title="Invalid arguments"
- output_text="Unsupported options"
-
- return 0
- ;;
- esac
- done
+ if ! zparseopts -D -F -K -- \
+ a=ib_autopaging \
+ m=ib_metadata \
+ p=ib_preview \
+ q=ib_quick
+ then
+ output_title="Invalid arguments"
+ output_text="Unsupported options"
- shift $((OPTIND - 1))
+ return 0
+ fi
fi
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
ib_query="${@}"
shift ${#}
@@ -79,10 +65,10 @@ fi
ib_limit=${inline_limit}
ib_page=${inline_page}
-if [ -n "${ib_iwildcard}" ]
+if [[ -n "${ib_iwildcard}" ]]
then
ib_query="$(printf "%s" "${ib_query}" | sed "s/${ib_iwildcard}/\\\\${ib_iwildcard}/g" | tr '*' "${ib_iwildcard}")"
fi
ib_hash="$(printf "%s%s%s%s%s" "${user_id}" "${ib_mode}" "${ib_board}" "${ib_page}" "${ib_query}" | enhash)"
-. "${units}/ib_file.sh"
+. "${units}/ib_file.zsh"
diff --git a/units/ib_size.sh b/units/ib_size.zsh
index 9859e95..c9ef020 100644
--- a/units/ib_size.sh
+++ b/units/ib_size.zsh
@@ -2,12 +2,12 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ -n "${ib_file_size}" ] && [ "${ib_file_size}" != "null" ]
+if [[ -n "${ib_file_size}" && "${ib_file_size}" != "null" ]]
then
return 0
fi
-if [ -z "${ib_file_url}" ] || [ "${ib_file_url}" = "null" ]
+if [[ -z "${ib_file_url}" || "${ib_file_url}" = "null" ]]
then
return 0
fi
diff --git a/units/ib_token.sh b/units/ib_token.zsh
index 03f2abd..e5d3c14 100644
--- a/units/ib_token.sh
+++ b/units/ib_token.zsh
@@ -7,19 +7,19 @@ do
sleep 1
done
-if [ -f "${user_config}/${ib_config}/legacy" ]
+if [[ -f "${user_config}/${ib_config}/legacy" ]]
then
. "${user_config}/${ib_config}/legacy"
fi
-if [ -f "${user_config}/${ib_config}/timestamp" ]
+if [[ -f "${user_config}/${ib_config}/timestamp" ]]
then
ib_ctime=$(date +%s)
ib_mtime=$(cat "${user_config}/${ib_config}/timestamp")
- if [ $((ib_ctime - ib_mtime)) -gt ${ib_expire} ]
+ if [[ $((ib_ctime - ib_mtime)) -gt ${ib_expire} ]]
then
- if [ -n "${ib_lock}" ]
+ if [[ -n "${ib_lock}" ]]
then
. "${units}/ib_lock.sh" &
@@ -27,12 +27,12 @@ then
output_text="Try again in a few seconds"
notification_text="${output_title} ${output_text}"
else
- . "${units}/ib_auth.sh"
+ . "${units}/ib_auth.zsh"
fi
fi
fi
-if [ -f "${user_config}/${ib_config}/token" ]
+if [[ -f "${user_config}/${ib_config}/token" ]]
then
ib_header="${ib_authorization} $(cat "${user_config}/${ib_config}/token")"
fi
diff --git a/units/log.sh b/units/log.zsh
index 145b82f..2e5b972 100644
--- a/units/log.sh
+++ b/units/log.zsh
@@ -2,7 +2,7 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ -n "${no_logs}" ]
+if [[ -n "${no_logs}" ]]
then
return 0
fi
diff --git a/units/shorts_search.sh b/units/shorts_search.sh
deleted file mode 100644
index 427c935..0000000
--- a/units/shorts_search.sh
+++ /dev/null
@@ -1,110 +0,0 @@
-# Copyright (C) 2024-2025 Maria Lisina
-# Copyright (C) 2024-2025 Danil Lisin
-# SPDX-License-Identifier: Apache-2.0
-
-if test "${1}" -gt 0
-then
- inline_page=${1}
- shift
-else
- inline_page=1
- set -- -a ${@}
-fi
-
-if [ -n "${offset}" ]
-then
- inline_page=${offset}
-fi
-
-if [ -n "${1}" ]
-then
- inline_query="${@}"
-
- while getopts "aqrw" inline_getopts
- do
- case "${inline_getopts}" in
- (a)
- shorts_autopaging=0
- ;;
- (q)
- shorts_quick=0
- ;;
- (r)
- shorts_reverse=0
- ;;
- (w)
- shorts_word=0
- ;;
- (*)
- output_title="Invalid arguments"
- output_text="Unsupported options"
-
- return 0
- ;;
- esac
- done
-
- shift $((OPTIND - 1))
-fi
-
-if [ -n "${1}" ]
-then
- shorts_query="${@}"
- shift ${#}
-fi
-
-if [ -d "${short_config}" ]
-then
- if [ -n "${shorts_reverse}" ]
- then
- shorts_ls="-xtr"
- else
- shorts_ls="-xt"
- fi
-
- shorts="$(ls ${shorts_ls} "${short_config}")"
-fi
-
-set -- ${shorts}
-
-if [ ${#} -eq 0 ]
-then
- output_title="No shortcuts found"
- output_text="You have no saved shortcuts yet"
-
- return 0
-fi
-
-if [ -n "${shorts_query}" ]
-then
- if [ -n "${shorts_word}" ]
- then
- shorts_grep="-lqwFe"
- else
- shorts_grep="-lqiFe"
- fi
-
- for short in ${@}
- do
- if grep ${shorts_grep} "${shorts_query}" "${short_config}/${short}"
- then
- query_shorts="${query_shorts} ${short}"
- fi
- done
-
- set -- ${query_shorts}
-fi
-
-if [ ${#} -ge $(((inline_page - 1) * inline_limit + 1)) ]
-then
- shift $(((inline_page - 1) * inline_limit))
-else
- if [ -n "${offset}" ]
- then
- output_title="End of results"
- else
- output_title="No results found"
- fi
-
- output_text="Try different page or query"
-fi
diff --git a/units/shorts_search.zsh b/units/shorts_search.zsh
new file mode 100644
index 0000000..9d98d34
--- /dev/null
+++ b/units/shorts_search.zsh
@@ -0,0 +1,94 @@
+# Copyright (C) 2024-2025 Maria Lisina
+# Copyright (C) 2024-2025 Danil Lisin
+# SPDX-License-Identifier: Apache-2.0
+
+if test "${1}" -gt 0
+then
+ inline_page=${1}
+ shift
+else
+ inline_page=1
+ set -- -a ${@}
+fi
+
+if [[ -n "${offset}" ]]
+then
+ inline_page=${offset}
+fi
+
+if [[ -n "${1}" ]]
+then
+ inline_query="${@}"
+
+ if ! zparseopts -D -F -K -- \
+ a=shorts_autopaging \
+ q=shorts_quick \
+ r=shorts_reverse \
+ w=shorts_word
+ then
+ output_title="Invalid arguments"
+ output_text="Unsupported options"
+
+ return 0
+ fi
+fi
+
+if [[ -n "${1}" ]]
+then
+ shorts_query="${@}"
+ shift ${#}
+fi
+
+if [[ -d "${short_config}" ]]
+then
+ if [[ -n "${shorts_reverse}" ]]
+ then
+ shorts_ls="-xtr"
+ else
+ shorts_ls="-xt"
+ fi
+
+ shorts=($(ls ${shorts_ls} "${short_config}"))
+fi
+
+if [[ ${#shorts} -eq 0 ]]
+then
+ output_title="No shortcuts found"
+ output_text="You have no saved shortcuts yet"
+
+ return 0
+fi
+
+if [[ -n "${shorts_query}" ]]
+then
+ if [[ -n "${shorts_word}" ]]
+ then
+ shorts_grep="-lqwFe"
+ else
+ shorts_grep="-lqiFe"
+ fi
+
+ for short in ${shorts[@]}
+ do
+ if grep ${shorts_grep} "${shorts_query}" "${short_config}/${short}"
+ then
+ query_shorts=(${query_shorts[@]} ${short})
+ fi
+ done
+
+ shorts=(${query_shorts[@]})
+fi
+
+if [[ ${#shorts} -ge $(((inline_page - 1) * inline_limit + 1)) ]]
+then
+ shorts=(${shorts[@]:$(((inline_page - 1) * inline_limit))})
+else
+ if [[ -n "${offset}" ]]
+ then
+ output_title="End of results"
+ else
+ output_title="No results found"
+ fi
+
+ output_text="Try different page or query"
+fi
diff --git a/units/sn_auth.sh b/units/sn_auth.zsh
index 8bf8fc3..e441224 100644
--- a/units/sn_auth.sh
+++ b/units/sn_auth.zsh
@@ -2,10 +2,10 @@
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
sn_key="${1}"
-elif [ -f "${user_config}/saucenao" ]
+elif [[ -f "${user_config}/saucenao" ]]
then
sn_key="$(cat "${user_config}/saucenao")"
return 0
@@ -30,8 +30,8 @@ then
output_text="Failed to process request"
log_text="sn_auth (${update_id}): ${output_text}"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
@@ -41,19 +41,19 @@ then
output_text="An unknown error occurred"
log_text="sn_auth (${update_id}): ${output_text}"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
-if [ "$(jq -r '.header.user_id' "${sn_file}")" = "null" ]
+if [[ "$(jq -r '.header.user_id' "${sn_file}")" = "null" ]]
then
output_text="Invalid API Key"
log_text="sn_auth (${update_id}): ${output_text}"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
diff --git a/units/sn_get.sh b/units/sn_get.zsh
index 0adb1f7..d47658a 100644
--- a/units/sn_get.sh
+++ b/units/sn_get.zsh
@@ -5,13 +5,13 @@
message_id="$(jq -r '.message.reply_to_message.message_id' "${update}")"
file_id="$(jq -r '.message.reply_to_message.photo.[1].file_id' "${update}")"
-if [ "${message_id}" = "null" ] || [ "${message_id}" = "${message_thread_id}" ]
+if [[ "${message_id}" = "null" || "${message_id}" = "${message_thread_id}" ]]
then
output_text="You must use this command in reply to an image"
return 0
fi
-if [ "${file_id}" = "null" ]
+if [[ "${file_id}" = "null" ]]
then
output_text="Could not find an image in replied message"
return 0
@@ -32,8 +32,8 @@ then
output_text="Failed to get the image file"
log_text="getFile (${update_id}): Failed to access Telegram Bot API"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
@@ -43,42 +43,42 @@ then
output_text="An unknown error occurred"
log_text="getFile (${update_id}): An unknown error occurred"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
-if [ "$(jq -r '.ok' "${output_file}")" != "true" ]
+if [[ "$(jq -r '.ok' "${output_file}")" != "true" ]]
then
output_text="Failed to get the image file"
error_description="$(jq -r '.description' "${output_file}")"
- if [ "${error_description}" != "null" ]
+ if [[ "${error_description}" != "null" ]]
then
log_text="getFile (${update_id}): ${error_description}"
else
log_text="getFile (${update_id}): An unknown error occurred"
fi
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
file_path="$(jq -r '.result.file_path' "${output_file}")"
-if [ "${api_address}" = "${local_address}" ] && ! ls "${file_path}" > /dev/null
+if [[ "${api_address}" = "${local_address}" ]] && ! ls "${file_path}" > /dev/null
then
output_text="There is an error on the bot side, please contact bot deployer"
log_text="Error: sn_get: Cannot access Telegram Bot API working directory"
- . "${units}/log.sh"
+ . "${units}/log.zsh"
return 0
fi
-if [ "${api_address}" = "${default_address}" ]
+if [[ "${api_address}" = "${default_address}" ]]
then
output_file="${cache}/${update_id}_file.jpg"
dump="${dump} ${output_file##*/}"
@@ -93,26 +93,26 @@ then
output_text="Failed to download the image file"
log_text="getFile (${update_id}): Failed to access Telegram Bot API"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
- if [ "$(jq -r '.ok' "${output_file}")" = "false" ]
+ if [[ "$(jq -r '.ok' "${output_file}")" = "false" ]]
then
output_text="Failed to download the image file"
error_description="$(jq -r '.description' "${output_file}")"
- if [ "${error_description}" != "null" ]
+ if [[ "${error_description}" != "null" ]]
then
log_text="getFile (${update_id}): ${error_description}"
else
log_text="getFile (${update_id}): An unknown error occurred"
fi
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
@@ -121,4 +121,4 @@ then
fi
sn_query="file=@${file_path}"
-. "${units}/sn_search.sh"
+. "${units}/sn_search.zsh"
diff --git a/units/sn_search.sh b/units/sn_search.zsh
index bfdd047..2c6bd45 100644
--- a/units/sn_search.sh
+++ b/units/sn_search.zsh
@@ -26,8 +26,8 @@ then
output_text="Failed to process request"
log_text="sn_search (${update_id}): ${output_text}"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
@@ -37,17 +37,17 @@ then
output_text="An unknown error occurred"
log_text="sn_search (${update_id}): ${output_text}"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
return 0
fi
-if [ "$(jq -r '.header.status' "${sn_file}")" != "0" ]
+if [[ "$(jq -r '.header.status' "${sn_file}")" != "0" ]]
then
output_text="Error: <code>$(jq -r '.header.message' "${sn_file}" | htmlescape)</code>"
log_text="sn_search (${update_id}): $(jq -r '.header.message' "${sn_file}")"
- . "${units}/log.sh"
- . "${units}/dump.sh"
+ . "${units}/log.zsh"
+ . "${units}/dump.zsh"
fi
diff --git a/units/user.sh b/units/user.sh
deleted file mode 100644
index 69c7dd7..0000000
--- a/units/user.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (C) 2024-2025 Maria Lisina
-# Copyright (C) 2024-2025 Danil Lisin
-# SPDX-License-Identifier: Apache-2.0
-
-aliases="${files}/aliases.txt"
-blacklist="${files}/blacklist.txt"
-whitelist="${files}/whitelist.txt"
-
-positional_parameters="${@}"
-
-if [ -s "${aliases}" ] && alias="$(grep -x "${user_id} .*" "${aliases}")"
-then
- user_id="$(printf "%s" "${alias}" | parameter 2)"
-fi
-
-if [ -s "${blacklist}" ] && grep -qx "${user_id}" "${blacklist}"
-then
- exit 0
-fi
-
-if [ -s "${whitelist}" ] && ! grep -qx "${user_id}" "${whitelist}"
-then
- exit 0
-fi
-
-user_config="${config}/${user_id}"
-set -- ${positional_parameters}
diff --git a/units/user.zsh b/units/user.zsh
new file mode 100644
index 0000000..f861301
--- /dev/null
+++ b/units/user.zsh
@@ -0,0 +1,24 @@
+# Copyright (C) 2024-2025 Maria Lisina
+# Copyright (C) 2024-2025 Danil Lisin
+# SPDX-License-Identifier: Apache-2.0
+
+aliases_file="${files}/aliases.txt"
+blacklist_file="${files}/blacklist.txt"
+whitelist_file="${files}/whitelist.txt"
+
+if [[ -s "${aliases_file}" ]] && alias="$(grep -x "${user_id} .*" "${aliases_file}")"
+then
+ user_id="$(printf "%s" "${alias}" | parameter 2)"
+fi
+
+if [[ -s "${blacklist_file}" ]] && grep -qx "${user_id}" "${blacklist_file}"
+then
+ exit 0
+fi
+
+if [[ -s "${whitelist_file}" ]] && ! grep -qx "${user_id}" "${whitelist_file}"
+then
+ exit 0
+fi
+
+user_config="${config}/${user_id}"
diff --git a/whitelist.sh b/whitelist.zsh
index df9ce6e..5633745 100755
--- a/whitelist.sh
+++ b/whitelist.zsh
@@ -1,4 +1,4 @@
-#!/usr/bin/env dash
+#!/usr/bin/env zsh
#
# Copyright (C) 2024-2025 Maria Lisina
# Copyright (C) 2024-2025 Danil Lisin
@@ -14,7 +14,7 @@ dir="${0%/*}"
files="${dir}/files"
list="${files}/whitelist.txt"
-if [ -n "${1}" ]
+if [[ -n "${1}" ]]
then
action="${1}"
@@ -36,7 +36,7 @@ else
help=0
fi
-if [ -n "${help}" ]
+if [[ -n "${help}" ]]
then
echo "Whitelist Manager" \
"\n\nUsage: ${0} [action] [ID]" \
@@ -57,7 +57,7 @@ do
fi
done
-if [ -n "${missing}" ]
+if [[ -n "${missing}" ]]
then
echo "Missing dependencies:${missing}" \
"\nFor more information follow: https://command-not-found.com/"
@@ -66,7 +66,7 @@ fi
for function in cat grep mkdir sed
do
- if busybox ${function} --help
+ if busybox ${function} --help > /dev/null
then
alias ${function}="busybox ${function}"
else
@@ -74,7 +74,7 @@ do
fi
done
-if [ -n "${missing}" ]
+if [[ -n "${missing}" ]]
then
echo "Missing BusyBox functions:${missing}" \
"\nUpdate your BusyBox or get a version with all the required functions"
@@ -83,7 +83,7 @@ fi
case "${action}" in
(add | del)
- if [ -n "${1}" ]
+ if [[ -n "${1}" ]]
then
user_id="${1}"
@@ -104,13 +104,13 @@ esac
case "${action}" in
(show)
- if [ -s "${list}" ]
+ if [[ -s "${list}" ]]
then
cat "${list}"
fi
;;
(add)
- if [ -s "${list}" ] && grep -qxe "${user_id}" "${list}"
+ if [[ -s "${list}" ]] && grep -qxe "${user_id}" "${list}"
then
echo "User ID ${user_id} is already in the whitelist"
exit 1
@@ -119,7 +119,7 @@ case "${action}" in
printf "%s\n" "${user_id}" >> "${list}"
;;
(del)
- if [ -s "${list}" ]
+ if [[ -s "${list}" ]]
then
sed -e "s/^${user_id}$//" -e '/^$/d' -i "${list}"
fi