When only --account is provided, fallback to supybot.protocols.irc.banmask before exact mask

This commit is contained in:
Valentin Lorentz 2024-07-19 13:34:18 +02:00
parent cf63674f7c
commit 54f7b5a5b6
2 changed files with 33 additions and 2 deletions

View File

@ -237,7 +237,17 @@ class ChannelTestCase(ChannelPluginTestCase):
'foobar!user@host.domain.tld')
join()
self.assertKban('kban --account foobar',
'foobar!user@host.domain.tld')
'*!*@host.domain.tld')
join()
with conf.supybot.protocols.irc.banmask.context(['user', 'host']):
# falls back from --account to config
self.assertKban('kban --account foobar',
'*!user@host.domain.tld')
join()
with conf.supybot.protocols.irc.banmask.context(['account']):
# falls back from --account to config, then to exact hostmask
self.assertKban('kban --account foobar',
'foobar!user@host.domain.tld')
join()
self.assertKban('kban --account --host foobar',
'*!*@host.domain.tld')
@ -259,7 +269,17 @@ class ChannelTestCase(ChannelPluginTestCase):
'foobar!user@host.domain.tld')
join()
self.assertKban('kban --account foobar',
'foobar!user@host.domain.tld')
'*!*@host.domain.tld')
join()
with conf.supybot.protocols.irc.banmask.context(['user', 'host']):
# falls back from --account to config
self.assertKban('kban --account foobar',
'*!user@host.domain.tld')
join()
with conf.supybot.protocols.irc.banmask.context(['account']):
# falls back from --account to config, then to exact hostmask
self.assertKban('kban --account foobar',
'foobar!user@host.domain.tld')
join()
self.assertKban('kban --account --host foobar',
'*!*@host.domain.tld')

View File

@ -1302,6 +1302,17 @@ class Banmask(registry.SpaceSeparatedSetOfStrings):
if add_star_mask and (bnick, buser, bhost) != ('*', '*', '*'):
masks.append(ircutils.joinHostmask(bnick, buser, bhost))
if (bnick, buser, bhost) == ('*', '*', '*') and \
options == ['account'] and \
not masks:
# found no ban mask to set (because options == ['account'] and user
# is logged out?), try again with the default ban mask
options = supybot.protocols.irc.banmask.getSpecific(
network, channel)()
options = [option for option in options if option != 'account']
return self.makeExtBanmasks(
hostmask, options=options, channel=channel, network=network)
if (bnick, buser, bhost) == ('*', '*', '*') and \
ircutils.isUserHostmask(hostmask) and \
not masks: