From ad34f6c4f9529c57581586341156d99117acce23 Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 20 Jul 2015 14:36:47 -0700 Subject: [PATCH] relay: make separator a per-network config option --- config.yml.example | 3 +++ plugins/relay.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/config.yml.example b/config.yml.example index 7b17154..3af93b8 100644 --- a/config.yml.example +++ b/config.yml.example @@ -43,6 +43,9 @@ servers: # When more than two consecutive pings are missed, PyLink will disconnect with a ping timeout. pingfreq: 30 + # Separator character (used by relay) + separator: "/" + # Plugins to load (omit the .py extension) plugins: - commands diff --git a/plugins/relay.py b/plugins/relay.py index 52ed152..799791e 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -15,12 +15,15 @@ from log import log dbname = "pylinkrelay.db" relayusers = defaultdict(dict) -def normalizeNick(irc, netname, nick, separator="/"): +def normalizeNick(irc, netname, nick, separator=None): # Block until we know the IRC network's nick length (after capabilities # are sent) log.debug('(%s) normalizeNick: waiting for irc.connected', irc.name) irc.connected.wait(1) + separator = separator or irc.serverdata.get('separator') or "/" + log.debug('(%s) normalizeNick: using %r as separator.', irc.name, separator) + orig_nick = nick protoname = irc.proto.__name__ maxnicklen = irc.maxnicklen @@ -45,7 +48,7 @@ def normalizeNick(irc, netname, nick, separator="/"): nick = nick[:allowedlength] nick += suffix - # TODO: factorize + # FIXME: factorize while utils.nickToUid(irc, nick) and not utils.isInternalClient(irc, utils.nickToUid(irc, nick)): # The nick we want exists? Darn, create another one then, but only if # the target isn't an internal client! @@ -53,6 +56,7 @@ def normalizeNick(irc, netname, nick, separator="/"): # but couldn't be created due to a nick conflict. # This can happen when someone steals a relay user's nick. new_sep = separator + separator[-1] + log.debug('(%s) normalizeNick: using %r as new_sep.', irc.name, separator) nick = normalizeNick(irc, netname, orig_nick, separator=new_sep) finalLength = len(nick) assert finalLength <= maxnicklen, "Normalized nick %r went over max " \