mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 09:19:23 +01:00
relay: warn users when messaging channels they aren't in / remote users w/o sharing a channel
Some refactoring of relay's PRIVMSG handling is done here: - Messages to channels the sender isn't in are dropped, with a notice warning sent. - Messaging a remote user without sharing a channel with them raises an error, and is dropped. Closes #91.
This commit is contained in:
parent
e5c7d438b1
commit
4382b22138
@ -311,57 +311,51 @@ def handle_privmsg(irc, numeric, command, args):
|
|||||||
text = args['text']
|
text = args['text']
|
||||||
if target == irc.pseudoclient.uid:
|
if target == irc.pseudoclient.uid:
|
||||||
return
|
return
|
||||||
sent = 0
|
|
||||||
relay = findRelay((irc.name, target))
|
relay = findRelay((irc.name, target))
|
||||||
# Don't send any "you must be in common channels" if we're not part
|
remoteusers = relayusers[(irc.name, numeric)]
|
||||||
# of a relay, or we are but there are no links!
|
if utils.isChannel(target) and relay and numeric not in irc.channels[target].users:
|
||||||
remoteusers = relayusers[(irc.name, numeric)].items()
|
# The sender must be in the target channel to send messages over the relay;
|
||||||
'''
|
# it's the only way we can make sure they have a spawned client on ALL
|
||||||
if utils.isChannel(target) and ((relay and not db[relay]['links']) or \
|
# of the linked networks. This affects -n channels too; see
|
||||||
relay is None):
|
# https://github.com/GLolol/PyLink/issues/91 for an explanation of why.
|
||||||
|
utils.msg(irc, numeric, 'Error: You must be in %r in order to send '
|
||||||
|
'messages over the relay.' % target, notice=True)
|
||||||
return
|
return
|
||||||
'''
|
if utils.isChannel(target):
|
||||||
if not remoteusers:
|
for netname, user in relayusers[(irc.name, numeric)].items():
|
||||||
return
|
remoteirc = utils.networkobjects[netname]
|
||||||
for netname, user in relayusers[(irc.name, numeric)].items():
|
# HACK: Don't break on sending to @#channel or similar.
|
||||||
remoteirc = utils.networkobjects[netname]
|
|
||||||
# HACK: Don't break on sending to @#channel or similar.
|
|
||||||
try:
|
|
||||||
prefix, target = target.split('#', 1)
|
prefix, target = target.split('#', 1)
|
||||||
except ValueError:
|
|
||||||
prefix = ''
|
|
||||||
else:
|
|
||||||
target = '#' + target
|
target = '#' + target
|
||||||
if utils.isChannel(target):
|
|
||||||
log.debug('(%s) relay privmsg: prefix is %r, target is %r', irc.name, prefix, target)
|
log.debug('(%s) relay privmsg: prefix is %r, target is %r', irc.name, prefix, target)
|
||||||
real_target = findRemoteChan(irc, remoteirc, target)
|
real_target = findRemoteChan(irc, remoteirc, target)
|
||||||
if not real_target:
|
if not real_target:
|
||||||
continue
|
continue
|
||||||
real_target = prefix + real_target
|
real_target = prefix + real_target
|
||||||
else:
|
if notice:
|
||||||
remoteuser = getLocalUser(irc, target)
|
remoteirc.proto.noticeClient(remoteirc, user, real_target, text)
|
||||||
if remoteuser is None:
|
else:
|
||||||
continue
|
remoteirc.proto.messageClient(remoteirc, user, real_target, text)
|
||||||
real_target = remoteuser[1]
|
else:
|
||||||
|
remoteuser = getLocalUser(irc, target)
|
||||||
|
if remoteuser is None:
|
||||||
|
return
|
||||||
|
homenet, real_target = remoteuser
|
||||||
|
# For PMs, 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 anything to send our
|
||||||
|
# messages from.
|
||||||
|
if homenet not in remoteusers.keys():
|
||||||
|
utils.msg(irc, numeric, 'Error: you must be in a common channel '
|
||||||
|
'with %r in order to send messages.' % \
|
||||||
|
irc.users[target].nick, notice=True)
|
||||||
|
return
|
||||||
|
remoteirc = utils.networkobjects[homenet]
|
||||||
|
user = getRemoteUser(irc, remoteirc, numeric, spawnIfMissing=False)
|
||||||
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)
|
||||||
sent += 1
|
|
||||||
'''
|
|
||||||
if not sent:
|
|
||||||
# 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')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user