From e936b9cfd20986249989217a3279af1756fbf3de Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 29 Jan 2017 20:20:39 -0800 Subject: [PATCH] relay: add a spawn_if_missing option to get_remote_sid() --- plugins/relay.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/relay.py b/plugins/relay.py index c908b74..413a732 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -239,15 +239,20 @@ def spawn_relay_server(irc, remoteirc): return sid -def get_remote_sid(irc, remoteirc): +def get_remote_sid(irc, remoteirc, spawn_if_missing=True): """Gets the remote server SID representing remoteirc on irc, spawning - it if it doesn't exist.""" + it if it doesn't exist (and spawn_if_missing is enabled).""" log.debug('(%s) Grabbing spawnlocks_servers[%s]', irc.name, irc.name) if spawnlocks_servers[irc.name].acquire(5): try: sid = relayservers[irc.name][remoteirc.name] except KeyError: + if not spawn_if_missing: + log.debug('(%s) get_remote_sid: %s.relay doesn\'t have a known SID, ignoring.', irc.name, remoteirc.name) + spawnlocks_servers[irc.name].release() + return + log.debug('(%s) get_remote_sid: %s.relay doesn\'t have a known SID, spawning.', irc.name, remoteirc.name) sid = spawn_relay_server(irc, remoteirc)