119 lines
2.9 KiB
Bash
119 lines
2.9 KiB
Bash
#!/bin/bash
|
|
#############################
|
|
ENDPOINT='pooper.social'
|
|
SQL_USER='root'
|
|
SQL_PASS='sql'
|
|
SQL_HOST='postgresql'
|
|
SQL_DATABASE='pooper'
|
|
STATS_MESSAGE="Daily Block Stats for: $ENDPOINT"
|
|
############################
|
|
cd /opt
|
|
|
|
blocks(){
|
|
#TIME_STAMP="`date +%y-%m-%d` `date +%H`"
|
|
TIME_STAMP="`date +%y-%m-%d` `date +%H:%M`"
|
|
TIME=`echo $TIME_STAMP | sed 's/.$//'`
|
|
data=''
|
|
|
|
echo "select * from activities where data->>'type' = 'Block';" | PGPASSWORD=$SQL_PASS psql -h $SQL_HOST -U $SQL_USER $SQL_DATABASE | grep "$TIME" > /tmp/list
|
|
|
|
readarray -t list < /tmp/list
|
|
|
|
for i in "${list[@]}"
|
|
do
|
|
:
|
|
json=`echo $i | cut -d '{' -f2-3 | cut -d '}' -f1 | sed '1 i\{' | sed '$a } '`
|
|
|
|
blocker="`echo $json | jq -r .actor | cut -d '/' -f5`@`echo $json | jq -r .actor | cut -d '/' -f3`"
|
|
|
|
blocked="@`echo $json | jq -r .object | cut -d '/' -f5`@`echo $json | jq -r .object | cut -d '/' -f3`"
|
|
|
|
profile=`echo $json | jq -r .actor`
|
|
|
|
message="BLOCK ALERT! $blocker blocked $blocked. Profile is available at: $profile"
|
|
|
|
|
|
if [ -n "$1" ]; then
|
|
echo $message
|
|
else
|
|
echo $message
|
|
toot post "$message" -m ./bot.png
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
scalps(){
|
|
data=$STATS_MESSAGE
|
|
users=( $(echo "select nickname from users where ap_id like '%${ENDPOINT}%';" | PGPASSWORD=sql psql -h $SQL_HOST -U $SQL_USER $SQL_DATABASE --csv | egrep -vi 'relay|nickname|internal.fetch') );
|
|
|
|
for i in "${users[@]}"
|
|
do
|
|
:
|
|
number=`echo "select * from activities where data->>'type' = 'Block';" | PGPASSWORD=$SQL_PASS psql -h $SQL_HOST -U $SQL_USER $SQL_DATABASE | grep -i $i | cut -d '"' -f18 | grep -iv $ENDPOINT | wc -l`
|
|
if [ $number -gt 0 ];
|
|
then
|
|
data=$data" @$i: ` echo "select * from activities where data->>'type' = 'Block';" | PGPASSWORD=$SQL_PASS psql -h $SQL_HOST -U $SQL_USER $SQL_DATABASE | grep -i $i | cut -d '"' -f18 | grep -iv $ENDPOINT | wc -l`! "
|
|
fi
|
|
done
|
|
|
|
if [ -n "$1" ]; then
|
|
echo "$data"
|
|
else
|
|
toot post "$data"
|
|
fi
|
|
}
|
|
|
|
|
|
|
|
background_daemon(){
|
|
echo;echo "BlockBot running in Daemon Mode";echo;echo
|
|
while true
|
|
do
|
|
echo "#######################################"
|
|
echo "Current Time: `date`"
|
|
|
|
if [[ `date | cut -d ':' -f2 | tail -c2` == *"9"* ]]; then
|
|
echo "Checking for new blocks.......";echo
|
|
blocks
|
|
fi
|
|
if [[ `date` == *"10:10:"* ]]; then
|
|
echo "Sending Block Report.......";echo
|
|
scalps
|
|
fi
|
|
blocks print
|
|
echo "Sleeping for 50......"
|
|
echo "#######################################";
|
|
sleep 50
|
|
done
|
|
}
|
|
background(){
|
|
if [[ `date` == *":00"* ]]; then
|
|
background_daemon
|
|
else
|
|
echo "Waiting for time to be in sync...."
|
|
sleep 1
|
|
background
|
|
fi
|
|
}
|
|
|
|
help(){
|
|
echo;echo "bot.sh daemon"
|
|
echo;echo "bot.sh blocks"
|
|
echo;echo "bot.sh blocks print"
|
|
echo "bot.sh scalps"
|
|
echo "bot.sh scalps print"
|
|
echo "bot.sh help";echo;echo
|
|
}
|
|
|
|
if [ "$1" = "daemon" ]; then
|
|
background
|
|
elif [ "$1" = "blocks" ]; then
|
|
blocks "$2"
|
|
elif [ "$1" = "scalps" ]; then
|
|
scalps "$2"
|
|
else
|
|
help
|
|
fi
|