Remove a dependecy on netcat.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 6 Oct 2012 11:00:07 +0000 (07:00 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 6 Oct 2012 11:00:07 +0000 (07:00 -0400)
irk

diff --git a/irk b/irk
index 2ccab51fd85845f76d70e4cd59ebb7bc7053e58b..50ddc8fbc82b3f4321df7fa6122a8926b959c5d1 100755 (executable)
--- a/irk
+++ b/irk
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env python
 # Illustrates how to test irkerd.
 #
 # First argument must be a channel URL. If it does not begin with "irc", 
@@ -6,12 +6,14 @@
 #
 # Second argument must be a payload string.
 #
-channel=$1
-message=$2
+import json
+import socket
+import sys
 
-case $channel in
-irc:*) ;;
-*) channel="irc://chat.freenode.net/$channel"
-esac
-
-echo "{\"to\":\"$channel\",\"privmsg\":\"$message\"}" | netcat localhost 6659
+s = socket.create_connection(("localhost", 6659))
+target = sys.argv[1]
+if not "irc:" in target:
+    target = "irc://chat.freenode.net/{0}".format(target)
+data = {"to": target, "privmsg" : " ".join(sys.argv[2:])}
+print(json.dumps(data))
+s.sendall(json.dumps(data))