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

utils.applyModes: operate on a copy of the original modelist

This prevents bugs where mode changes are applied to the wrong users (possibly due to the scope not clearing).
This commit is contained in:
James Lu 2015-07-08 23:11:44 -07:00
parent 27bb6af7f6
commit b27fcc7f8f

View File

@ -143,11 +143,12 @@ def applyModes(irc, target, changedmodes):
usermodes = not isChannel(target) usermodes = not isChannel(target)
log.debug('(%s) Using usermodes for this query? %s', irc.name, usermodes) log.debug('(%s) Using usermodes for this query? %s', irc.name, usermodes)
if usermodes: if usermodes:
modelist = irc.users[target].modes old_modelist = irc.users[target].modes
supported_modes = irc.umodes supported_modes = irc.umodes
else: else:
modelist = irc.channels[target].modes old_modelist = irc.channels[target].modes
supported_modes = irc.cmodes supported_modes = irc.cmodes
modelist = old_modelist.copy()
log.debug('(%s) Applying modes %r on %s (initial modelist: %s)', irc.name, changedmodes, target, modelist) log.debug('(%s) Applying modes %r on %s (initial modelist: %s)', irc.name, changedmodes, target, modelist)
for mode in changedmodes: for mode in changedmodes:
# Chop off the +/- part that parseModes gives; it's meaningless for a mode list. # Chop off the +/- part that parseModes gives; it's meaningless for a mode list.
@ -197,6 +198,10 @@ def applyModes(irc, target, changedmodes):
# Swap the - for a + and then remove it from the list. # Swap the - for a + and then remove it from the list.
modelist.discard(real_mode) modelist.discard(real_mode)
log.debug('(%s) Final modelist: %s', irc.name, modelist) log.debug('(%s) Final modelist: %s', irc.name, modelist)
if usermodes:
irc.users[target].modes = modelist
else:
irc.channels[target].modes = modelist
def joinModes(modes): def joinModes(modes):
"""<mode list> """<mode list>