From b28706964e78199859cbf6b78f869e9cc2f8a8ac Mon Sep 17 00:00:00 2001 From: lassulus Date: Sun, 27 Jan 2019 03:34:47 +0100 Subject: hotdog.r: Reaktor -> reaktor2 --- krebs/2configs/reaktor2.nix | 181 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 krebs/2configs/reaktor2.nix (limited to 'krebs/2configs/reaktor2.nix') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix new file mode 100644 index 000000000..95a95b8f5 --- /dev/null +++ b/krebs/2configs/reaktor2.nix @@ -0,0 +1,181 @@ +with import ; +{ config, pkgs, ... }: + +let + stateDir = config.krebs.reaktor2.r.stateDir; + + generators = pkgs.reaktor2-plugins.generators; + hooks = pkgs.reaktor2-plugins.hooks; + commands = pkgs.reaktor2-plugins.commands; + + task = name: let + rcFile = builtins.toFile "taskrc" '' + confirmation=no + ''; + in { + "${name}-task-add" = { + pattern = "^${name}-add: (.*)$"; + activate = "match"; + arguments = [1]; + command = { + env = { + TASKDATA = "${stateDir}/${name}"; + }; + filename = pkgs.writeDash "${name}-task-add" '' + ${pkgs.taskwarrior}/bin/task rc:${rcFile} add "$*" + ''; + }; + }; + + "${name}-task-list" = { + pattern = "^${name}-list$"; + activate = "match"; + command = { + env = { + TASKDATA = "${stateDir}/${name}"; + }; + filename = pkgs.writeDash "${name}-task-list" '' + ${pkgs.taskwarrior}/bin/task rc:${rcFile} export | ${pkgs.jq}/bin/jq -r '.[] | select(.id != 0) | "\(.id) \(.description)"' + ''; + }; + }; + + "${name}-task-delete" = { + pattern = "^${name}-delete: (.*)$"; + activate = "match"; + arguments = [1]; + command = { + env = { + TASKDATA = "${stateDir}/${name}"; + }; + filename = pkgs.writeDash "${name}-task-delete" '' + ${pkgs.taskwarrior}/bin/task rc:${rcFile} delete "$*" + ''; + }; + }; + + "${name}-task-done" = { + pattern = "^${name}-done: (.*)$"; + activate = "match"; + arguments = [1]; + command = { + env = { + TASKDATA = "${stateDir}/${name}"; + }; + filename = pkgs.writeDash "${name}-task-done" '' + ${pkgs.taskwarrior}/bin/task rc:${rcFile} done "$*" + ''; + }; + }; + }; + + systemPlugin = { + plugin = "system"; + config = { + workdir = stateDir; + hooks.JOIN = [ + { + activate = "always"; + command = { + filename = + "${pkgs.Reaktor.src}/reaktor/commands/tell-on_join"; + env = { + PATH = makeBinPath [ + pkgs.coreutils # XXX env, touch + pkgs.jq # XXX sed + pkgs.utillinux # XXX flock + ]; + state_file = "${stateDir}/tell.json"; + }; + }; + } + ]; + hooks.PRIVMSG = [ + { + pattern = "^ledger balance"; + activate = "match"; + command = { + env = { + state_file = "${stateDir}/ledger"; + }; + filename = pkgs.writeDash "ledger-balance" '' + ${pkgs.hledger}/bin/hledger -f $state_file bal -N + ''; + }; + } + { + pattern = ''^(\S+)\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 + ''; + }; + } + hooks.sed + (generators.command_hook { + inherit (commands) hello random-emoji nixos-version stockholm-issue; + tell = { + filename = + "${pkgs.Reaktor.src}/reaktor/commands/tell-on_privmsg"; + env = { + PATH = makeBinPath [ + pkgs.coreutils # XXX date, env + pkgs.jq # XXX sed + pkgs.utillinux # XXX flock + ]; + state_file = "${stateDir}/tell.txt"; + }; + }; + }) + ] ++ (attrValues (task "agenda")) + ; + }; + }; + +in { + + krebs.reaktor2 = { + freenode = { + hostname = "irc.freenode.org"; + nick = "reaktor2|krebs"; + plugins = [ + { + plugin = "register"; + config = { + channels = [ + "#krebs" + ]; + }; + } + systemPlugin + ]; + user = "reaktor2"; + }; + r = { + nick = "reaktor2|krebs"; + plugins = [ + { + plugin = "register"; + config = { + channels = [ + "#noise" + "#xxx" + ]; + }; + } + systemPlugin + ]; + user = "reaktor2"; + }; + }; +} -- cgit v1.2.3 From 052cef71fd24ce36bbd043e2aa12d2ff3a9d247c Mon Sep 17 00:00:00 2001 From: lassulus Date: Sun, 27 Jan 2019 13:50:31 +0100 Subject: reaktor: ledger balance -> bier balance --- krebs/2configs/reaktor2.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'krebs/2configs/reaktor2.nix') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index 95a95b8f5..ae2e975a2 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -92,13 +92,13 @@ let ]; hooks.PRIVMSG = [ { - pattern = "^ledger balance"; + pattern = "^bier balance"; activate = "match"; command = { env = { state_file = "${stateDir}/ledger"; }; - filename = pkgs.writeDash "ledger-balance" '' + filename = pkgs.writeDash "bier-balance" '' ${pkgs.hledger}/bin/hledger -f $state_file bal -N ''; }; -- cgit v1.2.3 From fd4876da16d436a38700b358f26ba48903de8d20 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sun, 27 Jan 2019 14:27:54 +0100 Subject: reaktor2: pretty print bier balance --- krebs/2configs/reaktor2.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'krebs/2configs/reaktor2.nix') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index ae2e975a2..bdd95a256 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -99,7 +99,9 @@ let state_file = "${stateDir}/ledger"; }; filename = pkgs.writeDash "bier-balance" '' - ${pkgs.hledger}/bin/hledger -f $state_file bal -N + ${pkgs.hledger}/bin/hledger -f $state_file bal -N -O csv \ + | ${pkgs.coreutils}/bin/tail +2 \ + | ${pkgs.miller}/bin/mlr --icsv --opprint cat ''; }; } -- cgit v1.2.3 From 92caf2dadae82310fe13830dfaac30fe885fbf3e Mon Sep 17 00:00:00 2001 From: lassulus Date: Sun, 27 Jan 2019 14:32:33 +0100 Subject: reaktor2 bier: allow 'bier bal' as command --- krebs/2configs/reaktor2.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'krebs/2configs/reaktor2.nix') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index bdd95a256..9ca60b5bf 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -92,7 +92,7 @@ let ]; hooks.PRIVMSG = [ { - pattern = "^bier balance"; + pattern = "^bier bal(ance)*$"; activate = "match"; command = { env = { -- cgit v1.2.3 From 5926a718593544c69301f4168d30051ff1d61aab Mon Sep 17 00:00:00 2001 From: lassulus Date: Sun, 27 Jan 2019 16:55:47 +0100 Subject: reaktor2 task: use single hook for more efficency --- krebs/2configs/reaktor2.nix | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'krebs/2configs/reaktor2.nix') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index 9ca60b5bf..f1e59142e 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -2,6 +2,7 @@ with import ; { config, pkgs, ... }: let + #for shared state directory stateDir = config.krebs.reaktor2.r.stateDir; generators = pkgs.reaktor2-plugins.generators; @@ -13,11 +14,12 @@ let confirmation=no ''; in { - "${name}-task-add" = { - pattern = "^${name}-add: (.*)$"; - activate = "match"; - arguments = [1]; - command = { + pattern = "^${name}-([a-z]+)(?::\\s*(.*))?"; + activate = "match"; + command = 1; + arguments = [2]; + commands = { + add = { env = { TASKDATA = "${stateDir}/${name}"; }; @@ -25,12 +27,7 @@ let ${pkgs.taskwarrior}/bin/task rc:${rcFile} add "$*" ''; }; - }; - - "${name}-task-list" = { - pattern = "^${name}-list$"; - activate = "match"; - command = { + list = { env = { TASKDATA = "${stateDir}/${name}"; }; @@ -38,13 +35,7 @@ let ${pkgs.taskwarrior}/bin/task rc:${rcFile} export | ${pkgs.jq}/bin/jq -r '.[] | select(.id != 0) | "\(.id) \(.description)"' ''; }; - }; - - "${name}-task-delete" = { - pattern = "^${name}-delete: (.*)$"; - activate = "match"; - arguments = [1]; - command = { + delete = { env = { TASKDATA = "${stateDir}/${name}"; }; @@ -52,13 +43,7 @@ let ${pkgs.taskwarrior}/bin/task rc:${rcFile} delete "$*" ''; }; - }; - - "${name}-task-done" = { - pattern = "^${name}-done: (.*)$"; - activate = "match"; - arguments = [1]; - command = { + done = { env = { TASKDATA = "${stateDir}/${name}"; }; @@ -139,8 +124,8 @@ let }; }; }) - ] ++ (attrValues (task "agenda")) - ; + (task "agenda") + ]; }; }; -- cgit v1.2.3 From 52ef20148e44f2b2017a0edc30899860799ad652 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 27 Jan 2019 20:06:06 +0100 Subject: reaktor2 service: user -> username + proper type --- krebs/2configs/reaktor2.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'krebs/2configs/reaktor2.nix') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index f1e59142e..2beb6561b 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -146,7 +146,7 @@ in { } systemPlugin ]; - user = "reaktor2"; + username = "reaktor2"; }; r = { nick = "reaktor2|krebs"; @@ -162,7 +162,7 @@ in { } systemPlugin ]; - user = "reaktor2"; + username = "reaktor2"; }; }; } -- cgit v1.2.3 From 06b23af29d434f448faebf822d5f1f1e8a0c0a39 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 27 Jan 2019 20:32:04 +0100 Subject: reaktor2 task: define env in hook --- krebs/2configs/reaktor2.nix | 48 +++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'krebs/2configs/reaktor2.nix') diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix index 2beb6561b..ff6b539ba 100644 --- a/krebs/2configs/reaktor2.nix +++ b/krebs/2configs/reaktor2.nix @@ -18,39 +18,23 @@ let activate = "match"; command = 1; arguments = [2]; + env.TASKDATA = "${stateDir}/${name}"; commands = { - add = { - env = { - TASKDATA = "${stateDir}/${name}"; - }; - filename = pkgs.writeDash "${name}-task-add" '' - ${pkgs.taskwarrior}/bin/task rc:${rcFile} add "$*" - ''; - }; - list = { - env = { - TASKDATA = "${stateDir}/${name}"; - }; - filename = pkgs.writeDash "${name}-task-list" '' - ${pkgs.taskwarrior}/bin/task rc:${rcFile} export | ${pkgs.jq}/bin/jq -r '.[] | select(.id != 0) | "\(.id) \(.description)"' - ''; - }; - delete = { - env = { - TASKDATA = "${stateDir}/${name}"; - }; - filename = pkgs.writeDash "${name}-task-delete" '' - ${pkgs.taskwarrior}/bin/task rc:${rcFile} delete "$*" - ''; - }; - done = { - env = { - TASKDATA = "${stateDir}/${name}"; - }; - filename = pkgs.writeDash "${name}-task-done" '' - ${pkgs.taskwarrior}/bin/task rc:${rcFile} done "$*" - ''; - }; + add.filename = pkgs.writeDash "${name}-task-add" '' + ${pkgs.taskwarrior}/bin/task rc:${rcFile} add "$1" + ''; + list.filename = pkgs.writeDash "${name}-task-list" '' + ${pkgs.taskwarrior}/bin/task rc:${rcFile} export \ + | ${pkgs.jq}/bin/jq -r ' + .[] | select(.id != 0) | "\(.id) \(.description)" + ' + ''; + delete.filename = pkgs.writeDash "${name}-task-delete" '' + ${pkgs.taskwarrior}/bin/task rc:${rcFile} delete "$1" + ''; + done.filename = pkgs.writeDash "${name}-task-done" '' + ${pkgs.taskwarrior}/bin/task rc:${rcFile} done "$1" + ''; }; }; -- cgit v1.2.3