Better plugin and answer examples
This commit is contained in:
parent
1b8b17ae8a
commit
b49934972f
34
chat/answer
34
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() {
|
||||
if (( "$1" < 1 )); then
|
||||
echo '1'
|
||||
else
|
||||
shuf -n1 -i "1-$1"
|
||||
fi
|
||||
}
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
if grep -q -- "$1" "ignore"; then
|
||||
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
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
bodqhrohro
|
||||
MiniRoboDancer
|
||||
kosc
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue