summaryrefslogtreecommitdiffstats
path: root/krebs/2configs/reaktor2.nix
diff options
context:
space:
mode:
Diffstat (limited to 'krebs/2configs/reaktor2.nix')
-rw-r--r--krebs/2configs/reaktor2.nix134
1 files changed, 132 insertions, 2 deletions
diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix
index f76bc6463..afaac9dae 100644
--- a/krebs/2configs/reaktor2.nix
+++ b/krebs/2configs/reaktor2.nix
@@ -80,6 +80,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 = {
@@ -94,7 +126,7 @@ let
PATH = makeBinPath [
pkgs.coreutils # XXX env, touch
pkgs.jq # XXX sed
- pkgs.utillinux # XXX flock
+ pkgs.util-linux # XXX flock
];
state_file = "${stateDir}/tell.json";
};
@@ -102,6 +134,104 @@ let
}
];
hooks.PRIVMSG = [
+ {
+ 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";
+ command = {
+ env = {
+ CACHE_DIR = "${stateDir}/krebsfood";
+ };
+ filename =
+ let
+ osm-restaurants-src = pkgs.fetchFromGitHub {
+ owner = "kmein";
+ repo = "scripts";
+ rev = "66b2068d548d3418c81dd093bba3f80248c68196";
+ sha256 = "059sp2lz54iwklswaxv9w703sbm2vv7p0ccig10gsqshriq6v58z";
+ };
+ osm-restaurants = pkgs.callPackage "${osm-restaurants-src}/osm-restaurants" {};
+ in pkgs.writeDash "krebsfood" ''
+ set -efu
+ 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)?"'
+ '
+ '';
+ };
+ }
+ {
+ 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
@@ -114,7 +244,7 @@ let
PATH = makeBinPath [
pkgs.coreutils # XXX date, env
pkgs.jq # XXX sed
- pkgs.utillinux # XXX flock
+ pkgs.util-linux # XXX flock
];
state_file = "${stateDir}/tell.txt";
};