refactor bot replies.
This commit is contained in:
@ -1533,8 +1533,8 @@ class Bantracker(callbacks.Plugin):
|
||||
def comment(self, irc, msg, args, ids, kickmsg):
|
||||
"""<id>[,<id> ...] [<comment>][, <duration>]
|
||||
|
||||
Reads or adds the <comment> for the ban with <id>,
|
||||
use @bansearch to find the id of a ban
|
||||
Reads or adds the <comment> for the ban with <id>, use @bansearch to
|
||||
find the id of a ban. Using <duration> will set the duration of the ban.
|
||||
"""
|
||||
|
||||
def addComment(id, nick, msg):
|
||||
@ -1555,7 +1555,7 @@ class Bantracker(callbacks.Plugin):
|
||||
|
||||
for id in splitID(ids):
|
||||
try:
|
||||
mask, channel, removal = self._getBan(id)
|
||||
self._getBan(id)
|
||||
except ValueError:
|
||||
irc.reply("I don't know any ban with id %s." % id)
|
||||
continue
|
||||
@ -1564,15 +1564,11 @@ class Bantracker(callbacks.Plugin):
|
||||
addComment(id, nick, kickmsg)
|
||||
if duration is not None:
|
||||
# set duration time
|
||||
type = guessBanType(mask)
|
||||
if type not in ('ban', 'quiet'):
|
||||
continue
|
||||
|
||||
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))
|
||||
irc.reply("Failed to set duration time on %s (%s)" % (id, exc))
|
||||
else:
|
||||
data = readComment(id)
|
||||
if data:
|
||||
@ -1582,25 +1578,30 @@ class Bantracker(callbacks.Plugin):
|
||||
else:
|
||||
irc.reply("No comments recorded for ban %s" % id)
|
||||
|
||||
# success reply. If duration time used, say which ones.
|
||||
# success reply. If duration time used, say which ones were set.
|
||||
if kickmsg:
|
||||
if banset:
|
||||
irc.replySuccess("%s set to expire." % ', '.join(banset))
|
||||
try:
|
||||
time = 'after ' + timeElapsed(duration)
|
||||
except ValueError:
|
||||
time = 'soon'
|
||||
irc.reply("Comment added. %s will be removed %s." \
|
||||
% (utils.str.format('%L', banset), time))
|
||||
else:
|
||||
irc.replySuccess()
|
||||
# only a comment
|
||||
irc.reply("Comment added.")
|
||||
|
||||
comment = wrap(comment, ['something', optional('text')])
|
||||
|
||||
def duration(self, irc, msg, args, ids, duration):
|
||||
"""[<id>[,<id> ...]] [<duration>]
|
||||
|
||||
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.
|
||||
Sets the duration of a ban. If <duration> isn't given show when a ban expires. f no <id> is given shows the ids of bans set to expire.
|
||||
"""
|
||||
if ids is None:
|
||||
count = len(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, utils.str.format('%L', L)))
|
||||
return
|
||||
|
||||
if duration is not None:
|
||||
@ -1640,10 +1641,13 @@ class Bantracker(callbacks.Plugin):
|
||||
expires = None
|
||||
if br:
|
||||
expires = (br.ban.when + br.expires) - nowSeconds()
|
||||
try:
|
||||
expires = "expires in %s" % timeElapsed(expires)
|
||||
except ValueError:
|
||||
expires = "expires soon"
|
||||
if expires > 0:
|
||||
try:
|
||||
expires = "expires in %s" % timeElapsed(expires)
|
||||
except ValueError:
|
||||
expires = "expires soon"
|
||||
else:
|
||||
expires = "expired and will be removed soon"
|
||||
else:
|
||||
if type in ('quiet', 'ban'):
|
||||
if not removal:
|
||||
@ -1658,7 +1662,11 @@ class Bantracker(callbacks.Plugin):
|
||||
|
||||
# reply with the bans ids that were correctly set.
|
||||
if banset:
|
||||
irc.reply("%s set to expire." % ', '.join(banset))
|
||||
try:
|
||||
time = 'after ' + timeElapsed(duration)
|
||||
except ValueError:
|
||||
time = 'soon'
|
||||
irc.reply("%s will be removed %s." % (utils.str.format('%L', banset), time))
|
||||
|
||||
duration = wrap(duration, [optional('something'), optional('text')])
|
||||
|
||||
|
@ -129,31 +129,34 @@ class BantrackerTestCase(ChannelPluginTestCase):
|
||||
self.feedBan('asd!*@*')
|
||||
self.assertResponse('comment 1', 'No comments recorded for ban 1')
|
||||
self.assertResponse('comment 1 this is a test',
|
||||
'The operation succeeded.')
|
||||
'Comment added.')
|
||||
self.assertRegexp('comment 1', 'test: this is a test$')
|
||||
self.assertResponse('comment 1 this is a test, another test',
|
||||
'The operation succeeded.')
|
||||
'Comment added.')
|
||||
self.feedBan('nick', mode='k')
|
||||
self.assertResponse('comment 2 this is a kick, 2week',
|
||||
'The operation succeeded.')
|
||||
"Failed to set duration time on 2 (not a ban or quiet)")
|
||||
msg = self.irc.takeMsg()
|
||||
self.assertEqual(msg.args[1], 'test: Comment added.')
|
||||
self.assertResponse('comment 1 not a valid, duration 2',
|
||||
'The operation succeeded.')
|
||||
'Comment added.')
|
||||
|
||||
def testMultiComment(self):
|
||||
self.feedBan('asd!*@*')
|
||||
self.feedBan('qwe!*@*')
|
||||
self.assertResponse('comment 1,2,3 this is a test',
|
||||
self.assertResponse('comment 1,2,3 this is a test, 2 days',
|
||||
"I don't know any ban with id 3.")
|
||||
msg = self.irc.takeMsg()
|
||||
self.assertEqual(msg.args[1], "test: The operation succeeded.")
|
||||
self.assertRegexp('comment 1,2', 'test: this is a test$')
|
||||
self.assertEqual(msg.args[1],
|
||||
"test: Comment added. 1 and 2 will be removed after 2 days.")
|
||||
self.assertRegexp('comment 1,2', 'test: this is a test, 2 days$')
|
||||
msg = self.irc.takeMsg()
|
||||
self.assertTrue(msg.args[1].endswith("test: this is a test"))
|
||||
self.assertTrue(msg.args[1].endswith("test: this is a test, 2 days"))
|
||||
|
||||
def testCommentDuration(self):
|
||||
self.feedBan('asd!*@*')
|
||||
self.assertResponse('comment 1 this is a test, 1 week 10',
|
||||
'The operation succeeded. 1 set to expire.')
|
||||
'Comment added. 1 will be removed after 1 week.')
|
||||
self.assertRegexp('comment 1', 'test: this is a test, 1 week 10$')
|
||||
self.assertRegexp('duration 1', 'expires in 1 week$')
|
||||
|
||||
@ -385,7 +388,7 @@ class BantrackerTestCase(ChannelPluginTestCase):
|
||||
self.feedBan('asd!*@*')
|
||||
cb.autoRemoveBans(self.irc)
|
||||
self.assertFalse(cb.managedBans)
|
||||
self.assertNotError('duration 1 1')
|
||||
self.assertResponse('duration 1 1', "1 will be removed soon.")
|
||||
self.assertTrue(cb.managedBans) # ban in list
|
||||
print 'waiting 2 secs ...'
|
||||
time.sleep(2)
|
||||
@ -414,10 +417,11 @@ class BantrackerTestCase(ChannelPluginTestCase):
|
||||
|
||||
def testDurationMultiSet(self):
|
||||
self.feedBan('asd!*@*')
|
||||
self.assertResponse('duration 1,2 10',
|
||||
self.assertResponse('duration 1,2 10d',
|
||||
"Failed to set duration time on 2 (unknow id)")
|
||||
msg = self.irc.takeMsg()
|
||||
self.assertEqual(msg.args[1], "test: 1 set to expire.")
|
||||
self.assertEqual(msg.args[1],
|
||||
"test: 1 will be removed after 1 week and 3 days.")
|
||||
|
||||
|
||||
def testDurationQuiet(self):
|
||||
@ -435,7 +439,7 @@ class BantrackerTestCase(ChannelPluginTestCase):
|
||||
self.assertResponse('duration 1 0',
|
||||
"Failed to set duration time on 1 (not a ban or quiet)")
|
||||
self.feedBan('$a:nick')
|
||||
self.assertResponse('duration 2 0', '2 set to expire.')
|
||||
self.assertResponse('duration 2 0', '2 will be removed soon.')
|
||||
|
||||
def testDurationBadId(self):
|
||||
self.assertResponse('duration 1 0',
|
||||
@ -530,6 +534,6 @@ class BantrackerTestCase(ChannelPluginTestCase):
|
||||
self.assertNotError('duration 1 1d')
|
||||
self.assertResponse('duration', "1 bans set to expire: 1")
|
||||
self.assertNotError('duration 2 1d')
|
||||
self.assertResponse('duration', "2 bans set to expire: 1, 2")
|
||||
self.assertResponse('duration', "2 bans set to expire: 1 and 2")
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user