3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-25 20:22:45 +01:00

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.
This commit is contained in:
James Lu 2015-07-18 12:24:12 -07:00
parent d30890c5cd
commit 024ac165a8

View File

@ -262,14 +262,27 @@ def handle_privmsg(irc, numeric, command, args):
if not real_target: if not real_target:
continue continue
else: else:
try: remoteuser = getLocalUser(irc, target)
real_target = getLocalUser(irc, target)[1] if remoteuser is None:
except TypeError: continue
real_target = getRemoteUser(irc, remoteirc, target) real_target = remoteuser[1]
if notice: if notice:
remoteirc.proto.noticeClient(remoteirc, user, real_target, text) remoteirc.proto.noticeClient(remoteirc, user, real_target, text)
else: else:
remoteirc.proto.messageClient(remoteirc, user, real_target, text) 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, 'PRIVMSG')
utils.add_hook(handle_privmsg, 'NOTICE') utils.add_hook(handle_privmsg, 'NOTICE')