From 984413c47c20392907d234e3b326e1813d12e0d5 Mon Sep 17 00:00:00 2001 From: HonusBot Date: Sun, 16 May 2021 00:10:10 +0200 Subject: [PATCH] Handle errors --- honusbot-cli.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/honusbot-cli.sh b/honusbot-cli.sh index 9bf2fdf..a27e1ab 100755 --- a/honusbot-cli.sh +++ b/honusbot-cli.sh @@ -14,13 +14,11 @@ display_command_after="true" download_url_to_stdin=true if [ -x "$(command -v viu)" ]; then - echo "Found viu" picture_save_to_temp_command="tee ${temp_path}/temp-honus.bin" display_command_pipe="cat > /dev/null" display_command_after="viu ${temp_path}/temp-honus.bin" download_url_to_stdin=true elif [ -x "$(command -v feh)" ]; then - echo "Found feh" display_command_pipe="xargs --max-args=1 --no-run-if-empty feh --title \"HonusBot CLI\" --auto-zoom" display_command_after="true" download_url_to_stdin=false @@ -31,6 +29,10 @@ if [ "$download_url_to_stdin" = true ]; then picture_download_command="xargs --max-args=1 --no-run-if-empty curl -s --location" fi -curl -s --location --request POST 'https://api.ignuranza.net/remote-command-api/command' --header 'Content-Type: application/json' --header 'User-Agent: RcAPI/1.2' --data-raw "{\"botName\": \"AstralNetworkHonusBot\", \"botPassword\": \"KixdujXD37898ZSy893\", \"command\": \"${command}\", \"replyToUserId\": 0, \"senderUserId\": 1237252783, \"chatId\": 1237252783, \"queryText\": \"$args\", \"rawSingleArgument\": false}" | jq -r ".imageUrl" | eval "${picture_download_command}" | eval "${picture_save_to_temp_command}" | eval "${display_command_pipe}" +{ # try + curl -s --location --request POST 'https://api.ignuranza.net/remote-command-api/command' --header 'Content-Type: application/json' --header 'User-Agent: RcAPI/1.2' --data-raw "{\"botName\": \"AstralNetworkHonusBot\", \"botPassword\": \"KixdujXD37898ZSy893\", \"command\": \"${command}\", \"replyToUserId\": 0, \"senderUserId\": 1237252783, \"chatId\": 1237252783, \"queryText\": \"$args\", \"rawSingleArgument\": false}" | jq -r ".imageUrl" | eval "${picture_download_command}" | eval "${picture_save_to_temp_command}" | eval "${display_command_pipe}" && + eval "${display_command_after}" +} 2>/dev/null || { # catch + echo "Error/Not found" +} -eval "${display_command_after}"