summaryrefslogtreecommitdiffstats
path: root/krebs/2configs/reaktor2.nix
blob: ff6b539ba1a06c35ccf74a8a2af8c936ea32e3a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
with import <stockholm/lib>;
{ config, pkgs, ... }:

let
  #for shared state directory
  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 {
    pattern = "^${name}-([a-z]+)(?::\\s*(.*))?";
    activate = "match";
    command = 1;
    arguments = [2];
    env.TASKDATA = "${stateDir}/${name}";
    commands = {
      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"
      '';
    };
  };

  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 = "^bier bal(ance)*$";
          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
            '';
          };
        }
        {
          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";
            };
          };
        })
        (task "agenda")
      ];
    };
  };

in {

  krebs.reaktor2 = {
    freenode = {
      hostname = "irc.freenode.org";
      nick = "reaktor2|krebs";
      plugins = [
        {
          plugin = "register";
          config = {
            channels = [
              "#krebs"
            ];
          };
        }
        systemPlugin
      ];
      username = "reaktor2";
    };
    r = {
      nick = "reaktor2|krebs";
      plugins = [
        {
          plugin = "register";
          config = {
            channels = [
              "#noise"
              "#xxx"
            ];
          };
        }
        systemPlugin
      ];
      username = "reaktor2";
    };
  };
}