nix-configs/other/scripts/networkhooks/ccchh.nu

41 lines
880 B
Text
Raw Normal View History

2023-10-28 22:25:06 +02:00
const wave_timeout = 15min;
def main [
interface: string
type: string
] {
if not ('/var/lib/ccchh-winken/last' | path exists) {
mkdir '/var/lib/ccchh-winken';
0 | into datetime | save '/var/lib/ccchh-winken/last' -f;
}
let $last_waved = open '/var/lib/ccchh-winken/last' --raw | into datetime;
if ((date now) - $last_waved) > $wave_timeout {
if $type == "up" {
mullvad disconnect;
curl mqtt://mqtt.z9/winkekatze/katz9/eye/set -d (rand-color);
curl mqtt://mqtt.z9/winkekatze/Viktoria/eye/set -d (rand-color);
curl mqtt://mqtt.z9/winkekatze/allcats -d 'wink';
date now | save '/var/lib/ccchh-winken/last' -f;
}
}
}
def rand-color [] {
const colors = [
"blue"
"cyan"
"green"
"pink"
"red"
"white"
"yellow"
];
2023-11-13 14:07:25 +01:00
$colors | get (random int 0..(($colors | length) - 1))
2023-10-28 22:25:06 +02:00
}