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.
18 def send(target, message):
19 data = {"to": target, "privmsg" : message}
20 #print(json.dumps(data))
22 s = socket.create_connection(("localhost", 6659))
23 s.sendall(json.dumps(data))
24 except socket.error, e:
25 sys.stderr.write("irk: write to server failed: %r\n" % e)
28 s = socket.create_connection(("localhost", 6659))
30 print "No irker is running."
33 if not "irc:" in target:
34 target = "irc://chat.freenode.net/{0}".format(target)
35 message = " ".join(sys.argv[2:])
36 message = message.decode('string_escape')
38 for line in fileinput.input('-'):
39 send(target, line.rstrip('\n'))