mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-24 03:29:28 +01:00
applyModes: chop off the +/- part of each mode tuple when storing mode lists
Also update these tests accordingly.
This commit is contained in:
parent
f1e26b6c55
commit
48c3b4b2e9
@ -182,19 +182,19 @@ class TestInspIRCdProtocol(unittest.TestCase):
|
||||
|
||||
def testHandleFjoinModes(self):
|
||||
self.irc.run(':70M FJOIN #Chat 1423790411 +nt :,10XAAAAAA ,10XAAAAAB')
|
||||
self.assertEqual({('+n', None), ('+t', None)}, self.irc.channels['#chat'].modes)
|
||||
self.assertEqual({('n', None), ('t', None)}, self.irc.channels['#chat'].modes)
|
||||
# Sequential FJOINs must NOT remove existing modes
|
||||
self.irc.run(':70M FJOIN #Chat 1423790412 + :,10XAAAAAC')
|
||||
self.assertEqual({('+n', None), ('+t', None)}, self.irc.channels['#chat'].modes)
|
||||
self.assertEqual({('n', None), ('t', None)}, self.irc.channels['#chat'].modes)
|
||||
|
||||
def testHandleFjoinModesWithArgs(self):
|
||||
self.irc.run(':70M FJOIN #Chat 1423790414 +nlks 10 t0psekrit :,10XAAAAAA ,10XAAAAAB')
|
||||
self.assertEqual({('+n', None), ('+s', None), ('+l', '10'), ('+k', 't0psekrit')},
|
||||
self.assertEqual({('n', None), ('s', None), ('l', '10'), ('k', 't0psekrit')},
|
||||
self.irc.channels['#chat'].modes)
|
||||
|
||||
def testHandleFjoinPrefixes(self):
|
||||
self.irc.run(':70M FJOIN #Chat 1423790418 +nt :ov,10XAAAAAA v,10XAAAAAB ,10XAAAAAC')
|
||||
self.assertEqual({('+n', None), ('+t', None)}, self.irc.channels['#chat'].modes)
|
||||
self.assertEqual({('n', None), ('t', None)}, self.irc.channels['#chat'].modes)
|
||||
self.assertEqual({'10XAAAAAA', '10XAAAAAB', '10XAAAAAC'}, self.irc.channels['#chat'].users)
|
||||
self.assertIn('10XAAAAAA', self.irc.channels['#chat'].prefixmodes['ops'])
|
||||
self.assertEqual({'10XAAAAAA', '10XAAAAAB'}, self.irc.channels['#chat'].prefixmodes['voices'])
|
||||
@ -202,18 +202,18 @@ class TestInspIRCdProtocol(unittest.TestCase):
|
||||
def testHandleFmode(self):
|
||||
self.irc.run(':70M FJOIN #pylink 1423790411 +n :o,10XAAAAAA ,10XAAAAAB')
|
||||
self.irc.run(':70M FMODE #pylink 1423790412 +ikl herebedragons 100')
|
||||
self.assertEqual({('+i', None), ('+k', 'herebedragons'), ('+l', '100'), ('+n', None)}, self.irc.channels['#pylink'].modes)
|
||||
self.assertEqual({('i', None), ('k', 'herebedragons'), ('l', '100'), ('n', None)}, self.irc.channels['#pylink'].modes)
|
||||
self.irc.run(':70M FMODE #pylink 1423790413 -ilk+m herebedragons')
|
||||
self.assertEqual({('+m', None), ('+n', None)}, self.irc.channels['#pylink'].modes)
|
||||
self.assertEqual({('m', None), ('n', None)}, self.irc.channels['#pylink'].modes)
|
||||
|
||||
def testHandleFmodeWithPrefixes(self):
|
||||
self.irc.run(':70M FJOIN #pylink 1423790411 +n :o,10XAAAAAA ,10XAAAAAB')
|
||||
# Prefix modes are stored separately, so they should never show up in .modes
|
||||
self.assertNotIn(('+o', '10XAAAAAA'), self.irc.channels['#pylink'].modes)
|
||||
self.assertNotIn(('o', '10XAAAAAA'), self.irc.channels['#pylink'].modes)
|
||||
self.assertEqual({'10XAAAAAA'}, self.irc.channels['#pylink'].prefixmodes['ops'])
|
||||
self.irc.run(':70M FMODE #pylink 1423790412 +lot 50 %s' % self.u)
|
||||
self.assertIn(self.u, self.irc.channels['#pylink'].prefixmodes['ops'])
|
||||
modes = {('+l', '50'), ('+n', None), ('+t', None)}
|
||||
modes = {('l', '50'), ('n', None), ('t', None)}
|
||||
self.assertEqual(modes, self.irc.channels['#pylink'].modes)
|
||||
self.irc.run(':70M FMODE #pylink 1423790413 -o %s' % self.u)
|
||||
self.assertEqual(modes, self.irc.channels['#pylink'].modes)
|
||||
|
19
utils.py
19
utils.py
@ -128,6 +128,10 @@ def parseModes(irc, target, args):
|
||||
return res
|
||||
|
||||
def applyModes(irc, target, changedmodes):
|
||||
"""<target> <changedmodes>
|
||||
|
||||
Takes a list of parsed IRC modes (<changedmodes>, in the format of parseModes()), and applies them on <target>.
|
||||
<target> can be either a channel or a user; this is handled automatically."""
|
||||
usermodes = not isChannel(target)
|
||||
log.debug('(%s) Using usermodes for this query? %s', irc.name, usermodes)
|
||||
if usermodes:
|
||||
@ -136,10 +140,12 @@ def applyModes(irc, target, changedmodes):
|
||||
modelist = irc.channels[target].modes
|
||||
log.debug('(%s) Applying modes %r on %s (initial modelist: %s)', irc.name, changedmodes, target, modelist)
|
||||
for mode in changedmodes:
|
||||
# Chop off the +/- part that parseModes gives; it's meaningless for a mode list.
|
||||
real_mode = (mode[0][1], mode[1])
|
||||
if not usermodes:
|
||||
pmode = ''
|
||||
for m in ('owner', 'admin', 'op', 'halfop', 'voice'):
|
||||
if m in irc.cmodes and mode[0][1] == irc.cmodes[m]:
|
||||
if m in irc.cmodes and real_mode[0] == irc.cmodes[m]:
|
||||
pmode = m+'s'
|
||||
if pmode:
|
||||
pmodelist = irc.channels[target].prefixmodes[pmode]
|
||||
@ -149,26 +155,25 @@ def applyModes(irc, target, changedmodes):
|
||||
else:
|
||||
pmodelist.discard(mode[1])
|
||||
log.debug('(%s) Final prefixmodes list: %s', irc.name, irc.channels[target].prefixmodes)
|
||||
if mode[0][1] in irc.prefixmodes:
|
||||
if real_mode[0] in irc.prefixmodes:
|
||||
# Ignore other prefix modes such as InspIRCd's +Yy
|
||||
log.debug('(%s) Not adding mode %s to IrcChannel.modes because it\'s a prefix mode', irc.name, str(mode))
|
||||
continue
|
||||
if mode[0][0] == '+':
|
||||
# We're adding a mode
|
||||
modelist.add(mode)
|
||||
modelist.add(real_mode)
|
||||
log.debug('(%s) Adding mode %r on %s', irc.name, mode, target)
|
||||
else:
|
||||
log.debug('(%s) Removing mode %r on %s', irc.name, mode, target)
|
||||
# We're removing a mode
|
||||
if mode[1] is None:
|
||||
if real_mode[1] is None:
|
||||
# We're removing a mode that only takes arguments when setting.
|
||||
for oldmode in modelist.copy():
|
||||
if oldmode[0][1] == mode[0][1]:
|
||||
if oldmode[0] == real_mode[0]:
|
||||
modelist.discard(oldmode)
|
||||
else:
|
||||
# Swap the - for a + and then remove it from the list.
|
||||
mode = ('+' + mode[0][1], mode[1])
|
||||
modelist.discard(mode)
|
||||
modelist.discard(real_mode)
|
||||
log.debug('(%s) Final modelist: %s', irc.name, modelist)
|
||||
|
||||
def joinModes(modes):
|
||||
|
Loading…
Reference in New Issue
Block a user