3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

Merge branch 'devel' into wip/antispam-textfilters

This commit is contained in:
James Lu 2018-06-08 15:57:40 -07:00
commit 7b744655ee
2 changed files with 20 additions and 14 deletions

View File

@ -174,13 +174,14 @@ class UserMapping(collections.abc.MutableMapping, structures.CopyWrapper):
A mapping storing User objects by UID, as well as UIDs by nick via A mapping storing User objects by UID, as well as UIDs by nick via
the 'bynick' attribute the 'bynick' attribute
""" """
def __init__(self, *, data=None): def __init__(self, irc, data=None):
if data is not None: if data is not None:
assert isinstance(data, dict) assert isinstance(data, dict)
self._data = data self._data = data
else: else:
self._data = {} self._data = {}
self.bynick = collections.defaultdict(list) self.bynick = collections.defaultdict(list)
self._irc = irc
def __getitem__(self, key): def __getitem__(self, key):
return self._data[key] return self._data[key]
@ -188,7 +189,7 @@ class UserMapping(collections.abc.MutableMapping, structures.CopyWrapper):
def __setitem__(self, key, userobj): def __setitem__(self, key, userobj):
assert hasattr(userobj, 'lower_nick'), "Cannot add object without lower_nick attribute to UserMapping" assert hasattr(userobj, 'lower_nick'), "Cannot add object without lower_nick attribute to UserMapping"
if key in self._data: if key in self._data:
log.warning('(%s) Attempting to replace User object for %r: %r -> %r', self.name, log.warning('(%s) Attempting to replace User object for %r: %r -> %r', self._irc.name,
key, self._data.get(key), userobj) key, self._data.get(key), userobj)
self._data[key] = userobj self._data[key] = userobj
@ -310,7 +311,7 @@ class PyLinkNetworkCore(structures.CamelCaseToSnakeCase):
# Intialize the server, channel, and user indexes to be populated by # Intialize the server, channel, and user indexes to be populated by
# our protocol module. # our protocol module.
self.servers = {} self.servers = {}
self.users = UserMapping() self.users = UserMapping(self)
# Two versions of the channels index exist in PyLink 2.0, and they are joined together # Two versions of the channels index exist in PyLink 2.0, and they are joined together
# - irc._channels which implicitly creates channels on access (mostly used # - irc._channels which implicitly creates channels on access (mostly used

View File

@ -2234,15 +2234,17 @@ link_parser = utils.IRCParser()
link_parser.add_argument('remotenet') link_parser.add_argument('remotenet')
link_parser.add_argument('channel') link_parser.add_argument('channel')
link_parser.add_argument('localchannel', nargs='?') link_parser.add_argument('localchannel', nargs='?')
link_parser.add_argument("-f", "--force", action='store_true') link_parser.add_argument("-f", "--force-ts", action='store_true')
def link(irc, source, args): def link(irc, source, args):
"""<remotenet> <channel> [<local channel>] [-f/--force] """<remotenet> <channel> [<local channel>] [-f/--force-ts]
Links the specified channel on \x02remotenet\x02 over PyLink Relay as \x02local channel\x02. Links the specified channel on \x02remotenet\x02 over PyLink Relay as \x02local channel\x02.
If \x02local channel\x02 is not specified, it defaults to the same name as \x02channel\x02. If \x02local channel\x02 is not specified, it defaults to the same name as \x02channel\x02.
If the --force option is given, this command will bypass checks for TS and whether the target If the --force-ts option is given, this command will bypass checks for TS and whether the target
network is alive, and link the channel anyways.""" network is alive, and link the channel anyways. It will not bypass other link restrictions like
those imposed by LINKACL."""
args = link_parser.parse_args(args) args = link_parser.parse_args(args)
# Normalize channel case # Normalize channel case
@ -2259,6 +2261,8 @@ def link(irc, source, args):
irc.error('Cannot link two channels on the same network.') irc.error('Cannot link two channels on the same network.')
return return
permissions.check_permissions(irc, source, ['relay.link'])
if localchan not in irc.channels or source not in irc.channels[localchan].users: if localchan not in irc.channels or source not in irc.channels[localchan].users:
# Caller is not in the requested channel. # Caller is not in the requested channel.
log.debug('(%s) Source not in channel %s; protoname=%s', irc.name, localchan, irc.protoname) log.debug('(%s) Source not in channel %s; protoname=%s', irc.name, localchan, irc.protoname)
@ -2269,15 +2273,16 @@ def link(irc, source, args):
irc.join(irc.pseudoclient.uid, localchan) irc.join(irc.pseudoclient.uid, localchan)
irc.reply('Joining %r now to check for op status; please run this command again after I join.' % localchan) irc.reply('Joining %r now to check for op status; please run this command again after I join.' % localchan)
return return
elif not irc.channels[localchan].is_op_plus(source):
irc.error('You must be opped in %r to complete this operation.' % localchan)
return
else: else:
irc.error('You must be in %r to complete this operation.' % localchan) irc.error('You must be in %r to complete this operation.' % localchan)
return return
permissions.check_permissions(irc, source, ['relay.link']) elif irc.protoname == 'clientbot' and not irc.channels[localchan].is_op_plus(source):
if irc.pseudoclient and source == irc.pseudoclient.uid:
irc.error('Please op the bot in %r to complete this operation.' % localchan)
else:
irc.error('You must be opped in %r to complete this operation.' % localchan)
return
if remotenet not in world.networkobjects: if remotenet not in world.networkobjects:
irc.error('No network named %r exists.' % remotenet) irc.error('No network named %r exists.' % remotenet)
@ -2308,8 +2313,8 @@ def link(irc, source, args):
"as %r." % (remotenet, args.channel, link[1])) "as %r." % (remotenet, args.channel, link[1]))
return return
if args.force: if args.force_ts:
permissions.check_permissions(irc, source, ['relay.link.force']) permissions.check_permissions(irc, source, ['relay.link.force_ts', 'relay.link.force'])
log.info("(%s) relay: Forcing link %s%s -> %s%s", irc.name, irc.name, localchan, remotenet, log.info("(%s) relay: Forcing link %s%s -> %s%s", irc.name, irc.name, localchan, remotenet,
args.channel) args.channel)
else: else: