+++ /dev/null
-#!/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.
-#
-# -k option kills irkerd if irk hard to spawn one.
-#
-# Second argument must be a payload string. Standard C-style escapes
-# such as \n and \t are decoded.
-#
-import json
-import socket
-import sys
-import fileinput
-import subprocess
-import time
-import os
-import signal
-import getopt
-
-def send(target, message):
- data = {"to": target, "privmsg" : message}
- #print(json.dumps(data))
- try:
- s = socket.create_connection(("localhost", 6659))
- s.sendall(json.dumps(data))
- except socket.error, e:
- sys.stderr.write("irkerd: write to server failed: %r\n" % e)
-
-if __name__ == "__main__":
- (options, arguments) = getopt.getopt(sys.argv[1:], "k", )
- killafter = False
- for (opt, val) in options:
- if opt == '-k':
- killafter = True
-
- # Spawn an irkerd instance if none is running.
- try:
- # irkerd might already be running
- s = socket.create_connection(("localhost", 6659))
- irkerd = None
- except:
- # If it isn't, spawn an instance
- print "Spawning an irker instance..."
- irkerd = subprocess.Popen("irkerd", shell=True, preexec_fn=os.setsid)
- time.sleep(0.5)
-
- target = arguments[0]
- if not "irc:" in target:
- target = "irc://chat.freenode.net/{0}".format(target)
- message = " ".join(arguments[1:])
- message = message.decode('string_escape')
- if message == '-':
- for line in fileinput.input('-'):
- send(target, line.rstrip('\n'))
- else:
- send(target, message)
- if killafter:
- if irkerd:
- time.sleep(0.5)
- # Magic required because shell=True, terminate() won't work.
- os.killpg(irkerd.pid, signal.SIGTERM)
- print "...terminated."
def usage():
sys.stdout.write("""
Usage:
- irkerd [-d debuglevel] [-l logfile] [-n nick] [-p password] [-V] [-h]
+ irkerd [-d debuglevel] [-l logfile] [-n nick] [-p password] [-i channel message] [-V] [-h]
Options
-d set debug level
-l set logfile
-n set nick-style
-p set nickserv password
+ -i immediate mode
-V return irkerd version
-h print this help dialog
""")
def bailout():
raise SystemExit, 1
irker.irc.add_event_handler("quit", lambda _c, _e: bailout())
- (to, privmsg) = val.split(",")
- irker.handle('{"to":"%s","privmsg":"%s"}' % (to, privmsg), quit_after=True)
+ irker.handle('{"to":"%s","privmsg":"%s"}' % (immediate, arguments[0]), quit_after=True)
irker.irc.spin()
else:
irker.thread_launch()
<arg>-l <replaceable>logfile</replaceable></arg>
<arg>-n <replaceable>nick</replaceable></arg>
<arg>-p <replaceable>password</replaceable></arg>
+ <arg>-i <replaceable>ITC-URL</replaceable></arg>
<arg>-V</arg>
- <arg>-h</arg>
+ <arg>-h</arg>
+ <arg choice='opt'><replaceable>message text</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
authenticate the nick on receipt of a welcome message.</para></listitem>
</varlistentry>
<varlistentry>
+<term>-i</term>
+<listitem><para>Immediate mode, to be run in foreground. Takes two
+following values interpreted as a channel URL and a message
+string. Sends the message, then quits.</para></listitem>
+</varlistentry>
+<varlistentry>
<term>-V</term>
<listitem><para>Write the program version to stdout and
terminate.</para></listitem>