Add support for extended banmasks. Closes GH-105.

This commit is contained in:
Valentin Lorentz 2012-12-02 19:04:48 +01:00
parent 650cbe548a
commit 93586d71f4
4 changed files with 26 additions and 4 deletions

View File

@ -342,7 +342,13 @@ class Channel(callbacks.Plugin):
banmaskstyle = conf.supybot.protocols.irc.banmask banmaskstyle = conf.supybot.protocols.irc.banmask
banmask = banmaskstyle.makeBanmask(bannedHostmask, [o[0] for o in optlist]) banmask = banmaskstyle.makeBanmask(bannedHostmask, [o[0] for o in optlist])
except KeyError: except KeyError:
irc.error(format(_('I haven\'t seen %s.'), bannedNick), Raise=True) if not conf.supybot.protocols.irc.strictRfc() and \
target.startswith('$'):
# Select the last part, or the whole target:
bannedNick = target.split(':')[-1]
banmask = bannedHostmask = target
else:
irc.error(format(_('I haven\'t seen %s.'), bannedNick), Raise=True)
else: else:
bannedNick = ircutils.nickFromHostmask(target) bannedNick = ircutils.nickFromHostmask(target)
banmask = bannedHostmask = target banmask = bannedHostmask = target

View File

@ -173,6 +173,13 @@ class ChannelTestCase(ChannelPluginTestCase):
self.assertBan('iban foo!bar@baz', 'foo!bar@baz') self.assertBan('iban foo!bar@baz', 'foo!bar@baz')
self.assertBan('iban foobar', 'foobar!user@host.domain.tld') self.assertBan('iban foobar', 'foobar!user@host.domain.tld')
conf.supybot.protocols.irc.strictRfc.setValue(True)
self.assertError('iban $a:nyuszika7h')
self.assertError('unban $a:nyuszika7h')
conf.supybot.protocols.irc.strictRfc.setValue(False)
self.assertBan('iban $a:nyuszika7h', '$a:nyuszika7h')
self.assertNotError('unban $a:nyuszika7h')
## def testKban(self): ## def testKban(self):
## self.irc.prefix = 'something!else@somehwere.else' ## self.irc.prefix = 'something!else@somehwere.else'
## self.irc.nick = 'something' ## self.irc.nick = 'something'
@ -209,6 +216,11 @@ class ChannelTestCase(ChannelPluginTestCase):
# is being called but the assert is failing # is being called but the assert is failing
self.assertError('ban add not!a.hostmask') self.assertError('ban add not!a.hostmask')
self.assertNotRegexp('ban add not!a.hostmask', 'KeyError') self.assertNotRegexp('ban add not!a.hostmask', 'KeyError')
self.assertError('ban add $a:nyuszika7h')
self.assertError('ban remove $a:nyuszika7h')
conf.supybot.protocols.irc.strictRfc.setValue(False)
self.assertNotError('ban add $a:nyuszika7h')
self.assertNotError('ban remove $a:nyuszika7h')
finally: finally:
conf.supybot.protocols.irc.strictRfc.setValue(orig) conf.supybot.protocols.irc.strictRfc.setValue(orig)
finally: finally:

View File

@ -351,7 +351,9 @@ def validChannel(irc, msg, args, state):
state.errorInvalid(_('channel'), args[0]) state.errorInvalid(_('channel'), args[0])
def getHostmask(irc, msg, args, state): def getHostmask(irc, msg, args, state):
if ircutils.isUserHostmask(args[0]): if ircutils.isUserHostmask(args[0]) or \
(not conf.supybot.protocols.irc.strictRfc() and
args[0].startswith('$')):
state.args.append(args.pop(0)) state.args.append(args.pop(0))
else: else:
try: try:

View File

@ -387,12 +387,14 @@ class IrcChannel(object):
def addBan(self, hostmask, expiration=0): def addBan(self, hostmask, expiration=0):
"""Adds a ban to the channel banlist.""" """Adds a ban to the channel banlist."""
assert ircutils.isUserHostmask(hostmask), 'got %s' % hostmask assert not conf.supybot.protocols.irc.strictRfc() or \
ircutils.isUserHostmask(hostmask), 'got %s' % hostmask
self.bans[hostmask] = int(expiration) self.bans[hostmask] = int(expiration)
def removeBan(self, hostmask): def removeBan(self, hostmask):
"""Removes a ban from the channel banlist.""" """Removes a ban from the channel banlist."""
assert ircutils.isUserHostmask(hostmask), 'got %s' % hostmask assert not conf.supybot.protocols.irc.strictRfc() or \
ircutils.isUserHostmask(hostmask), 'got %s' % hostmask
return self.bans.pop(hostmask) return self.bans.pop(hostmask)
def checkBan(self, hostmask): def checkBan(self, hostmask):