From e55219115930fc4c0505cef6a5f876a402562ed3 Mon Sep 17 00:00:00 2001 From: Asa Venton Date: Mon, 19 Oct 2020 17:17:39 +0100 Subject: Add additional checks, adjust help output to reflect new name of command in the IRC bot. --- oedquery.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'oedquery.sh') diff --git a/oedquery.sh b/oedquery.sh index 6bdad65..50e9fd2 100755 --- a/oedquery.sh +++ b/oedquery.sh @@ -16,6 +16,10 @@ _jq() { _getdata() { # Take everything after final space as the requested word (assuming everything before the last space is a flag) word=$(echo $word | sed 's/.* //') + if [[ "$word" = "null" ]] + then + echo "Missing word. Usage: !oed [option] [word]. Use -h for help." + fi lemmasUrl=https://od-api.oxforddictionaries.com/api/v2/lemmas/$language/$word # get lemmas to link an inflected form back to its headword (required to get definition) result=$(eval curl $OPTS $lemmasUrl) @@ -94,7 +98,12 @@ _thes() { _audio() { _getdata output=$(echo "${result}" | jq '.results[0].lexicalEntries[0].entries[0].pronunciations[0].audioFile' | tr -d \") - echo $output + if [[ "$output" != "null" ]] + then + echo $output + else + echo "No audio file found." + fi exit 0 } @@ -109,6 +118,7 @@ _wod() { # Remove surrounding quotes definition=$(echo "${definition:1: -1}") lexicalCategory=$(echo "${lexicalCategory:1: -1}") + # Don't output example sentence if not returned from OED if [[ "$examplePhrase" != "null" ]] then output=$word" - "$lexicalCategory" - "$definition" - "$examplePhrase @@ -120,7 +130,7 @@ _wod() { } _help() { - echo "Usage: !oeddefine [option] [word]. Options: -h help -t thesaurus -e etymology -d define -a audio -s source" + echo "Usage: !oed [option] [word]. Options: -h help -t thesaurus -e etymology -d define -a audio -s source" exit 0 } -- cgit v1.2.3