3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 01:09:22 +01:00

apply_modes: fix removing multiple ban modes in one command

This commit is contained in:
James Lu 2019-12-22 23:52:02 -08:00
parent 847c26cd7b
commit a79354cd52
2 changed files with 21 additions and 4 deletions

View File

@ -1106,10 +1106,11 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore):
existing = mapping.get(real_mode[0]) existing = mapping.get(real_mode[0])
arg = real_mode[1] arg = real_mode[1]
# When removing a mode: check all existing modes with the same character # Mode requires argument for removal (case insensitive)
# If no args were needed on removal, remove all modes with that letter if real_mode[0] in (supported_modes['*A'] + supported_modes['*B']):
# If an arg was given, remove all modes matching the arg (IRC case insensitive) modelist.discard((real_mode[0], self.to_lower(arg)))
if existing is not None: # Mode does not require argument for removal - remove all modes entries with the same character
else:
while existing: while existing:
oldvalue = existing.pop() oldvalue = existing.pop()
if arg is None or self.to_lower(arg) == self.to_lower(oldvalue): if arg is None or self.to_lower(arg) == self.to_lower(oldvalue):

View File

@ -575,6 +575,13 @@ class BaseProtocolTest(unittest.TestCase):
self.p.apply_modes('#', [('+n', None), ('-i', None)]) self.p.apply_modes('#', [('+n', None), ('-i', None)])
self.assertEqual(c.modes, {('n', None)}) self.assertEqual(c.modes, {('n', None)})
c = self.p.channels['#Magic'] = Channel(self.p, name='#Magic')
self.p.apply_modes('#Magic', [('+m', None), ('+n', None), ('+i', None)])
self.assertEqual(c.modes, {('m', None), ('n', None), ('i', None)}, "Modes should be added")
self.p.apply_modes('#Magic', [('-i', None), ('-n', None)])
self.assertEqual(c.modes, {('m', None)}, "Modes should be removed")
def test_apply_modes_channel_remove_nonexistent(self): def test_apply_modes_channel_remove_nonexistent(self):
c = self.p.channels['#abc'] = Channel(self.p, name='#abc') c = self.p.channels['#abc'] = Channel(self.p, name='#abc')
self.p.apply_modes('#abc', [('+t', None)]) self.p.apply_modes('#abc', [('+t', None)])
@ -634,6 +641,15 @@ class BaseProtocolTest(unittest.TestCase):
self.p.apply_modes('#Magic', [('-b', '*!*@BEST.HOST')]) self.p.apply_modes('#Magic', [('-b', '*!*@BEST.HOST')])
self.assertFalse(c.modes, "Ban on *!*@best.host should be removed (different case)") self.assertFalse(c.modes, "Ban on *!*@best.host should be removed (different case)")
def test_apply_modes_channel_ban_multiple(self):
c = self.p.channels['#Magic'] = Channel(self.p, name='#Magic')
self.p.apply_modes('#Magic', [('+b', '*!*@test.host'), ('+b', '*!*@best.host'), ('+b', '*!*@guest.host')])
self.assertEqual(c.modes, {('b', '*!*@test.host'), ('b', '*!*@best.host'), ('b', '*!*@guest.host')},
"Bans should be added")
self.p.apply_modes('#Magic', [('-b', '*!*@best.host'), ('-b', '*!*@guest.host'), ('-b', '*!*@test.host')])
self.assertEqual(c.modes, set(), "Bans should be removed")
def test_apply_modes_channel_mode_cycle(self): def test_apply_modes_channel_mode_cycle(self):
c = self.p.channels['#Magic'] = Channel(self.p, name='#Magic') c = self.p.channels['#Magic'] = Channel(self.p, name='#Magic')
self.p.apply_modes('#Magic', [('+b', '*!*@example.net'), ('-b', '*!*@example.net')]) self.p.apply_modes('#Magic', [('+b', '*!*@example.net'), ('-b', '*!*@example.net')])