2 # Illustrates how to test irkerd. Requires that the irkerd source
3 # be in the current directory.
5 # First argument must be a channel URL. If it does not begin with "irc",
6 # the base URL for freenode is prepended.
8 # Second argument must be a payload string. Standard C-style escapes
9 # such as \n and \t are decoded.
19 def send(target, message):
20 data = {"to": target, "privmsg" : message}
21 #print(json.dumps(data))
23 s = socket.create_connection(("localhost", 6659))
24 s.sendall(json.dumps(data))
25 except socket.error, e:
26 sys.stderr.write("irkerd: write to server failed: %r\n" % e)
30 # irkerd might already be running
31 s = socket.create_connection(("localhost", 6659))
33 # If it isn't, spawn an instance
34 print "Spawning an irker instance..."
35 subprocess.Popen("irkerd", shell=True)
39 if not "irc:" in target:
40 target = "irc://chat.freenode.net/{0}".format(target)
41 message = " ".join(sys.argv[2:])
42 message = message.decode('string_escape')
44 for line in fileinput.input('-'):
45 send(target, line.rstrip('\n'))