Add adc tamagotchi script. - brcon2024-hackathons - Bitreichcon 2024 Hackathons
(HTM) git clone git://bitreich.org/brcon2024-hackathons git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/brcon2024-hackathons
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) Submodules
---
(DIR) commit 0b190cea54fbc97803635f2bf771a2edd6b262e5
(DIR) parent 7ac09da5aedd5b5e3fbbdcc57adadb263f09d011
(HTM) Author: Christoph Lohmann <20h@r-36.net>
Date: Thu, 8 Aug 2024 23:03:05 +0200
Add adc tamagotchi script.
Diffstat:
A mqtt/tamagotchi-adc.sh | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/mqtt/tamagotchi-adc.sh b/mqtt/tamagotchi-adc.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+cookiefile="$(mktemp)"
+datefunc() {
+ date +%s
+}
+datefunc >"$cookiefile"
+while read -r msg
+do
+ last="$(tail -n 1 "$cookiefile")"
+ if test "$msg" = "cookie"
+ then
+ now="$(datefunc)"
+ printf '%s\n' "$now" >"$cookiefile"
+ delta="$(printf '%s-%s\n' "$now" "$last" | bc)"
+ if test "$delta" -gt 28 && test "$delta" -lt 32
+ then
+ echo ":D"
+ elif test "$delta" -gt 25 && test "$delta" -lt 35
+ then
+ echo ":)"
+ elif test "$delta" -gt 23 && test "$delta" -lt 38
+ then
+ echo ":|"
+ elif test "$delta" -gt 20 && test "$delta" -lt 40
+ then
+ echo ":("
+ else
+ printf 'DEAD: delta = %s s\n' "$delta"
+ fi
+ fi
+done