mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-25 12:12:53 +01:00
Merge branch 'devel' into wip/antispam-textfilters
This commit is contained in:
commit
7b744655ee
@ -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
|
||||
the 'bynick' attribute
|
||||
"""
|
||||
def __init__(self, *, data=None):
|
||||
def __init__(self, irc, data=None):
|
||||
if data is not None:
|
||||
assert isinstance(data, dict)
|
||||
self._data = data
|
||||
else:
|
||||
self._data = {}
|
||||
self.bynick = collections.defaultdict(list)
|
||||
self._irc = irc
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self._data[key]
|
||||
@ -188,7 +189,7 @@ class UserMapping(collections.abc.MutableMapping, structures.CopyWrapper):
|
||||
def __setitem__(self, key, userobj):
|
||||
assert hasattr(userobj, 'lower_nick'), "Cannot add object without lower_nick attribute to UserMapping"
|
||||
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)
|
||||
|
||||
self._data[key] = userobj
|
||||
@ -310,7 +311,7 @@ class PyLinkNetworkCore(structures.CamelCaseToSnakeCase):
|
||||
# Intialize the server, channel, and user indexes to be populated by
|
||||
# our protocol module.
|
||||
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
|
||||
# - irc._channels which implicitly creates channels on access (mostly used
|
||||
|
@ -2234,15 +2234,17 @@ link_parser = utils.IRCParser()
|
||||
link_parser.add_argument('remotenet')
|
||||
link_parser.add_argument('channel')
|
||||
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):
|
||||
"""<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.
|
||||
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
|
||||
network is alive, and link the channel anyways."""
|
||||
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. It will not bypass other link restrictions like
|
||||
those imposed by LINKACL."""
|
||||
|
||||
args = link_parser.parse_args(args)
|
||||
|
||||
# Normalize channel case
|
||||
@ -2259,6 +2261,8 @@ def link(irc, source, args):
|
||||
irc.error('Cannot link two channels on the same network.')
|
||||
return
|
||||
|
||||
permissions.check_permissions(irc, source, ['relay.link'])
|
||||
|
||||
if localchan not in irc.channels or source not in irc.channels[localchan].users:
|
||||
# Caller is not in the requested channel.
|
||||
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.reply('Joining %r now to check for op status; please run this command again after I join.' % localchan)
|
||||
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:
|
||||
irc.error('You must be in %r to complete this operation.' % localchan)
|
||||
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:
|
||||
irc.error('No network named %r exists.' % remotenet)
|
||||
@ -2308,8 +2313,8 @@ def link(irc, source, args):
|
||||
"as %r." % (remotenet, args.channel, link[1]))
|
||||
return
|
||||
|
||||
if args.force:
|
||||
permissions.check_permissions(irc, source, ['relay.link.force'])
|
||||
if args.force_ts:
|
||||
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,
|
||||
args.channel)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user