summaryrefslogtreecommitdiffstats
path: root/irk
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 14:27:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 14:27:58 +0000
commit3aecc6d0a8d757d6159dfa5083f1b254296c5b43 (patch)
tree3a305eb312ed47a1ac8967170ea1d45bb3c208be /irk
parentInitial commit. (diff)
downloadirker-3aecc6d0a8d757d6159dfa5083f1b254296c5b43.tar.xz
irker-3aecc6d0a8d757d6159dfa5083f1b254296c5b43.zip
Adding upstream version 2.23+dfsg.upstream/2.23+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'irk')
-rwxr-xr-xirk65
1 files changed, 65 insertions, 0 deletions
diff --git a/irk b/irk
new file mode 100755
index 0000000..22918d6
--- /dev/null
+++ b/irk
@@ -0,0 +1,65 @@
+#!/usr/bin/env python3
+# Illustrates how to test irkerd.
+#
+# First argument must be a channel URL. If it does not begin with "irc",
+# the base URL for freenode is prepended.
+#
+# Second argument must be a payload string. Standard C-style escapes
+# such as \n and \t are decoded.
+#
+# SPDX-License-Identifier: BSD-2-Clause
+import json
+import socket
+import sys
+import fileinput
+
+DEFAULT_SERVER = ("localhost", 6659)
+
+def connect(server = DEFAULT_SERVER):
+ return socket.create_connection(server)
+
+def send(s, target, message):
+ data = {"to": target, "privmsg" : message}
+ dump = json.dumps(data)
+ if not isinstance(dump, bytes):
+ dump = dump.encode('ascii')
+ s.sendall(dump)
+
+def irk(target, message, server = DEFAULT_SERVER):
+ s = connect(server)
+ if "irc:" not in target and "ircs:" not in target:
+ target = "irc://chat.freenode.net/{0}".format(target)
+ if message == '-':
+ for line in fileinput.input('-'):
+ send(s, target, line.rstrip('\n'))
+ else:
+ send(s, target, message)
+ s.close()
+
+def main():
+ if len(sys.argv) < 2:
+ sys.stderr.write("irk: a URL argument is required\n")
+ sys.exit(1)
+ target = sys.argv[1]
+ message = " ".join(sys.argv[2:])
+ # Allows pretty formatting of irker messages
+ if str == bytes:
+ message = message.decode('string_escape')
+
+ # The actual IRC limit is 512. Avoid any off-by-ones
+ chunksize = 511
+ try:
+ while message[:chunksize]:
+ irk(target, message[:chunksize])
+ message = message[chunksize:]
+ except socket.error as e:
+ sys.stderr.write("irk: write to server failed: %r\n" % e)
+ sys.exit(1)
+
+if __name__ == '__main__':
+ main()
+
+# The following sets edit modes for GNU EMACS
+# Local Variables:
+# mode:python
+# End: