Remove @baninfo. Ban information is fetched with @duration now.
This commit is contained in:
parent
2e3506c9bd
commit
02e5f2aa10
|
@ -191,6 +191,14 @@ def timeElapsed(elapsed, short=False, resolution=2):
|
||||||
result += ' ago'
|
result += ' ago'
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def splitID(s):
|
||||||
|
"""get a list of integers from a comma separated list of numbers"""
|
||||||
|
for id in s.split(','):
|
||||||
|
if id.isdigit():
|
||||||
|
id = int(id)
|
||||||
|
if id > 0:
|
||||||
|
yield id
|
||||||
|
|
||||||
def capab(user, capability):
|
def capab(user, capability):
|
||||||
capability = capability.lower()
|
capability = capability.lower()
|
||||||
capabilities = list(user.capabilities)
|
capabilities = list(user.capabilities)
|
||||||
|
@ -1535,7 +1543,7 @@ class Bantracker(callbacks.Plugin):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for id in [ int(i) for i in ids.split(',') if i.isdigit() and int(i) > 0 ]:
|
for id in splitID(ids):
|
||||||
try:
|
try:
|
||||||
mask, channel, removal = self._getBan(id)
|
mask, channel, removal = self._getBan(id)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -1574,80 +1582,76 @@ class Bantracker(callbacks.Plugin):
|
||||||
|
|
||||||
comment = wrap(comment, ['something', optional('text')])
|
comment = wrap(comment, ['something', optional('text')])
|
||||||
|
|
||||||
def duration(self, irc, msg, args, ids, timespec):
|
def duration(self, irc, msg, args, ids, duration):
|
||||||
"""<id>[,<id> ...] <duration>
|
"""[<id>[,<id> ...]] [<duration>]
|
||||||
|
|
||||||
Sets expiration time.
|
Sets the duration of a ban. If <duration> isn't given show when a ban expires.
|
||||||
|
If no <id> is given shows the ids of bans set to expire.
|
||||||
"""
|
"""
|
||||||
try:
|
if ids is None:
|
||||||
seconds = readTimeDelta(timespec)
|
|
||||||
except ValueError:
|
|
||||||
irc.error("bad time format.")
|
|
||||||
return
|
|
||||||
|
|
||||||
banset = []
|
|
||||||
for id in [ int(i) for i in ids.split(',') if i.isdigit() and int(i) > 0 ]:
|
|
||||||
try:
|
|
||||||
self._setBanDuration(id, seconds)
|
|
||||||
banset.append(str(id))
|
|
||||||
except Exception as exc:
|
|
||||||
irc.reply("Failed to set duration time on ban %s (%s)" % (id, exc))
|
|
||||||
|
|
||||||
if banset:
|
|
||||||
irc.reply("Ban set for auto removal: %s" % ', '.join(banset))
|
|
||||||
|
|
||||||
duration = wrap(duration, ['something', 'text'])
|
|
||||||
|
|
||||||
def baninfo(self, irc, msg, args, id):
|
|
||||||
"""[<id>]
|
|
||||||
|
|
||||||
Show ban information. If <id> is not given shows the ids of bans set to
|
|
||||||
expire.
|
|
||||||
"""
|
|
||||||
|
|
||||||
if id is None:
|
|
||||||
count = len(self.managedBans)
|
count = len(self.managedBans)
|
||||||
L = [ str(item.ban.id) for item in self.managedBans ]
|
L = [ str(item.ban.id) for item in self.managedBans ]
|
||||||
irc.reply("%s bans set to expire: %s" % (count, ', '.join(L)))
|
irc.reply("%s bans set to expire: %s" % (count, ', '.join(L)))
|
||||||
return
|
return
|
||||||
|
|
||||||
L = self.db_run("SELECT mask, channel, removal FROM bans WHERE id = %s",
|
if duration is not None:
|
||||||
id, expect_result=True)
|
|
||||||
if not L:
|
|
||||||
irc.reply("I don't know any ban with that id.")
|
|
||||||
return
|
|
||||||
|
|
||||||
mask, channel, removal = L[0]
|
|
||||||
type = guessBanType(mask)
|
|
||||||
if type == 'quiet':
|
|
||||||
mask = mask[1:]
|
|
||||||
for br in self.managedBans:
|
|
||||||
if br.ban.id == id:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
br = None
|
|
||||||
|
|
||||||
expires = None
|
|
||||||
if br:
|
|
||||||
expires = (br.ban.when + br.expires) - nowSeconds()
|
|
||||||
try:
|
try:
|
||||||
expires = "expires in %s" % timeElapsed(expires)
|
duration = readTimeDelta(duration)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
expires = "expires soon"
|
irc.error("bad time format.")
|
||||||
else:
|
return
|
||||||
if type in ('quiet', 'ban'):
|
|
||||||
if not removal:
|
banset = []
|
||||||
expires = "never expires"
|
for id in splitID(ids):
|
||||||
|
if duration is not None:
|
||||||
|
# set ban duration
|
||||||
|
try:
|
||||||
|
self._setBanDuration(id, duration)
|
||||||
|
banset.append(str(id))
|
||||||
|
except Exception as exc:
|
||||||
|
irc.reply("Failed to set duration time on ban %s (%s)" \
|
||||||
|
% (id, exc))
|
||||||
|
else:
|
||||||
|
# get ban information
|
||||||
|
try:
|
||||||
|
mask, channel, removal = self._getBan(id)
|
||||||
|
except ValueError:
|
||||||
|
irc.reply("I don't know any ban with id %s." % id)
|
||||||
|
continue
|
||||||
|
|
||||||
|
type = guessBanType(mask)
|
||||||
|
if type == 'quiet':
|
||||||
|
mask = mask[1:]
|
||||||
|
for br in self.managedBans:
|
||||||
|
if br.ban.id == id:
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
expires = "not active"
|
br = None
|
||||||
|
|
||||||
if expires:
|
expires = None
|
||||||
irc.reply("[%s] %s - %s - %s - %s" % (id, type, mask, channel, expires))
|
if br:
|
||||||
else:
|
expires = (br.ban.when + br.expires) - nowSeconds()
|
||||||
irc.reply("[%s] %s - %s - %s" % (id, type, mask, channel))
|
try:
|
||||||
|
expires = "expires in %s" % timeElapsed(expires)
|
||||||
|
except ValueError:
|
||||||
|
expires = "expires soon"
|
||||||
|
else:
|
||||||
|
if type in ('quiet', 'ban'):
|
||||||
|
if not removal:
|
||||||
|
expires = "never expires"
|
||||||
|
else:
|
||||||
|
expires = "not active"
|
||||||
|
|
||||||
|
if expires:
|
||||||
|
irc.reply("[%s] %s - %s - %s - %s" % (id, type, mask, channel, expires))
|
||||||
|
else:
|
||||||
|
irc.reply("[%s] %s - %s - %s" % (id, type, mask, channel))
|
||||||
|
|
||||||
baninfo = wrap(baninfo, [optional('id')])
|
# reply with the bans ids that were correctly set.
|
||||||
|
if banset:
|
||||||
|
irc.reply("Ban set for auto removal: %s" % ', '.join(banset))
|
||||||
|
|
||||||
|
duration = wrap(duration, [optional('something'), optional('text')])
|
||||||
|
|
||||||
def banlink(self, irc, msg, args, id, highlight):
|
def banlink(self, irc, msg, args, id, highlight):
|
||||||
"""<id> [<highlight>]
|
"""<id> [<highlight>]
|
||||||
|
|
|
@ -146,7 +146,7 @@ class BantrackerTestCase(ChannelPluginTestCase):
|
||||||
self.feedBan('asd!*@*')
|
self.feedBan('asd!*@*')
|
||||||
self.assertResponse('comment 1 this is a test, 1 week 10', 'Ban set for auto removal: 1')
|
self.assertResponse('comment 1 this is a test, 1 week 10', 'Ban set for auto removal: 1')
|
||||||
self.assertRegexp('comment 1', 'test: this is a test, 1 week 10$')
|
self.assertRegexp('comment 1', 'test: this is a test, 1 week 10$')
|
||||||
self.assertRegexp('baninfo 1', 'expires in 1 week$')
|
self.assertRegexp('duration 1', 'expires in 1 week$')
|
||||||
|
|
||||||
def testCommentRequest(self):
|
def testCommentRequest(self):
|
||||||
pluginConf.request.setValue(True)
|
pluginConf.request.setValue(True)
|
||||||
|
@ -500,22 +500,22 @@ class BantrackerTestCase(ChannelPluginTestCase):
|
||||||
def testBaninfo(self):
|
def testBaninfo(self):
|
||||||
cb = self.getCallback()
|
cb = self.getCallback()
|
||||||
self.feedBan('asd!*@*')
|
self.feedBan('asd!*@*')
|
||||||
self.assertResponse('baninfo 1', '[1] ban - asd!*@* - #test - never expires')
|
self.assertResponse('duration 1', '[1] ban - asd!*@* - #test - never expires')
|
||||||
self.assertNotError('duration 1 10')
|
self.assertNotError('duration 1 10')
|
||||||
self.assertResponse('baninfo 1', '[1] ban - asd!*@* - #test - expires soon')
|
self.assertResponse('duration 1', '[1] ban - asd!*@* - #test - expires soon')
|
||||||
self.assertNotError('duration 1 34502')
|
self.assertNotError('duration 1 34502')
|
||||||
self.assertResponse('baninfo 1', '[1] ban - asd!*@* - #test - expires in 9 hours and 35 minutes')
|
self.assertResponse('duration 1', '[1] ban - asd!*@* - #test - expires in 9 hours and 35 minutes')
|
||||||
self.irc.feedMsg(ircmsgs.unban(self.channel, 'asd!*@*',
|
self.irc.feedMsg(ircmsgs.unban(self.channel, 'asd!*@*',
|
||||||
'op!user@host.net'))
|
'op!user@host.net'))
|
||||||
self.assertResponse('baninfo 1', '[1] ban - asd!*@* - #test - not active')
|
self.assertResponse('duration 1', '[1] ban - asd!*@* - #test - not active')
|
||||||
|
|
||||||
def testBaninfoGeneral(self):
|
def testBaninfoGeneral(self):
|
||||||
cb = self.getCallback()
|
cb = self.getCallback()
|
||||||
self.feedBan('asd!*@*')
|
self.feedBan('asd!*@*')
|
||||||
self.feedBan('qwe!*@*')
|
self.feedBan('qwe!*@*')
|
||||||
self.assertNotError('duration 1 1d')
|
self.assertNotError('duration 1 1d')
|
||||||
self.assertResponse('baninfo', "1 bans set to expire: 1")
|
self.assertResponse('duration', "1 bans set to expire: 1")
|
||||||
self.assertNotError('duration 2 1d')
|
self.assertNotError('duration 2 1d')
|
||||||
self.assertResponse('baninfo', "2 bans set to expire: 1, 2")
|
self.assertResponse('duration', "2 bans set to expire: 1, 2")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue