k 5 Reaktor/plugins: converted plugins from makefu/2/Reaktor
This commit is contained in:
parent
0a24f4b4ed
commit
59914cc41b
|
@ -1,18 +0,0 @@
|
|||
_:
|
||||
{
|
||||
# implementation of the complete Reaktor bot
|
||||
imports = [
|
||||
#./stockholmLentil.nix
|
||||
./simpleExtend.nix
|
||||
./random-emoji.nix
|
||||
./titlebot.nix
|
||||
./shack-correct.nix
|
||||
./sed-plugin.nix
|
||||
];
|
||||
krebs.Reaktor.nickname = "Reaktor|bot";
|
||||
krebs.Reaktor.enable = true;
|
||||
|
||||
krebs.Reaktor.extraEnviron = {
|
||||
REAKTOR_CHANNELS = "#krebs,#binaergewitter,#shackspace";
|
||||
};
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with pkgs;
|
||||
let
|
||||
rpkg = pkgs.substituteAll( {
|
||||
name="random-emoji";
|
||||
dir= "bin";
|
||||
isExecutable=true;
|
||||
src= ./random-emoji.sh;
|
||||
});
|
||||
rpkg-path = lib.makeSearchPath "bin" (with pkgs; [
|
||||
coreutils
|
||||
gnused
|
||||
gnugrep
|
||||
xmlstarlet
|
||||
curl]);
|
||||
in {
|
||||
# TODO: make origin a variable, <- module is generic enough to handle different origins, not only stockholm
|
||||
krebs.Reaktor.extraConfig = ''
|
||||
public_commands.insert(0,{
|
||||
'capname' : "emoji",
|
||||
'pattern' : indirect_pattern.format("emoji"),
|
||||
'argv' : ["${rpkg}/bin/random-emoji"],
|
||||
'env' : { 'PATH':'${rpkg-path}' } })
|
||||
'';
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
#!/bin/sh
|
||||
curl http://emojicons.com/random -s | \
|
||||
grep data-text | \
|
||||
sed -n 's/.*>\(.*\)<\/textarea>/\1/p' | \
|
||||
head -n 1 | \
|
||||
xmlstarlet unesc
|
|
@ -1,20 +0,0 @@
|
|||
#! /bin/sh
|
||||
set -eu
|
||||
# requires env:
|
||||
# $state_dir
|
||||
# $origin
|
||||
|
||||
# in PATH: git,lentil,coreutils
|
||||
subdir=`echo "$1" | tr -dc "[:alnum:]"`
|
||||
name=`echo "$origin" | tr -dc "[:alnum:]"`
|
||||
track="$state_dir/$name-checkout"
|
||||
(if test -e "$track" ;then
|
||||
cd "$track"
|
||||
git fetch origin master
|
||||
git reset --hard origin/master
|
||||
else
|
||||
git clone "$origin" "$track"
|
||||
fi) >&2
|
||||
|
||||
cd "$track"
|
||||
lentil "${subdir:-.}" -f csv | sed 1d | shuf | head -1
|
|
@ -1,18 +0,0 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with pkgs;
|
||||
let
|
||||
script = ./sed-plugin.py;
|
||||
in {
|
||||
#TODO: this will eat up the last regex, fix Reaktor
|
||||
krebs.Reaktor.extraConfig = ''
|
||||
public_commands.append({
|
||||
'capname' : "sed-plugin",
|
||||
# only support s///gi
|
||||
'pattern' : '^(?P<args>.*)$$',
|
||||
'argv' : ["${pkgs.python3}/bin/python3","${script}"],
|
||||
'env' : { 'state_dir' : workdir,
|
||||
'PATH':'${lib.makeSearchPath "bin" [pkgs.gnused]}' }})
|
||||
'';
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Usage:
|
||||
# _from=krebs state_dir=. python sed-plugin.py 'dick butt'
|
||||
# _from=krebs state_dir=. python sed-plugin.py 's/t/l/g'
|
||||
## dick bull
|
||||
import shelve
|
||||
from os import environ
|
||||
from os.path import join
|
||||
from sys import argv
|
||||
d = shelve.open(join(environ['state_dir'],'sed-plugin.shelve'),writeback=True)
|
||||
usr = environ['_from']
|
||||
import re
|
||||
|
||||
def is_regex(line):
|
||||
myre = re.compile(r'^s/((?:\\/|[^/])+)/((?:\\/|[^/])*)/([ig]*)$')
|
||||
return myre.match(line)
|
||||
|
||||
line = argv[1]
|
||||
m = is_regex(line)
|
||||
|
||||
if m:
|
||||
f,t,flagstr = m.groups()
|
||||
fn = f.replace('\/','/')
|
||||
tn = t.replace('\/','/')
|
||||
flags = 0
|
||||
count = 1
|
||||
if flagstr:
|
||||
if 'i' in flagstr:
|
||||
flags = re.IGNORECASE
|
||||
if 'g' in flagstr:
|
||||
count = 0
|
||||
else:
|
||||
flagstr = ''
|
||||
last = d.get(usr,None)
|
||||
if last:
|
||||
#print(re.sub(fn,tn,last,count=count,flags=flags))
|
||||
from subprocess import Popen,PIPE
|
||||
p = Popen(['sed','s/{}/{}/{}'.format(f,t,flagstr)],stdin=PIPE,stdout=PIPE )
|
||||
so,se = p.communicate(bytes("{}\n".format(last),"UTF-8"))
|
||||
if p.returncode:
|
||||
print("something went wrong when trying to process your regex: {}".format(se.decode()))
|
||||
ret = so.decode()
|
||||
print("\x1b[1m{}\x1b[0m meinte: {}".format(usr,ret.strip()))
|
||||
if ret:
|
||||
d[usr] = ret
|
||||
|
||||
else:
|
||||
print("no last message")
|
||||
else:
|
||||
d[usr] = line
|
||||
|
||||
d.close()
|
|
@ -1,20 +0,0 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with pkgs;
|
||||
let
|
||||
script = pkgs.substituteAll ( {
|
||||
name="shack-correct";
|
||||
isExecutable=true;
|
||||
dir = "";
|
||||
src = ./shack-correct.sh;
|
||||
});
|
||||
in {
|
||||
krebs.Reaktor.extraConfig = ''
|
||||
public_commands.insert(0,{
|
||||
'capname' : "shack-correct",
|
||||
'pattern' : '^(?P<args>.*Shack.*)$$',
|
||||
'argv' : ["${script}"],
|
||||
'env' : { }})
|
||||
'';
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#! /bin/sh
|
||||
set -eu
|
||||
printf "Sie meinten wohl \""
|
||||
echo -n $@ | sed 's/Shack/shack/g'
|
||||
echo "\""
|
||||
echo "${_from}--"
|
|
@ -1,19 +0,0 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with pkgs;
|
||||
let
|
||||
nixos-version-script = pkgs.writeScript "nix-version" ''
|
||||
#! /bin/sh
|
||||
. /etc/os-release
|
||||
echo "$PRETTY_NAME"
|
||||
'';
|
||||
in {
|
||||
krebs.Reaktor.extraConfig = ''
|
||||
public_commands.insert(0,{
|
||||
'capname' : "nixos-version",
|
||||
'pattern' : indirect_pattern.format("nixos-version"),
|
||||
'argv' : ["${nixos-version-script}"],
|
||||
'env' : { 'state_dir': workdir } })
|
||||
'';
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with pkgs;
|
||||
let
|
||||
random-issue = pkgs.substituteAll( {
|
||||
name="random-issue";
|
||||
dir= "bin";
|
||||
isExecutable=true;
|
||||
src= ./random-issue.sh;
|
||||
});
|
||||
random-issue-path = lib.makeSearchPath "bin" (with pkgs; [
|
||||
coreutils
|
||||
git
|
||||
gnused
|
||||
lentil]);
|
||||
in {
|
||||
# TODO: make origin a variable, <- module is generic enough to handle different origins, not only stockholm
|
||||
krebs.Reaktor.extraConfig = ''
|
||||
public_commands.insert(0,{
|
||||
'capname' : "stockholm-issue",
|
||||
'pattern' : indirect_pattern.format("stockholm-issue"),
|
||||
'argv' : ["${random-issue}/bin/random-issue"],
|
||||
'env' : { 'state_dir': workdir,
|
||||
'PATH':'${random-issue-path}',
|
||||
'origin':'http://cgit.pnp/stockholm' } })
|
||||
'';
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
{ stdenv,config, lib, pkgs, ... }:
|
||||
|
||||
with pkgs;
|
||||
let
|
||||
pypkgs = pkgs.python3Packages;
|
||||
titlebot_cmds = pypkgs.buildPythonPackage {
|
||||
name = "titlebot_cmds";
|
||||
propagatedBuildInputs = with pypkgs; [ setuptools ];
|
||||
src = fetchurl {
|
||||
# https://github.com/makefu/reaktor-titlebot tag 2.1.0
|
||||
url = "https://github.com/makefu/reaktor-titlebot/archive/2.1.0.tar.gz";
|
||||
sha256 = "0wvf09wmk8b52f9j65qrw81nwrhs9pfhijwrlkzp5l7l2q8cjkp6";
|
||||
};
|
||||
};
|
||||
pub_cmds = ["up" "help" "list" "top" "highest" "undo" ];
|
||||
priv_cmds = [ "clear" ];
|
||||
in {
|
||||
# TODO: write identify file in
|
||||
# {config.users.extraUsers.Reaktor.home}/state/admin.lst
|
||||
krebs.Reaktor.extraConfig = ''
|
||||
def titlebot_cmd(cmd):
|
||||
return {
|
||||
'capname': cmd,
|
||||
'env': {
|
||||
'TITLEDB':
|
||||
'${config.users.extraUsers.Reaktor.home}/suggestions.json'
|
||||
},
|
||||
'pattern': '^\\.' + cmd + '\\s*(?:\\s+(?P<args>.*))?$$',
|
||||
'argv': [ '${titlebot_cmds}/bin/' + cmd ] }
|
||||
# TODO: for each element in ${titlebot_cmds}/bin/*
|
||||
public_commands.insert(0,titlebot_cmd('up'))
|
||||
public_commands.insert(0,titlebot_cmd('help'))
|
||||
public_commands.insert(0,titlebot_cmd('list'))
|
||||
public_commands.insert(0,titlebot_cmd('top'))
|
||||
public_commands.insert(0,titlebot_cmd('new'))
|
||||
commands.insert(0,titlebot_cmd('clear'))
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue