You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9 KiB
Bash

#!/bin/bash
# fanta <fanta@56k.es> - https://git.56k.es/fanta/santiago
# dependencies: toot
scriptDir="/home/fanta/repos/santiago" # The bot path
user=$(whoami)
opt="$1"
version="0.1"
fileNotifications="/tmp/notifications.txt"
function who { if [ "$(whoami)" = "root" ]; then exit; fi }
function checkDeps {
tootValue="$(toot | head -1)"
if [[ $tootValue != "toot - a Mastodon CLI client" ]]; then echo "Please install toot"; exit; fi
}
function login {
toot login
}
function run {
toot notifications -m --no-color | grep -i "ID " | cut -d " " -f 2 | head -20 > $fileNotifications
while read not; do
toot=$(toot thread "$not" | grep -i "@caminosantiago añade " | head -1)
if [ -z "$toot" ]
then echo "Toot no valido"
else
#toot thread "$not"
walkerName=$(toot thread "$not" --no-color | head -2 | tail -1 | cut -d "@" -f 2,3 | cut -d " " -f 1)
walkerDate=$(toot thread "$not" --no-color | head -2 | tail -1 | cut -d "@" -f 2,3 | rev | cut -d " " -f 1,2 | rev)
walkerFile=$(echo "$scriptDir/walkers/$walkerName")
walkerKm=3
if [ -f "$walkerFile" ]; then
walkerDate2=$(cat $walkerFile | grep "$walkerDate" | head -1)
if [ -z "$walkerDate2" ]; then
echo "Nuevo kilometraje de $walkerName"
echo "$walkerDate;$walkerKm" >> $walkerFile
else
echo "Toot ya añadido previamente"
fi
else
touch $walkerFile
echo "Primer kilometraje de $walkerName"
echo "$walkerDate;$walkerKm" > $walkerFile
fi
fi
done < $fileNotifications
}
function help {
echo -e "santiago $version - fanta <fanta@56k.es>\n"
echo "-l Login the mastodon bot account\n"
echo "-r Run the bot\n"
echo "-h Show this help\n"
}
function checkOpt {
if [ -z "$opt" ]; then help; fi
if [ "$opt" = "-h" ]; then help; fi
if [ "$opt" = "-l" ]; then login; fi
if [ "$opt" = "-r" ]; then run; fi
}
function main() {
who
checkDeps
checkOpt
}
main