Better plugin and answer examples

This commit is contained in:
Alexei Sorokin 2016-08-19 21:08:03 +03:00
parent 1b8b17ae8a
commit b49934972f
3 changed files with 26 additions and 25 deletions

View File

@ -1,21 +1,24 @@
#!/bin/bash #!/bin/bash
# simple chat bot # Simple chat bot
# with sending images to an external program # with sending images to an external programme.
# and ignoring some nicknames
random() { random() {
shuf -n1 -i "1-$1" if (( "$1" < 1 )); then
echo '1'
else
shuf -n1 -i "1-$1"
fi
} }
cd "$(dirname "$0")" cd "$(dirname "$0")"
if grep -q -- "$1" "ignore"; then if (grep -q -- "$1" "ignore"); then
exit 0 exit 0
fi fi
echo -n "$1: " printf "%s" "$1: "
from=$(echo "$1" | tr -d '$`|<>') from=$(printf "%s\n" "$1" | tr -d '$`|<>')
# Second argument shows whether user is an admin (useless). # Second argument shows whether user is an admin (useless).
shift 2 shift 2
@ -31,22 +34,23 @@ if [[ "$string" == *http*://* ]]; then
# Makes it a bit more human (time to find a link?). # Makes it a bit more human (time to find a link?).
sleep 1 sleep 1
sed -e '/https*:\/\//!d' ./frs.txt | sed -n "$(random "$amount")p" sed -e '/https*:\/\//!d' ./frs.txt | sed -n "$(random "$amount")p"
img="$(echo "$string" | sed -ne 's|.*\(https*://[^ \"()<>]*\).*|\1|g;1p')" img="$(printf "%s\n" "$string" | sed -ne 's|.*\(https*://[^ \"()<>]*\).*|\1|g;1p')"
ns="$(echo "$string" | sed -e "s|$img||g")" ns="$(printf "%s\n" "$string" | sed -e "s|$img||g")"
cl="$(wget --spider -S $(eval echo '$img') 2>&1)" cl="$(wget --spider -S $(eval printf '%s\n' '$img') 2>&1)"
if [[ $(echo "$cl" | sed -e '/Content-Type/!d;/image\//!d') ]]; then if [[ $(printf "%s\n" "$cl" | sed -e '/Content-Type/!d;/image\//!d') ]]; then
#echo 'posting' #echo 'posting'
#echo "$img" "$from" >> ~/data/pictures printf "%s\n" "$img $from" >> ../data/pictures
fi fi
else 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")" answer="$(sed -e '/https*:\/\//d' ./frs.txt | sed -ne "s/;;\\\n/\n/g;$(random "$amount")p")"
# Makes it a bit more human. # Makes it a bit more human.
sleep "$(echo "${#answer} * 0.1" | bc -l)" sleep "$(echo "${#answer} * 0.15" | bc -l)"
echo "$answer" printf "%s\n" "$answer"
fi fi
if [[ ${#string} -lt 7 ]]; then if [[ ${#string} -lt 7 ]]; then
exit 0 exit 0
fi 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 exit 0

View File

@ -1,3 +0,0 @@
bodqhrohro
MiniRoboDancer
kosc

View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/sh
user="$1" # nickname user="$1" # User nickname.
admin="$2" # if he is an admin admin="$2" # If one is an admin.
if [ "$admin" != 'true' ]; then if [ "$admin" != 'true' ]; then
echo "$user: you are not an admin" printf "%s\n" "$user: you are not an admin"
else else
echo "$user: you are an admin" printf "%s\n" "$user: you are an admin"
fi fi