"url": "https://matrix.example.com",
"user": "@user:matrix.example.com",
"password": "WHATEVER"
- },
- "paths": {
- "fifodir": "/path/to/fifo/dir"
}
}
--- /dev/null
+#!/usr/bin/env python3
+
+import errno
+import os
+import posix
+import stat
+import sys
+import time
+
+assert sys.version_info >= (3, 5)
+
+if len(sys.argv) != 2:
+ print("Usage: %s <channel>" % sys.argv[0])
+
+fifo_dir = os.getenv('MTXBOT_FIFO_DIR', '/run/mtxbot')
+fifo_path = "%s/%s" % (fifo_dir, sys.argv[1])
+
+if not os.path.isdir(fifo_dir):
+ print("Fifo directory %s does not exist!" % fifo_dir, file=sys.stderr)
+ sys.exit(1)
+
+if not stat.S_ISFIFO( os.stat(fifo_path).st_mode ):
+ print("Channel %s does not exist!" % sys.argv[1], file=sys.stderr)
+ sys.exit(2)
+
+for i in range(0, 10):
+ fifo = -1
+ try:
+ fifo = posix.open(fifo_path, posix.O_WRONLY | posix.O_NONBLOCK)
+ posix.write(fifo, sys.stdin.read().encode())
+ sys.exit(0)
+ except OSError as e:
+ if e.errno == errno.ENXIO:
+ time.sleep(1.0)
+ finally:
+ if fifo != -1:
+ posix.close(fifo)
+
+print("Error posting to channel %s!" % sys.argv[1], file=sys.stderr)
+sys.exit(3)
with open(sys.argv[1]) as configFile:
config = json.load(configFile)
+fifo_dir = os.getenv('MTXBOT_FIFO_DIR', '/run/mtxbot')
+
while not stop:
presences = []
- for entry in os.listdir(config['paths']['fifodir']):
- fullpath = "%s/%s" % (config['paths']['fifodir'], entry)
+ for entry in os.listdir(fifo_dir):
+ fullpath = "%s/%s" % (fifo_dir, entry)
if stat.S_ISFIFO(os.stat(fullpath).st_mode):
logging.info("Creating presence for %s..." % entry)
presences.append( Presence(entry, fullpath) )