From 024ac165a83b07d494dc8b5d14b29c5c8b0c2e25 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 18 Jul 2015 12:24:12 -0700 Subject: [PATCH] relay: Only allow messaging users in common channels / channels that you're in The old behavior, which iterated over the pseudoclients representing the sender, dropped messages to clients without a common channel without any warning. Now, the sender will get a lovely notice from the PyLink client. Trying to send to a '-n' channel without being in it: -PyLink-devel- Error: You must be in '#channel' in order to send messages. Trying to message a user without sharing a common channel: -PyLink-devel- Error: You must be in a common channel with 'GLolol/testnet' in order to send messages. Closes #62. --- plugins/relay.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/plugins/relay.py b/plugins/relay.py index 91a5f31..8279d86 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -262,14 +262,27 @@ def handle_privmsg(irc, numeric, command, args): if not real_target: continue else: - try: - real_target = getLocalUser(irc, target)[1] - except TypeError: - real_target = getRemoteUser(irc, remoteirc, target) + remoteuser = getLocalUser(irc, target) + if remoteuser is None: + continue + real_target = remoteuser[1] if notice: remoteirc.proto.noticeClient(remoteirc, user, real_target, text) else: remoteirc.proto.messageClient(remoteirc, user, real_target, text) + break + else: + # We must be on a common channel with the target. Otherwise, the sender + # doesn't have a client representing them on the remote network, + # and we won't have anywhere to send our messages from. + # In this case, we've iterated over all networks where the sender + # has pseudoclients, and found no suitable targets to send to. + if target in irc.users: + target_s = 'a common channel with %r' % irc.users[target].nick + else: + target_s = repr(target) + utils.msg(irc, numeric, 'Error: You must be in %s in order to send messages.' % \ + target_s, notice=True) utils.add_hook(handle_privmsg, 'PRIVMSG') utils.add_hook(handle_privmsg, 'NOTICE')