Revert ban description-related commits.

Squashed commit of the following:

commit ea4743caa8bdc7abba99635898ae09a9497c43d3
Author: Valentin Lorentz <progval@progval.net>
Date:   Sun May 24 01:07:49 2015 +0200

    Revert "Channel & core: Add support for ban descriptions. Closes GH-1092."

    This reverts commit 6efea561a5.

    Conflicts:
    	src/ircdb.py

commit d43b9229fe926869852c4abda1da1b18a0093938
Author: Valentin Lorentz <progval@progval.net>
Date:   Sun May 24 01:06:30 2015 +0200

    Revert "Fix import of channel database."

    This reverts commit 8ed5522da0.

commit 6c453d9acb3dc37711cb4d51abd9fe216ca65c08
Author: Valentin Lorentz <progval@progval.net>
Date:   Sun May 24 01:06:27 2015 +0200

    Revert "Fix previous commit."

    This reverts commit 394f1554f7.
This commit is contained in:
Valentin Lorentz 2015-05-24 01:08:54 +02:00
parent 394f1554f7
commit f85395d8b1
3 changed files with 17 additions and 36 deletions

View File

@ -575,8 +575,8 @@ class Channel(callbacks.Plugin):
hostmask = wrap(hostmask, ['op', ('haveHalfop+', _('ban someone')), 'text']) hostmask = wrap(hostmask, ['op', ('haveHalfop+', _('ban someone')), 'text'])
@internationalizeDocstring @internationalizeDocstring
def add(self, irc, msg, args, channel, banmask, expires, description): def add(self, irc, msg, args, channel, banmask, expires):
"""[<channel>] <nick|hostmask> [<expires>] [<description>] """[<channel>] <nick|hostmask> [<expires>]
If you have the #channel,op capability, this will effect a If you have the #channel,op capability, this will effect a
persistent ban from interacting with the bot on the given persistent ban from interacting with the bot on the given
@ -589,11 +589,10 @@ class Channel(callbacks.Plugin):
channel itself. channel itself.
""" """
c = ircdb.channels.getChannel(channel) c = ircdb.channels.getChannel(channel)
c.addBan(banmask, expires or 0, description) c.addBan(banmask, expires)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
add = wrap(add, ['op', first('hostmask', 'banmask'), add = wrap(add, ['op', first('hostmask', 'banmask'), additional('expiry', 0)])
optional('expiry'), optional('text')])
@internationalizeDocstring @internationalizeDocstring
def remove(self, irc, msg, args, channel, banmask): def remove(self, irc, msg, args, channel, banmask):
@ -631,16 +630,12 @@ class Channel(callbacks.Plugin):
if filtered_bans: if filtered_bans:
bans = [] bans = []
for ban in filtered_bans: for ban in filtered_bans:
(expiration, description) = all_bans[ban] if all_bans[ban]:
if expiration: bans.append(format(_('%q (expires %t)'),
bans.append(format(_('%q (%s, expires %t)'), ban, all_bans[ban]))
ban,
description or _('no description'),
expiration))
else: else:
bans.append(format(_('%q (%s, never expires)'), bans.append(format(_('%q (never expires)'),
ban, ban, all_bans[ban]))
description or _('no description')))
irc.reply(format('%L', bans)) irc.reply(format('%L', bans))
else: else:
irc.reply(format(_('There are no persistent bans on %s.'), irc.reply(format(_('There are no persistent bans on %s.'),

View File

@ -234,15 +234,7 @@ class ChannelTestCase(ChannelPluginTestCase):
self.assertRegexp('ban list foobar!*@baz', r'.*foobar!\*@baz.*') self.assertRegexp('ban list foobar!*@baz', r'.*foobar!\*@baz.*')
self.assertRegexp('ban list foobar!*@baz', r'.*foobar!qux@baz.*') self.assertRegexp('ban list foobar!*@baz', r'.*foobar!qux@baz.*')
self.assertResponse('ban list foobar!\*@baz', self.assertResponse('ban list foobar!\*@baz',
'"foobar!*@baz" (no description, never expires)') '"foobar!*@baz" (never expires)')
self.assertNotError('ban add foobarbaz!qux@baz foo')
self.assertResponse('ban list foobarbaz!*@baz',
'"foobarbaz!qux@baz" (foo, never expires)')
self.assertNotError('ban add foobarbazqux!qux@baz 5 bar')
self.assertRegexp('ban list foobarbazqux!*@baz',
r'"foobarbazqux!qux@baz" \(bar, expires [^ ]+\)')
def testIgnore(self): def testIgnore(self):
orig = conf.supybot.protocols.irc.banmask() orig = conf.supybot.protocols.irc.banmask()

View File

@ -389,11 +389,11 @@ class IrcChannel(object):
self.capabilities, self.lobotomized, self.capabilities, self.lobotomized,
self.defaultAllow, self.silences, self.exceptions) self.defaultAllow, self.silences, self.exceptions)
def addBan(self, hostmask, expiration=0, description=None): def addBan(self, hostmask, expiration=0):
"""Adds a ban to the channel banlist.""" """Adds a ban to the channel banlist."""
assert not conf.supybot.protocols.irc.strictRfc() or \ assert not conf.supybot.protocols.irc.strictRfc() or \
ircutils.isUserHostmask(hostmask), 'got %s' % hostmask ircutils.isUserHostmask(hostmask), 'got %s' % hostmask
self.bans[hostmask] = (int(expiration), description) 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."""
@ -405,7 +405,7 @@ class IrcChannel(object):
"""Checks whether a given hostmask is banned by the channel banlist.""" """Checks whether a given hostmask is banned by the channel banlist."""
assert ircutils.isUserHostmask(hostmask), 'got %s' % hostmask assert ircutils.isUserHostmask(hostmask), 'got %s' % hostmask
now = time.time() now = time.time()
for (pattern, (expiration, description)) in self.bans.items(): for (pattern, expiration) in self.bans.items():
if now < expiration or not expiration: if now < expiration or not expiration:
if ircutils.hostmaskPatternEqual(pattern, hostmask): if ircutils.hostmaskPatternEqual(pattern, hostmask):
return True return True
@ -478,11 +478,9 @@ class IrcChannel(object):
for capability in self.capabilities: for capability in self.capabilities:
write('capability ' + capability) write('capability ' + capability)
bans = self.bans.items() bans = self.bans.items()
bans = [(x, (y, None) if isinstance(y, int) else y) utils.sortBy(operator.itemgetter(1), bans)
for (x, y) in bans] for (ban, expiration) in bans:
utils.sortBy(lambda x:x[1][0], bans) write('ban %s %d' % (ban, expiration))
for (ban, (expiration, description)) in bans:
write('ban %s %d %s' % (ban, expiration, description))
ignores = self.ignores.items() ignores = self.ignores.items()
utils.sortBy(operator.itemgetter(1), ignores) utils.sortBy(operator.itemgetter(1), ignores)
for (ignore, expiration) in ignores: for (ignore, expiration) in ignores:
@ -592,11 +590,7 @@ class IrcChannelCreator(Creator):
def ban(self, rest, lineno): def ban(self, rest, lineno):
self._checkId() self._checkId()
parts = rest.split(None, 2) (pattern, expiration) = rest.split()
if len(parts) == 2: # Old format
(pattern, expiration) = parts
else:
(pattern, expiration, description) = parts
self.c.bans[pattern] = int(float(expiration)) self.c.bans[pattern] = int(float(expiration))
def ignore(self, rest, lineno): def ignore(self, rest, lineno):