mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 07:34:08 +01:00
Add support for extended banmasks. Closes GH-105.
This commit is contained in:
parent
650cbe548a
commit
93586d71f4
@ -342,7 +342,13 @@ class Channel(callbacks.Plugin):
|
||||
banmaskstyle = conf.supybot.protocols.irc.banmask
|
||||
banmask = banmaskstyle.makeBanmask(bannedHostmask, [o[0] for o in optlist])
|
||||
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:
|
||||
bannedNick = ircutils.nickFromHostmask(target)
|
||||
banmask = bannedHostmask = target
|
||||
|
@ -173,6 +173,13 @@ class ChannelTestCase(ChannelPluginTestCase):
|
||||
self.assertBan('iban foo!bar@baz', 'foo!bar@baz')
|
||||
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):
|
||||
## self.irc.prefix = 'something!else@somehwere.else'
|
||||
## self.irc.nick = 'something'
|
||||
@ -209,6 +216,11 @@ class ChannelTestCase(ChannelPluginTestCase):
|
||||
# is being called but the assert is failing
|
||||
self.assertError('ban add not!a.hostmask')
|
||||
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:
|
||||
conf.supybot.protocols.irc.strictRfc.setValue(orig)
|
||||
finally:
|
||||
|
@ -351,7 +351,9 @@ def validChannel(irc, msg, args, state):
|
||||
state.errorInvalid(_('channel'), args[0])
|
||||
|
||||
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))
|
||||
else:
|
||||
try:
|
||||
|
@ -387,12 +387,14 @@ class IrcChannel(object):
|
||||
|
||||
def addBan(self, hostmask, expiration=0):
|
||||
"""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)
|
||||
|
||||
def removeBan(self, hostmask):
|
||||
"""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)
|
||||
|
||||
def checkBan(self, hostmask):
|
||||
|
Loading…
Reference in New Issue
Block a user