diff --git a/chat/answer b/chat/answer index 33a93fb..4c1aba8 100755 --- a/chat/answer +++ b/chat/answer @@ -1,21 +1,24 @@ #!/bin/bash -# simple chat bot -# with sending images to an external program -# and ignoring some nicknames +# Simple chat bot +# with sending images to an external programme. random() { - shuf -n1 -i "1-$1" + if (( "$1" < 1 )); then + echo '1' + else + shuf -n1 -i "1-$1" + fi } cd "$(dirname "$0")" -if grep -q -- "$1" "ignore"; then -exit 0 +if (grep -q -- "$1" "ignore"); then + exit 0 fi -echo -n "$1: " -from=$(echo "$1" | tr -d '$`|<>') +printf "%s" "$1: " +from=$(printf "%s\n" "$1" | tr -d '$`|<>') # Second argument shows whether user is an admin (useless). shift 2 @@ -31,22 +34,23 @@ if [[ "$string" == *http*://* ]]; then # Makes it a bit more human (time to find a link?). sleep 1 sed -e '/https*:\/\//!d' ./frs.txt | sed -n "$(random "$amount")p" - img="$(echo "$string" | sed -ne 's|.*\(https*://[^ \"()<>]*\).*|\1|g;1p')" - ns="$(echo "$string" | sed -e "s|$img||g")" - cl="$(wget --spider -S $(eval echo '$img') 2>&1)" - if [[ $(echo "$cl" | sed -e '/Content-Type/!d;/image\//!d') ]]; then + img="$(printf "%s\n" "$string" | sed -ne 's|.*\(https*://[^ \"()<>]*\).*|\1|g;1p')" + ns="$(printf "%s\n" "$string" | sed -e "s|$img||g")" + cl="$(wget --spider -S $(eval printf '%s\n' '$img') 2>&1)" + if [[ $(printf "%s\n" "$cl" | sed -e '/Content-Type/!d;/image\//!d') ]]; then #echo 'posting' - #echo "$img" "$from" >> ~/data/pictures + printf "%s\n" "$img $from" >> ../data/pictures fi else - amount="$(sed -e '/https*:\/\//d' ./frs.txt | wc -l)" + # Exclude last two entries from the amount. + amount="$(($(sed -e '/https*:\/\//d' ./frs.txt | wc -l) - 2))" answer="$(sed -e '/https*:\/\//d' ./frs.txt | sed -ne "s/;;\\\n/\n/g;$(random "$amount")p")" # Makes it a bit more human. - sleep "$(echo "${#answer} * 0.1" | bc -l)" - echo "$answer" + sleep "$(echo "${#answer} * 0.15" | bc -l)" + printf "%s\n" "$answer" fi if [[ ${#string} -lt 7 ]]; then exit 0 fi -echo "$string" | sed -e '{:q;N;s/\n/;;\\n/g;t q}' >> ./frs.txt +printf "%s\n" "$string" | sed -e '{:q;N;s/\n/;;\\n/g;t q}' >> ./frs.txt exit 0 diff --git a/chat/ignore b/chat/ignore deleted file mode 100644 index dfa2d57..0000000 --- a/chat/ignore +++ /dev/null @@ -1,3 +0,0 @@ -bodqhrohro -MiniRoboDancer -kosc diff --git a/plugins/example b/plugins/example index e8289da..2edcbcb 100755 --- a/plugins/example +++ b/plugins/example @@ -1,11 +1,11 @@ -#!/bin/bash +#!/bin/sh -user="$1" # nickname -admin="$2" # if he is an admin +user="$1" # User nickname. +admin="$2" # If one is an admin. if [ "$admin" != 'true' ]; then - echo "$user: you are not an admin" + printf "%s\n" "$user: you are not an admin" else - echo "$user: you are an admin" + printf "%s\n" "$user: you are an admin" fi