This commit is contained in:
Your Name 2022-11-30 16:29:37 -07:00
parent 36093f4c79
commit 52a0a80cc3
7 changed files with 227 additions and 0 deletions

12
Dockerfile Normal file
View File

@ -0,0 +1,12 @@
FROM ubuntu
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update;apt install jq toot anacron postgresql -y
#RUN cp -f /usr/share/zoneinfo/US/Mountain /etc/localtime
RUN cp -f /usr/share/zoneinfo/Atlantic/Reykjavik /etc/localtime
COPY crontab /
COPY bot.sh /opt/
COPY bot.png /opt/
#RUN crontab /crontab
RUN mkdir -p /root/.config/toot
COPY config.json /root/.config/toot/
CMD bash /opt/bot.sh daemon

BIN
bot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

118
bot.sh Normal file
View File

@ -0,0 +1,118 @@
#!/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

75
bot.v1 Normal file
View File

@ -0,0 +1,75 @@
#!/bin/bash
#############################
ENDPOINT='detroitriotcity.com'
SQL_USER='root'
SQL_PASS='sql'
SQL_HOST='127.0.0.1'
SQL_DATABASE='detroitriotcity'
users=( drunkenpriapus ThatWouldBeTelling chilliestbro Rasterman ArdainianRight rlier23 Leyonhjelm ChristiJunior verita84 admin cyberanathema blockbot )
STATS_MESSAGE="Daily Block Stats for: $ENDPOINT"
############################
cd /opt
TIME_STAMP="`date +%y-%m-%d` `date +%H:%M`"
TIME=`echo $TIME_STAMP | sed 's/.$//'`
blocks(){
data=''
echo $TIME_STAMP $TIME
echo "select * from activities where data->>'type' = 'Block';" | PGPASSWORD=$SQL_PASS psql -h $SQL_HOST -U $SQL_USER $SQL_DATABASE | grep "$TIME" > /tmp/list.txt
readarray list -d '|' < /tmp/list.txt
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`"
message="$blocker blocked $blocked"
if [ -n "$1" ]; then
echo "$message"
else
toot post "$message" -m ./bot.png
fi
done
}
scalps(){
data=$STATS_MESSAGE
for i in "${users[@]}"
do
:
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`! "
done
if [ -n "$1" ]; then
echo "$data"
else
toot post "$data"
fi
}
help(){
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" = "blocks" ]; then
blocks "$2"
elif [ "$1" = "scalps" ]; then
scalps "$2"
else
help
fi

18
config.json Normal file
View File

@ -0,0 +1,18 @@
{
"active_user": "auska@pooper.social",
"apps": {
"pooper.social": {
"base_url": "https://pooper.social",
"client_id": "ckB0MYu9zw2orlCguCmlRa9un7zXER1AEH_7sW3XGHU",
"client_secret": "e4QbDf3DgLpBXC9g5mbGiCZyO82rwO5fU9YLl10X-EU",
"instance": "pooper.social"
}
},
"users": {
"auska@pooper.social": {
"access_token": "F_lEeFj4xQv_Ln-5toGcB-x9v5Lb4iwNZfaeJ_htD8s",
"instance": "pooper.social",
"username": "auska"
}
}
}

2
crontab Normal file
View File

@ -0,0 +1,2 @@
58 * * * * bash /opt/bot.sh blocks
00 00 * * * bash /opt/bot.sh scalps

2
windows-task.bat Normal file
View File

@ -0,0 +1,2 @@
@echo off
docker-compose -f e:\docker\docker-compose-1.yml up -d blockbot