stockholm/krebs/5pkgs/simple/reaktor2-plugins.nix

109 lines
3.0 KiB
Nix
Raw Permalink Normal View History

2024-03-17 15:41:45 +00:00
{ pkgs, stockholm, ... }:
with stockholm.lib;
2019-01-27 02:27:29 +00:00
2024-03-17 15:41:45 +00:00
{
2019-01-27 02:27:29 +00:00
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 = {
2023-06-10 10:50:53 +00:00
filename = stockholm.outPath + "/krebs/5pkgs/simple/Reaktor/scripts/random-emoji.sh";
2019-01-27 02:27:29 +00:00
env = {
PATH = makeBinPath (with pkgs; [ coreutils gnused gnugrep xmlstarlet wget ]);
};
};
2022-01-25 20:47:23 +00:00
dance = {
2023-06-10 10:50:53 +00:00
filename = pkgs.writers.writeDash "dance" ''
2022-01-27 12:20:55 +00:00
${pkgs.krebsdance}/bin/krebsdance --dance "$@";
2022-01-25 20:47:23 +00:00
'';
};
2019-01-27 02:27:29 +00:00
nixos-version = {
2023-06-10 10:50:53 +00:00
filename = pkgs.writers.writeDash "nixos-version" ''
2019-01-27 02:27:29 +00:00
. /etc/os-release
echo "$PRETTY_NAME"
'';
};
stockholm-issue = {
2023-06-10 10:50:53 +00:00
filename = stockholm.outPath + "/krebs/5pkgs/simple/Reaktor/scripts/random-issue.sh";
2019-01-27 02:27:29 +00:00
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";
};
2023-06-10 10:50:53 +00:00
filename = pkgs.writers.writeDash "sed-plugin" ''
2019-01-27 02:27:29 +00:00
set -efu
exec ${pkgs.python3}/bin/python \
2023-07-23 21:00:32 +00:00
${./Reaktor/scripts/sed-plugin.py} "$@"
2019-01-27 02:27:29 +00:00
'';
};
};
shack-correct = {
activate = "match";
pattern = "^(.*Shack.*)$";
arguments = [1];
2023-06-10 10:50:53 +00:00
command.filename = stockholm.outPath + "/krebs/5pkgs/simple/Reaktor/scripts/shack-correct.sh";
2019-01-27 02:27:29 +00:00
};
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
'';
};
};
};
}