From b5c79e3f77fda034b7c0ad485f07b1e3c92d7533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Tue, 4 Oct 2022 11:34:40 +0200 Subject: reaktor2: add krebsfood hook --- krebs/2configs/reaktor2.nix | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'krebs/2configs') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index f5041a59d..9d738813b 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -75,6 +75,30 @@ let ''; }; } + { + pattern = "18@p"; + activate = "match"; + command = { + env.radius = toString 250; # metres around c-base to search + filename = pkgs.writeDash "krebsfood" '' + set -efu + expected_max_results=1024 # the upper bound on the number of restaurants + + echo '[out:json];node(id:260050809)->.cbase; + ( + node(around.cbase:'$radius')[amenity=fast_food]; + node(around.cbase:'$radius')[amenity=restaurant]; + );out;' \ + | ${pkgs.curl}/bin/curl -sSL -d @- -X POST http://overpass-api.de/api/interpreter \ + | ${pkgs.jq}/bin/jq -r --argjson random "$(shuf -i 0-$expected_max_results -n 1)" ' + .elements + | length as $length + | .[$random % $length] + | "How about \(.tags.name) (https://www.openstreetmap.org/\(.type)/\(.id))?" + ' + ''; + }; + } { pattern = ''^([\H-]*?):?\s+([+-][1-9][0-9]*)\s+(\S+)$''; activate = "match"; -- cgit v1.2.3 From af744fad896ffba2f78a7fd1721fe6887c466d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Tue, 4 Oct 2022 19:16:58 +0200 Subject: reaktor2: add cache to krebsfood hook --- krebs/2configs/reaktor2.nix | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'krebs/2configs') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index 9d738813b..33d7ad270 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -79,17 +79,34 @@ let pattern = "18@p"; activate = "match"; command = { - env.radius = toString 250; # metres around c-base to search + env = { + radius = toString 250; # metres around c-base to search + age_threshold = toString (24 * 60 * 60); + state_file = "${stateDir}/krebsfood"; + }; filename = pkgs.writeDash "krebsfood" '' set -efu expected_max_results=1024 # the upper bound on the number of restaurants - echo '[out:json];node(id:260050809)->.cbase; - ( - node(around.cbase:'$radius')[amenity=fast_food]; - node(around.cbase:'$radius')[amenity=restaurant]; - );out;' \ - | ${pkgs.curl}/bin/curl -sSL -d @- -X POST http://overpass-api.de/api/interpreter \ + file_age_seconds() { + expr "$(date +%s)" - "$(date +%s -r "$1")" + } + + get_restaurants() { + if [ -f "$state_file" ]; then + [ "$(file_age_seconds "$state_file")" -lt "$age_threshold" ] && cat "$state_file" + else + echo '[out:json];node(id:260050809)->.cbase; + ( + node(around.cbase:'$radius')[amenity=fast_food]; + node(around.cbase:'$radius')[amenity=restaurant]; + );out;' \ + | ${pkgs.curl}/bin/curl -sSL -d @- -X POST http://overpass-api.de/api/interpreter \ + | tee "$state_file" + fi + } + + get_restaurants \ | ${pkgs.jq}/bin/jq -r --argjson random "$(shuf -i 0-$expected_max_results -n 1)" ' .elements | length as $length -- cgit v1.2.3 From a768f4c994c371e21503daea696fec22789c904a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Tue, 4 Oct 2022 19:17:19 +0200 Subject: reaktor2: increase krebsfood radio --- krebs/2configs/reaktor2.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'krebs/2configs') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index 33d7ad270..a570e1e9d 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -80,7 +80,7 @@ let activate = "match"; command = { env = { - radius = toString 250; # metres around c-base to search + radius = toString 500; # metres around c-base to search age_threshold = toString (24 * 60 * 60); state_file = "${stateDir}/krebsfood"; }; -- cgit v1.2.3 From ea44b7a8515b6c2c989b2aafc1a89dc9c4473909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Tue, 4 Oct 2022 19:48:03 +0200 Subject: reaktor2: add opening hours to krebsfood --- krebs/2configs/reaktor2.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'krebs/2configs') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index a570e1e9d..b035ab81c 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -111,7 +111,7 @@ let .elements | length as $length | .[$random % $length] - | "How about \(.tags.name) (https://www.openstreetmap.org/\(.type)/\(.id))?" + | "How about \(.tags.name) (https://www.openstreetmap.org/\(.type)/\(.id)), open \(.tags.opening_hours)?" ' ''; }; -- cgit v1.2.3 From 7e40e32e4366eb0c276ca28fc2b3a95df144763c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Wed, 12 Oct 2022 09:37:28 +0200 Subject: reaktor2: do not suggest closed restaurants --- krebs/2configs/reaktor2.nix | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) (limited to 'krebs/2configs') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index b035ab81c..b62eb0497 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -80,38 +80,22 @@ let activate = "match"; command = { env = { - radius = toString 500; # metres around c-base to search - age_threshold = toString (24 * 60 * 60); - state_file = "${stateDir}/krebsfood"; + CACHE_DIR = "${stateDir}/krebsfood"; }; - filename = pkgs.writeDash "krebsfood" '' + filename = + let + osm-restaurants-src = pkgs.fetchFromGitHub { + owner = "kmein"; + repo = "scripts"; + rev = "c7a1256040c7a32ef4fd700e057bb4135a19791f"; + sha256 = "1f1cmm6wafsaii4mas1d9fishczmi6f6whkz3b1bh6jxmalwgka8"; + }; + osm-restaurants = pkgs.callPackage "${osm-restaurants-src}/osm-restaurants" {}; + in pkgs.writeDash "krebsfood" '' set -efu - expected_max_results=1024 # the upper bound on the number of restaurants - - file_age_seconds() { - expr "$(date +%s)" - "$(date +%s -r "$1")" - } - - get_restaurants() { - if [ -f "$state_file" ]; then - [ "$(file_age_seconds "$state_file")" -lt "$age_threshold" ] && cat "$state_file" - else - echo '[out:json];node(id:260050809)->.cbase; - ( - node(around.cbase:'$radius')[amenity=fast_food]; - node(around.cbase:'$radius')[amenity=restaurant]; - );out;' \ - | ${pkgs.curl}/bin/curl -sSL -d @- -X POST http://overpass-api.de/api/interpreter \ - | tee "$state_file" - fi - } - - get_restaurants \ - | ${pkgs.jq}/bin/jq -r --argjson random "$(shuf -i 0-$expected_max_results -n 1)" ' - .elements - | length as $length - | .[$random % $length] - | "How about \(.tags.name) (https://www.openstreetmap.org/\(.type)/\(.id)), open \(.tags.opening_hours)?" + c_base=260050809 + ${osm-restaurants}/bin/osm-restaurants --radius 500 --center "$c_base" \ + | ${pkgs.jq}/bin/jq -r '"How about \(.tags.name) (https://www.openstreetmap.org/\(.type)/\(.id)), open \(.tags.opening_hours)?"' ' ''; }; -- cgit v1.2.3 From 095eadf772f8eee6817065522151d2d009a47ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Wed, 12 Oct 2022 10:39:59 +0200 Subject: reaktor2: update to fix caching, center on 18@p-corner --- krebs/2configs/reaktor2.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'krebs/2configs') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index b62eb0497..a7dedf562 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -87,14 +87,15 @@ let osm-restaurants-src = pkgs.fetchFromGitHub { owner = "kmein"; repo = "scripts"; - rev = "c7a1256040c7a32ef4fd700e057bb4135a19791f"; - sha256 = "1f1cmm6wafsaii4mas1d9fishczmi6f6whkz3b1bh6jxmalwgka8"; + rev = "66b2068d548d3418c81dd093bba3f80248c68196"; + sha256 = "059sp2lz54iwklswaxv9w703sbm2vv7p0ccig10gsqshriq6v58z"; }; osm-restaurants = pkgs.callPackage "${osm-restaurants-src}/osm-restaurants" {}; in pkgs.writeDash "krebsfood" '' set -efu - c_base=260050809 - ${osm-restaurants}/bin/osm-restaurants --radius 500 --center "$c_base" \ + ecke_lat=52.51252 + ecke_lon=13.41740 + ${osm-restaurants}/bin/osm-restaurants --radius 500 --latitude "$ecke_lat" --longitude "$ecke_lon" \ | ${pkgs.jq}/bin/jq -r '"How about \(.tags.name) (https://www.openstreetmap.org/\(.type)/\(.id)), open \(.tags.opening_hours)?"' ' ''; -- cgit v1.2.3 From b5f7882fcada26d968b643765f32fd1ac23613ff Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 18 Oct 2022 21:37:26 +0200 Subject: reaktor2: give bedger its real name and logo --- krebs/2configs/reaktor2.nix | 81 ++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 37 deletions(-) (limited to 'krebs/2configs') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index 233fe2fd7..f76bc6463 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -9,6 +9,48 @@ let hooks = pkgs.reaktor2-plugins.hooks; commands = pkgs.reaktor2-plugins.commands; + # bedger - the bier ledger + # + # logo: http://c.r/bedger2 + # + bedger-add = { + pattern = ''^([\H-]*?):?\s+([+-][1-9][0-9]*)\s+(\S+)$''; + activate = "match"; + arguments = [1 2 3]; + command = { + env = { + # TODO; get state as argument + state_file = "${stateDir}/ledger"; + }; + filename = pkgs.writeDash "bedger-add" '' + set -x + tonick=$1 + amt=$2 + unit=$3 + printf '%s\n %s %d %s\n %s %d %s\n' "$(date -Id)" "$tonick" "$amt" "$unit" "$_from" "$(expr 0 - "''${amt#+}")" "$unit" >> $state_file + ${pkgs.hledger}/bin/hledger -f $state_file bal -N -O csv \ + | ${pkgs.coreutils}/bin/tail +2 \ + | ${pkgs.miller}/bin/mlr --icsv --opprint cat \ + | ${pkgs.gnugrep}/bin/grep "$_from" + ''; + }; + }; + bedger-balance = { + pattern = "^bier (ballern|bal(an(ce)?)?)$"; + activate = "match"; + command = { + env = { + state_file = "${stateDir}/ledger"; + }; + filename = pkgs.writeDash "bedger-balance" '' + ${pkgs.hledger}/bin/hledger -f $state_file bal -N -O csv \ + | ${pkgs.coreutils}/bin/tail +2 \ + | ${pkgs.miller}/bin/mlr --icsv --opprint cat \ + | ${pkgs.gnused}/bin/sed 's/^\(.\)/\1‍/' + ''; + }; + }; + taskRcFile = builtins.toFile "taskrc" '' confirmation=no ''; @@ -60,43 +102,8 @@ let } ]; hooks.PRIVMSG = [ - { - pattern = "^bier (ballern|bal(an(ce)?)?)$"; - activate = "match"; - command = { - env = { - state_file = "${stateDir}/ledger"; - }; - filename = pkgs.writeDash "bier-balance" '' - ${pkgs.hledger}/bin/hledger -f $state_file bal -N -O csv \ - | ${pkgs.coreutils}/bin/tail +2 \ - | ${pkgs.miller}/bin/mlr --icsv --opprint cat \ - | ${pkgs.gnused}/bin/sed 's/^\(.\)/\1‍/' - ''; - }; - } - { - pattern = ''^([\H-]*?):?\s+([+-][1-9][0-9]*)\s+(\S+)$''; - activate = "match"; - arguments = [1 2 3]; - command = { - env = { - # TODO; get state as argument - state_file = "${stateDir}/ledger"; - }; - filename = pkgs.writeDash "ledger-add" '' - set -x - tonick=$1 - amt=$2 - unit=$3 - printf '%s\n %s %d %s\n %s %d %s\n' "$(date -Id)" "$tonick" "$amt" "$unit" "$_from" "$(expr 0 - "''${amt#+}")" "$unit" >> $state_file - ${pkgs.hledger}/bin/hledger -f $state_file bal -N -O csv \ - | ${pkgs.coreutils}/bin/tail +2 \ - | ${pkgs.miller}/bin/mlr --icsv --opprint cat \ - | ${pkgs.gnugrep}/bin/grep "$_from" - ''; - }; - } + bedger-add + bedger-balance hooks.sed (generators.command_hook { inherit (commands) dance random-emoji nixos-version; -- cgit v1.2.3 From fbec9a17fe6a012ce6f794e5a2d73c6dcec19463 Mon Sep 17 00:00:00 2001 From: lassulus Date: Tue, 18 Oct 2022 23:44:02 +0200 Subject: reaktor2 locations: init --- krebs/2configs/reaktor2.nix | 82 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'krebs/2configs') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index a7dedf562..2ca84f568 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -38,6 +38,38 @@ let }; }; + locationsLib = pkgs.writeText "locations.sh" '' + ENDPOINT=http://c.r/poi.json + get_locations() { + curl -fsS "$ENDPOINT" + } + + set_locations() { + curl -fSs --data-binary @- "$ENDPOINT" + } + + set_location() { + [ $# -eq 3 ] || return 1 + get_locations \ + | jq \ + --arg name "$1" \ + --arg latitude "$2" \ + --arg longitude "$3" \ + '.[$name] = { $latitude, $longitude }' \ + | set_locations + } + + get_location() { + [ $# -eq 1 ] || return 1 + get_locations | jq --arg name "$1" '.[$name]' + } + + delete_location() { + [ $# -eq 1 ] || return 1 + get_locations | jq --arg name "$1" 'del(.[$name])' | set_locations + } + ''; + systemPlugin = { plugin = "system"; config = { @@ -75,6 +107,56 @@ let ''; }; } + { + pattern = "^list-locations"; + activate = "match"; + command = { + filename = pkgs.writeDash "list-locations" '' + export PATH=${makeBinPath [ + pkgs.curl + pkgs.jq + ]} + set -efu + set -x + . ${locationsLib} + get_locations | jq -r 'to_entries[]|"\(.key) \(.value.latitude),\(.value.longitude)"' + ''; + }; + } + { + pattern = ''^add-location (\S+) ([0-9.]+),([0-9.]+)$''; + activate = "match"; + arguments = [1 2 3]; + command = { + filename = pkgs.writeDash "add-location" '' + export PATH=${makeBinPath [ + pkgs.curl + pkgs.jq + ]} + set -efu + set -x + . ${locationsLib} + set_location "$1" $2 $3 + ''; + }; + } + { + pattern = ''^delete-location (\S+)$''; + activate = "match"; + arguments = [1]; + command = { + filename = pkgs.writeDash "add-location" '' + export PATH=${makeBinPath [ + pkgs.curl + pkgs.jq + ]} + set -efu + set -x + . ${locationsLib} + delete_location "$1" + ''; + }; + } { pattern = "18@p"; activate = "match"; -- cgit v1.2.3