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