3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 21: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:
James Lu 2016-03-19 17:25:04 -07:00
parent 1d4350c4fd
commit 8135f3a735
5 changed files with 28 additions and 23 deletions

View File

@ -573,8 +573,8 @@ class IrcChannel():
self.modes = {('n', None), ('t', None)} self.modes = {('n', None), ('t', None)}
self.topic = '' self.topic = ''
self.ts = int(time.time()) self.ts = int(time.time())
self.prefixmodes = {'ops': set(), 'halfops': set(), 'voices': set(), self.prefixmodes = {'op': set(), 'halfop': set(), 'voice': set(),
'owners': set(), 'admins': set()} 'owner': set(), 'admin': set()}
# Determines whether a topic has been set here or not. Protocol modules # Determines whether a topic has been set here or not. Protocol modules
# should set this. # should set this.

View File

@ -62,7 +62,7 @@ def handle_whois(irc, source, command, args):
# Show prefix modes like a regular IRCd does. # Show prefix modes like a regular IRCd does.
for prefixmode, prefixchar in irc.prefixmodes.items(): for prefixmode, prefixchar in irc.prefixmodes.items():
modename = [mname for mname, char in irc.cmodes.items() if char == prefixmode] 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 chan = prefixchar + chan
public_chans.append(chan) public_chans.append(chan)
if public_chans: # Only send the line if the person is in any visible channels... if public_chans: # Only send the line if the person is in any visible channels...

View File

@ -151,7 +151,7 @@ def showchan(irc, source, args):
for user, nick in sorted(zip(c.users, nicks), for user, nick in sorted(zip(c.users, nicks),
key=lambda userpair: userpair[1].lower()): key=lambda userpair: userpair[1].lower()):
prefixmodes = [irc.prefixmodes.get(irc.cmodes.get(pmode, ''), '') 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) nicklist.append(''.join(prefixmodes) + nick)
while nicklist[:20]: # 20 nicks per line to prevent message cutoff. while nicklist[:20]: # 20 nicks per line to prevent message cutoff.

View File

@ -203,8 +203,8 @@ def getPrefixModes(irc, remoteirc, channel, user, mlist=None):
if pmode in remoteirc.cmodes: # If the mode supported by IRCd if pmode in remoteirc.cmodes: # If the mode supported by IRCd
# Check if the caller is in the prefix modes list for that # Check if the caller is in the prefix modes list for that
# prefix.prefixmodes mapping looks like: # prefix.prefixmodes mapping looks like:
# {'ops': ['user1', 'user2'], 'voices': ['user3', 'user4'], ...} # {'op': ['user1', 'user2'], 'voice': ['user3', 'user4'], ...}
userlist = mlist[pmode+'s'] userlist = mlist[pmode]
log.debug('(%s) relay.getPrefixModes: checking if %r is in %s list: %r', log.debug('(%s) relay.getPrefixModes: checking if %r is in %s list: %r',
irc.name, user, pmode, userlist) irc.name, user, pmode, userlist)
if user in 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) " log.debug("(%s) relay.relayModes: argument found as (%r, %r) "
"for network %r.", "for network %r.",
irc.name, modechar, arg, remoteirc.name) 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", log.debug("(%s) relay.relayModes: list of %ss on %r is: %s",
irc.name, name, remotechan, oplist) irc.name, name, remotechan, oplist)

View File

@ -291,25 +291,30 @@ def applyModes(irc, target, changedmodes):
real_mode = (mode[0][1], mode[1]) real_mode = (mode[0][1], mode[1])
except IndexError: except IndexError:
real_mode = mode real_mode = mode
if not usermodes: if not usermodes:
pmode = '' # We only handle +qaohv for now. Iterate over every supported mode:
for m in ('owner', 'admin', 'op', 'halfop', 'voice'): # if the IRCd supports this mode and it is the one being set, add/remove
if m in irc.cmodes and real_mode[0] == irc.cmodes[m]: # the person from the corresponding prefix mode list (e.g. c.prefixmodes['op']
pmode = m+'s' # for ops).
if pmode: 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] pmodelist = irc.channels[target].prefixmodes[pmode]
log.debug('(%s) Initial prefixmodes list: %s', irc.name, irc.channels[target].prefixmodes) log.debug('(%s) Initial prefixmodes list: %s', irc.name, irc.channels[target].prefixmodes)
if mode[0][0] == '+': if mode[0][0] == '+':
pmodelist.add(mode[1]) pmodelist.add(mode[1])
else: else:
pmodelist.discard(mode[1]) pmodelist.discard(mode[1])
irc.channels[target].prefixmodes[pmode] = pmodelist
log.debug('(%s) Final prefixmodes list: %s', irc.name, irc.channels[target].prefixmodes) log.debug('(%s) Final prefixmodes list: %s', irc.name, irc.channels[target].prefixmodes)
if real_mode[0] in irc.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 ' 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 continue
if mode[0][0] == '+': if mode[0][0] == '+':
# We're adding a mode # We're adding a mode
existing = [m for m in modelist if m[0] == real_mode[0] and m[1] != real_mode[1]] 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) possible_modes['*A'] += ''.join(irc.prefixmodes)
for name, userlist in c.prefixmodes.items(): for name, userlist in c.prefixmodes.items():
try: try:
oldmodes.update([(irc.cmodes[name[:-1]], u) for u in userlist]) oldmodes.update([(irc.cmodes[name], u) for u in userlist])
except KeyError: except KeyError:
continue continue
else: else: