aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rwxr-xr-xbot.zsh70
-rw-r--r--units/sn_auth.zsh3
3 files changed, 70 insertions, 6 deletions
diff --git a/README.md b/README.md
index 34edad6..19f9a20 100644
--- a/README.md
+++ b/README.md
@@ -79,7 +79,8 @@ Options:
-d <secs> Head request connetion timeout, max: 5, default: 2 secs
-f <secs> Connrefused timeout, max: 2, default: none
-n <addr> Proxy server for Telegram Bot API
- -x <addr> Proxy server for Image Boards API/SauceNAO
+ -x <addr> Proxy server for Image Boards/SauceNAO API
+ -k <key> SauceNAO API Key for public use
Cache modes:
none No cache reuse
diff --git a/bot.zsh b/bot.zsh
index 8ffd2c4..9703263 100755
--- a/bot.zsh
+++ b/bot.zsh
@@ -76,7 +76,7 @@ busybox=(
if [[ -n "${1}" ]]
then
- while getopts ha:olg:r:m:t:s:cjqui:e:d:f:n:x: opts
+ while getopts ha:olg:r:m:t:s:cjqui:e:d:f:n:x:k: opts
do
case "${opts}" in
(h)
@@ -136,6 +136,9 @@ then
(x)
external_proxy="${OPTARG}"
;;
+ (k)
+ sn_key="${OPTARG}"
+ ;;
(*)
echo "Unrecognized options" \
"\nSee '${0} -h'"
@@ -172,7 +175,8 @@ then
"\n -d <secs>\tHead request connetion timeout, max: 5, default: 2 secs" \
"\n -f <secs>\tConnrefused timeout, max: 2, default: none" \
"\n -n <addr>\tProxy server for Telegram Bot API" \
- "\n -x <addr>\tProxy server for Image Boards API/SauceNAO" \
+ "\n -x <addr>\tProxy server for Image Boards/SauceNAO API" \
+ "\n -k <key>\tSauceNAO API Key for public use" \
"\n\nCache modes:" \
"\n none\t\tNo cache reuse" \
"\n normal\tReuse inline results and posts cache" \
@@ -594,8 +598,8 @@ else
if [[ -z "${profilephoto}" || "${profilephoto}" == "null" ]]
then
log_text="Error: Bot must have profile photo to run source command check"
-
. "${units}/log.zsh"
+
exit 1
fi
@@ -621,8 +625,8 @@ else
if ! jq -e '.' "${cache}/getFile.json" > /dev/null
then
log_text="getFile: An unknown error occurred"
-
. "${units}/log.zsh"
+
exit 1
fi
@@ -687,6 +691,62 @@ else
fi
fi
+if [[ -n "${sn_key}" ]]
+then
+ if ! curl --connect-timeout ${connrefused_timeout} \
+ --data-urlencode "output_type=2" \
+ --data-urlencode "api_key=${sn_key}" \
+ --get \
+ --max-time ${external_timeout} \
+ --output "${cache}/search.json" \
+ --proxy "${external_proxy}" \
+ --retry 1 \
+ --retry-connrefused \
+ --retry-max-time $((external_timeout - connrefused_timeout)) \
+ --silent \
+ --user-agent "${useragent}" \
+ "https://saucenao.com/search.php"
+ then
+ log_text="sn_search: Failed to access SauceNAO API"
+ . "${units}/log.zsh"
+
+ exit 1
+ fi
+
+ if ! jq -e '.' "${cache}/search.json" > /dev/null
+ then
+ log_text="sn_search: An unknown error occurred"
+ . "${units}/log.zsh"
+
+ exit 1
+ fi
+
+ sn_status="$(jq -r '.header.status' "${cache}/search.json")"
+
+ case "${sn_status}" in
+ (-3)
+ ;;
+ (-2)
+ log_text="sn_search: Rate limit exceeded, try again later"
+ . "${units}/log.zsh"
+
+ exit 1
+ ;;
+ (-1)
+ log_text="sn_search: Invalid API Key"
+ . "${units}/log.zsh"
+
+ exit 1
+ ;;
+ (*)
+ log_text="sn_search: An unknown error occurred"
+ . "${units}/log.zsh"
+
+ exit 1
+ ;;
+ esac
+fi
+
log_text="Loading lists..."
. "${units}/log.zsh"
@@ -776,8 +836,8 @@ do
if ! jq -c '.result.[0]' "${cache}/getUpdates.json" > "${update}"
then
log_text="Failed to write update file ${update_id}.json"
-
. "${units}/log.zsh"
+
continue
fi
diff --git a/units/sn_auth.zsh b/units/sn_auth.zsh
index 39523ba..4aa8cce 100644
--- a/units/sn_auth.zsh
+++ b/units/sn_auth.zsh
@@ -9,6 +9,9 @@ elif [[ -f "${user_config}/saucenao" ]]
then
sn_key="$(< "${user_config}/saucenao")"
return 0
+elif [[ -n "${sn_key}" ]]
+then
+ return 0
else
output_text="You must provide your SauceNAO API Key before you can use SauceNAO"
return 0