3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 03:29:28 +01:00

relay: use IrcChannel.getPrefixModes

This commit is contained in:
James Lu 2016-03-19 17:54:42 -07:00
parent e948db5c7b
commit c86a02e044

View File

@ -195,19 +195,10 @@ def getPrefixModes(irc, remoteirc, channel, user, mlist=None):
""" """
modes = '' modes = ''
# Get the mapping of all the channel's prefix modes if user in irc.channels[channel].users:
mlist = mlist or irc.channels[channel].prefixmodes # Iterate over the the prefix modes for relay supported by IRCd
for pmode in irc.channels[channel].getPrefixModes(user, prefixmodes=mlist):
# Iterate over the the supported prefix modes for relay if pmode in remoteirc.cmodes:
for pmode in ('owner', 'admin', 'op', 'halfop', 'voice'):
if pmode in remoteirc.cmodes: # If the mode supported by IRCd
# Check if the caller is in the prefix modes list for that
# prefix.prefixmodes mapping looks like:
# {'op': ['user1', 'user2'], 'voice': ['user3', 'user4'], ...}
userlist = mlist[pmode]
log.debug('(%s) relay.getPrefixModes: checking if %r is in %s list: %r',
irc.name, user, pmode, userlist)
if user in userlist:
modes += remoteirc.cmodes[pmode] modes += remoteirc.cmodes[pmode]
return modes return modes
@ -466,9 +457,11 @@ def checkClaim(irc, channel, sender, chanobj=None):
mlist = chanobj.prefixmodes mlist = chanobj.prefixmodes
except AttributeError: except AttributeError:
mlist = None mlist = None
sender_modes = getPrefixModes(irc, irc, channel, sender, mlist=mlist) sender_modes = getPrefixModes(irc, irc, channel, sender, mlist=mlist)
log.debug('(%s) relay.checkClaim: sender modes (%s/%s) are %s (mlist=%s)', irc.name, log.debug('(%s) relay.checkClaim: sender modes (%s/%s) are %s (mlist=%s)', irc.name,
sender, channel, sender_modes, mlist) sender, channel, sender_modes, mlist)
# XXX: stop hardcoding modes to check for and support mlist in isHalfopPlus and friends
return (not relay) or irc.name == relay[0] or not db[relay]['claim'] or \ return (not relay) or irc.name == relay[0] or not db[relay]['claim'] or \
irc.name in db[relay]['claim'] or \ irc.name in db[relay]['claim'] or \
any([mode in sender_modes for mode in ('y', 'q', 'a', 'o', 'h')]) \ any([mode in sender_modes for mode in ('y', 'q', 'a', 'o', 'h')]) \