mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-23 19:19:31 +01:00
core: Depluralize prefixmodes mappings (#168)
This is an API breaking change. I really don't know why I made these keys plural to start, since it only made things more complicated. Prefix modes are not pluralized in the list of supported modes of each IRCd.
This commit is contained in:
parent
1d4350c4fd
commit
8135f3a735
@ -573,8 +573,8 @@ class IrcChannel():
|
||||
self.modes = {('n', None), ('t', None)}
|
||||
self.topic = ''
|
||||
self.ts = int(time.time())
|
||||
self.prefixmodes = {'ops': set(), 'halfops': set(), 'voices': set(),
|
||||
'owners': set(), 'admins': set()}
|
||||
self.prefixmodes = {'op': set(), 'halfop': set(), 'voice': set(),
|
||||
'owner': set(), 'admin': set()}
|
||||
|
||||
# Determines whether a topic has been set here or not. Protocol modules
|
||||
# should set this.
|
||||
|
@ -62,7 +62,7 @@ def handle_whois(irc, source, command, args):
|
||||
# Show prefix modes like a regular IRCd does.
|
||||
for prefixmode, prefixchar in irc.prefixmodes.items():
|
||||
modename = [mname for mname, char in irc.cmodes.items() if char == prefixmode]
|
||||
if modename and target in c.prefixmodes[modename[0]+'s']:
|
||||
if modename and target in c.prefixmodes[modename[0]]:
|
||||
chan = prefixchar + chan
|
||||
public_chans.append(chan)
|
||||
if public_chans: # Only send the line if the person is in any visible channels...
|
||||
|
@ -151,7 +151,7 @@ def showchan(irc, source, args):
|
||||
for user, nick in sorted(zip(c.users, nicks),
|
||||
key=lambda userpair: userpair[1].lower()):
|
||||
prefixmodes = [irc.prefixmodes.get(irc.cmodes.get(pmode, ''), '')
|
||||
for pmode in pmodes if user in c.prefixmodes[pmode+'s']]
|
||||
for pmode in pmodes if user in c.prefixmodes[pmode]]
|
||||
nicklist.append(''.join(prefixmodes) + nick)
|
||||
|
||||
while nicklist[:20]: # 20 nicks per line to prevent message cutoff.
|
||||
|
@ -203,8 +203,8 @@ def getPrefixModes(irc, remoteirc, channel, user, mlist=None):
|
||||
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:
|
||||
# {'ops': ['user1', 'user2'], 'voices': ['user3', 'user4'], ...}
|
||||
userlist = mlist[pmode+'s']
|
||||
# {'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:
|
||||
@ -683,7 +683,7 @@ def relayModes(irc, remoteirc, sender, channel, modes=None):
|
||||
log.debug("(%s) relay.relayModes: argument found as (%r, %r) "
|
||||
"for network %r.",
|
||||
irc.name, modechar, arg, remoteirc.name)
|
||||
oplist = remoteirc.channels[remotechan].prefixmodes[name+'s']
|
||||
oplist = remoteirc.channels[remotechan].prefixmodes[name]
|
||||
|
||||
log.debug("(%s) relay.relayModes: list of %ss on %r is: %s",
|
||||
irc.name, name, remotechan, oplist)
|
||||
|
37
utils.py
37
utils.py
@ -291,25 +291,30 @@ def applyModes(irc, target, changedmodes):
|
||||
real_mode = (mode[0][1], mode[1])
|
||||
except IndexError:
|
||||
real_mode = mode
|
||||
|
||||
if not usermodes:
|
||||
pmode = ''
|
||||
for m in ('owner', 'admin', 'op', 'halfop', 'voice'):
|
||||
if m in irc.cmodes and real_mode[0] == irc.cmodes[m]:
|
||||
pmode = m+'s'
|
||||
if pmode:
|
||||
pmodelist = irc.channels[target].prefixmodes[pmode]
|
||||
log.debug('(%s) Initial prefixmodes list: %s', irc.name, irc.channels[target].prefixmodes)
|
||||
if mode[0][0] == '+':
|
||||
pmodelist.add(mode[1])
|
||||
else:
|
||||
pmodelist.discard(mode[1])
|
||||
irc.channels[target].prefixmodes[pmode] = pmodelist
|
||||
log.debug('(%s) Final prefixmodes list: %s', irc.name, irc.channels[target].prefixmodes)
|
||||
# We only handle +qaohv for now. Iterate over every supported mode:
|
||||
# if the IRCd supports this mode and it is the one being set, add/remove
|
||||
# the person from the corresponding prefix mode list (e.g. c.prefixmodes['op']
|
||||
# for ops).
|
||||
for pmode in ('owner', 'admin', 'op', 'halfop', 'voice'):
|
||||
if pmode in irc.cmodes and real_mode[0] == irc.cmodes[pmode]:
|
||||
pmodelist = irc.channels[target].prefixmodes[pmode]
|
||||
log.debug('(%s) Initial prefixmodes list: %s', irc.name, irc.channels[target].prefixmodes)
|
||||
if mode[0][0] == '+':
|
||||
pmodelist.add(mode[1])
|
||||
else:
|
||||
pmodelist.discard(mode[1])
|
||||
|
||||
log.debug('(%s) Final prefixmodes list: %s', irc.name, irc.channels[target].prefixmodes)
|
||||
|
||||
if real_mode[0] in irc.prefixmodes:
|
||||
# Ignore other prefix modes such as InspIRCd's +Yy
|
||||
# Don't add prefix modes to IrcChannel.modes; they belong in the
|
||||
# prefixmodes mapping handled above.
|
||||
log.debug('(%s) Not adding mode %s to IrcChannel.modes because '
|
||||
'it\'s a prefix mode we don\'t care about.', irc.name, str(mode))
|
||||
'it\'s a prefix mode.', irc.name, str(mode))
|
||||
continue
|
||||
|
||||
if mode[0][0] == '+':
|
||||
# We're adding a mode
|
||||
existing = [m for m in modelist if m[0] == real_mode[0] and m[1] != real_mode[1]]
|
||||
@ -417,7 +422,7 @@ def reverseModes(irc, target, modes, oldobj=None):
|
||||
possible_modes['*A'] += ''.join(irc.prefixmodes)
|
||||
for name, userlist in c.prefixmodes.items():
|
||||
try:
|
||||
oldmodes.update([(irc.cmodes[name[:-1]], u) for u in userlist])
|
||||
oldmodes.update([(irc.cmodes[name], u) for u in userlist])
|
||||
except KeyError:
|
||||
continue
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user