10 assert sys.version_info >= (3, 5)
12 if len(sys.argv) != 2:
13 print("Usage: %s <channel>" % sys.argv[0])
16 fifo_dir = os.getenv('MTXBOT_FIFO_DIR', '/run/mtxbot')
17 fifo_path = "%s/%s" % (fifo_dir, sys.argv[1])
19 if not os.path.isdir(fifo_dir):
20 print("Fifo directory %s does not exist!" % fifo_dir, file=sys.stderr)
23 if not ( os.exists(fifo_path) and stat.S_ISFIFO(os.stat(fifo_path).st_mode) ):
24 print("Channel %s does not exist!" % sys.argv[1], file=sys.stderr)
27 for i in range(0, 10):
30 fifo = posix.open(fifo_path, posix.O_WRONLY | posix.O_NONBLOCK)
31 posix.write(fifo, sys.stdin.read().encode())
34 if e.errno == errno.ENXIO:
40 print("Error posting to channel %s!" % sys.argv[1], file=sys.stderr)