aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@nomic.retiolum>2014-04-20 12:30:17 +0200
committertv <tv@nomic.retiolum>2014-04-20 12:30:17 +0200
commit7862c9c38d8109f8f307e7c1a6f374c9d4f0f41e (patch)
treecde93ad9545ead486a3672ff2c4fd70617315990
parentc16a558704572fc120244b912b9d4c2e4e2a1c3b (diff)
reaktor.py: add on_join hook: tell NICK MSG...
-rwxr-xr-xIRC/reaktor.py7
-rwxr-xr-xcommands/tell-on_join19
-rwxr-xr-xcommands/tell-on_privmsg17
-rw-r--r--config.py14
4 files changed, 56 insertions, 1 deletions
diff --git a/IRC/reaktor.py b/IRC/reaktor.py
index 0b285a3..5e5156a 100755
--- a/IRC/reaktor.py
+++ b/IRC/reaktor.py
@@ -34,6 +34,10 @@ class Reaktor(asybot):
def __init__(self):
asybot.__init__(self, getconf('irc_server'), getconf('irc_port'), getconf('irc_nickname'), getconf('irc_channels'), hammer_interval=getconf('irc_hammer_interval'), alarm_timeout=getconf('irc_alarm_timeout'), kill_timeout=getconf('irc_kill_timeout'))
+ def on_join(self, prefix, command, params, rest):
+ for command in getconf('on_join'):
+ self.execute_command(command, None, prefix, params)
+
def on_privmsg(self, prefix, command, params, rest):
for command in getconf('commands'):
y = match(command['pattern'], rest)
@@ -57,7 +61,8 @@ class Reaktor(asybot):
#TODO: allow only commands below ./commands/
exe = join(dirname(realpath(dirname(__file__))), command['argv'][0])
myargv = [exe] + command['argv'][1:]
- if match.groupdict().get('args',None):
+
+ if match and match.groupdict().get('args', None):
myargv += shlex.split(match.groupdict()['args'])
cwd = getconf('workdir')
diff --git a/commands/tell-on_join b/commands/tell-on_join
new file mode 100755
index 0000000..2dbff41
--- /dev/null
+++ b/commands/tell-on_join
@@ -0,0 +1,19 @@
+#! /bin/sh
+set -euf
+
+# require flock from util-linux
+if test "${FLOCK-}" != "$state_file"; then
+ exec env FLOCK="$state_file" flock "$state_file" "$0" "$@"
+fi
+
+to="$_from"
+
+# print messages
+sed -n '/^'"$to"' /{
+ s/^\([^ ]\+\) \([^ ]\+\) <\([^>]\+\)> \(.*\)/\1: \4 2-- \2, \3/p
+}' "$state_file"
+
+# delete messages
+sed -i '/^'"$to"' /{
+ d
+}' "$state_file"
diff --git a/commands/tell-on_privmsg b/commands/tell-on_privmsg
new file mode 100755
index 0000000..5d0aff4
--- /dev/null
+++ b/commands/tell-on_privmsg
@@ -0,0 +1,17 @@
+#! /bin/sh
+set -euf
+
+# require flock from util-linux
+if test "${FLOCK-}" != "$state_file"; then
+ exec env FLOCK="$state_file" flock "$state_file" "$0" "$@"
+fi
+
+from="$_prefix"
+to="$1"; shift
+msg="$*"
+date=$(date)
+
+# TODO tell now, if already joined
+printf '%s %s <%s> %s\n' "$to" "$from" "$date" "$msg" >> "$state_file"
+
+echo 'Consider it noted.' # that's what lambdabot says...
diff --git a/config.py b/config.py
index 8870137..db4c8a3 100644
--- a/config.py
+++ b/config.py
@@ -32,6 +32,12 @@ public_commands = [
default_command('rev'),
default_command('uptime'),
default_command('nocommand'),
+ {
+ 'capname': 'tell',
+ 'pattern': '^' + name + ':\\s*' + 'tell' + '\\s*(?:\\s+(?P<args>.*))?$',
+ 'argv': [ 'commands/tell-on_privmsg' ],
+ 'env': { 'state_file': workdir + '/tell.txt' }
+ },
# command not found
{ 'pattern': '^(?:' + name + '|\\*):.*',
'argv': [ 'commands/respond','You are made of stupid!'] },
@@ -46,3 +52,11 @@ public_commands = [
commands = [
default_command('reload')
]
+
+on_join = [
+ {
+ 'capname': 'tell',
+ 'argv': [ 'commands/tell-on_join' ],
+ 'env': { 'state_file': workdir + '/tell.txt' }
+ }
+]