tamagotchi-adc.sh - brcon2024-hackathons - Bitreichcon 2024 Hackathons HTML git clone git://bitreich.org/brcon2024-hackathons git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/brcon2024-hackathons DIR Log DIR Files DIR Refs DIR Tags DIR Submodules --- tamagotchi-adc.sh (628B) --- 1 #!/bin/sh 2 cookiefile="$(mktemp)" 3 datefunc() { 4 date +%s 5 } 6 datefunc >"$cookiefile" 7 while read -r msg 8 do 9 last="$(tail -n 1 "$cookiefile")" 10 if test "$msg" = "cookie" 11 then 12 now="$(datefunc)" 13 printf '%s\n' "$now" >"$cookiefile" 14 delta="$(printf '%s-%s\n' "$now" "$last" | bc)" 15 if test "$delta" -gt 28 && test "$delta" -lt 32 16 then 17 echo ":D" 18 elif test "$delta" -gt 25 && test "$delta" -lt 35 19 then 20 echo ":)" 21 elif test "$delta" -gt 23 && test "$delta" -lt 38 22 then 23 echo ":|" 24 elif test "$delta" -gt 20 && test "$delta" -lt 40 25 then 26 echo ":(" 27 else 28 printf 'DEAD: delta = %s s\n' "$delta" 29 fi 30 fi 31 done