diff options
Diffstat (limited to 'pipe_notify.py')
-rw-r--r-- | pipe_notify.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/pipe_notify.py b/pipe_notify.py new file mode 100644 index 0000000..2436e40 --- /dev/null +++ b/pipe_notify.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +""" +pipe_notify.py - Phenny Pipe Notification +Copyright 2013, Alexander Sulfrian <alex@spline.inf.fu-berlin.de> +Licensed under the Eiffel Forum License 2. + +http://inamidst.com/phenny/ +""" + +import os, fcntl, threading + +PIPE_PATH = os.path.join('/', 'var', 'run', 'phenny', 'pipe') + +def setup(phenny): + dir = os.path.dirname(PIPE_PATH) + if not os.path.exists(dir): + os.makedirs(dir) + + t = threading.Thread(target=monitor_pipe, args=(phenny, PIPE_PATH,)) + t.start() + +def monitor_pipe(phenny, name): + if not os.path.exists(name): + prev = os.umask(0o000) + os.mkfifo(name) + os.umask(prev) + + while True: + fifo = open(name, 'r') + for line in fifo: + for chan in phenny.config.channels: + phenny.msg(chan, line) |