diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 00:50:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 00:50:22 +0000 |
commit | 84a20cb80243f8614906be91953ca4213334b16b (patch) | |
tree | 414827e91acab4b596cdf8ed9632e4cdeff95480 /irk | |
parent | Initial commit. (diff) | |
download | irker-84a20cb80243f8614906be91953ca4213334b16b.tar.xz irker-84a20cb80243f8614906be91953ca4213334b16b.zip |
Adding upstream version 2.18+dfsg.upstream/2.18+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'irk')
-rwxr-xr-x | irk | 52 |
1 files changed, 52 insertions, 0 deletions
@@ -0,0 +1,52 @@ +#!/usr/bin/env python +# 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(): + target = sys.argv[1] + message = " ".join(sys.argv[2:]) + # XXX: why is this necessary? + #message = message.decode('string_escape') + + try: + irk(target, message) + except socket.error as e: + sys.stderr.write("irk: write to server failed: %r\n" % e) + sys.exit(1) + +if __name__ == '__main__': + main() |