2 # Illustrates how to test irkerd.
4 # First argument must be a channel URL. If it does not begin with "irc",
5 # the base URL for freenode is prepended.
7 # Second argument must be a payload string. Standard C-style escapes
8 # such as \n and \t are decoded.
15 def send(target, message):
16 data = {"to": target, "privmsg" : message}
17 print(json.dumps(data))
19 s = socket.create_connection(("localhost", 6659))
20 s.sendall(json.dumps(data))
21 except socket.error, e:
22 sys.stderr.write("irkerd: server launch failed: %r\n" % e)
25 if not "irc:" in target:
26 target = "irc://chat.freenode.net/{0}".format(target)
27 message = " ".join(sys.argv[2:])
28 message = message.decode('string_escape')
30 for line in fileinput.input('-'):
31 send(target, line.rstrip('\n'))