diff options
| author | tv <tv@krebsco.de> | 2026-01-11 20:55:04 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-01-11 20:55:04 +0100 |
| commit | 114a129b977863db2cba719fca1e213f518ca3b1 (patch) | |
| tree | b029c1ee96dc160c9c6f0e3ab623e4707de70c74 /krebs/5pkgs/simple/reaktor2-plugins/default.nix | |
| parent | f60ccbad0558542b0a803c6947f98f393facad1e (diff) | |
| parent | 68d3c925b0edb958fcbafa589d35967dfb2a979c (diff) | |
Diffstat (limited to 'krebs/5pkgs/simple/reaktor2-plugins/default.nix')
| -rw-r--r-- | krebs/5pkgs/simple/reaktor2-plugins/default.nix | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/krebs/5pkgs/simple/reaktor2-plugins/default.nix b/krebs/5pkgs/simple/reaktor2-plugins/default.nix new file mode 100644 index 000000000..3f2f6eac2 --- /dev/null +++ b/krebs/5pkgs/simple/reaktor2-plugins/default.nix @@ -0,0 +1,108 @@ +{ pkgs, stockholm, ... }: +with stockholm.lib; + +{ + generators = { + command_hook = commands: { + pattern = + "^\\s*([0-9A-Za-z._][0-9A-Za-z._-]*)(?:\\s+(.*\\S))?\\s*$"; + command = 1; + arguments = [2]; + commands = commands; + }; + }; + + commands = { + + random-emoji = { + filename = ./scripts/random-emoji.sh; + env = { + PATH = makeBinPath (with pkgs; [ coreutils gnused gnugrep xmlstarlet wget ]); + }; + }; + + dance = { + filename = pkgs.writers.writeDash "dance" '' + ${pkgs.krebsdance}/bin/krebsdance --dance "$@"; + ''; + }; + + nixos-version = { + filename = pkgs.writers.writeDash "nixos-version" '' + . /etc/os-release + echo "$PRETTY_NAME" + ''; + }; + + stockholm-issue = { + filename = ./scripts/random-issue.sh; + env = { + PATH = makeBinPath (with pkgs; [ coreutils git gnused haskellPackages.lentil ]); + origin = "http://cgit.gum/stockholm"; + state_dir = "/tmp/stockholm-issue"; + }; + }; + + }; + + hooks = { + + sed = { + activate = "always"; + pattern = "^(.*)$"; + arguments = [1]; + command = { + env = { + PATH = makeBinPath (with pkgs; [ gnused ]); + state_dir = "/tmp"; + }; + filename = pkgs.writers.writeDash "sed-plugin" '' + set -efu + exec ${pkgs.python3}/bin/python \ + ${./scripts/sed-plugin.py} "$@" + ''; + }; + }; + + shack-correct = { + activate = "match"; + pattern = "^(.*Shack.*)$"; + arguments = [1]; + command.filename = ./scripts/shack-correct.sh; + }; + + + url-title = { + #pattern = "^.*(http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+).*$"; + pattern = "^.*(http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+).*$"; + activate = "match"; + arguments = [1]; + command = { + filename = pkgs.writePython3 "url-title" { deps = with pkgs.python3Packages; [ beautifulsoup4 lxml ]; } '' + import cgi + import sys + import urllib.request + from bs4 import BeautifulSoup + + try: + req = urllib.request.Request(sys.argv[1]) + req.add_header('user-agent', 'Reaktor-url-title') + resp = urllib.request.urlopen(req) + if resp.headers['content-type'].find('text/html') >= 0: + soup = BeautifulSoup(resp.read(16000), "lxml") + title = soup.find('title').string + + if len(title.split('\n')) > 5: + title = '\n'.join(title.split('\n')[:5]) + + print(title[:450]) + else: + cd_header = resp.headers['content-disposition'] + print(cgi.parse_header(cd_header)[1]['filename']) + except: # noqa: E722 + pass + ''; + }; + }; + }; +} |
