diff --git a/Bantracker/plugin.py b/Bantracker/plugin.py index 8edad95..cd43c4c 100644 --- a/Bantracker/plugin.py +++ b/Bantracker/plugin.py @@ -534,9 +534,9 @@ class Bantracker(callbacks.Plugin): # add our scheduled events for check bans for reviews or removal schedule.addPeriodicEvent(lambda: self.reviewBans(irc), 60*60, - name=self.name() + '_review') + 'Bantracker_review') schedule.addPeriodicEvent(lambda: self.autoRemoveBans(irc), 600, - name=self.name() + '_autoremove') + 'Bantracker_autoremove') def get_nicks(self, irc): self.hosts.clear() @@ -896,6 +896,19 @@ class Bantracker(callbacks.Plugin): def getOp(self, irc, channel): msg = ircmsgs.privmsg('Chanserv', "op %s %s" % (channel, irc.nick)) irc.queueMsg(msg) + schedule.addEvent(lambda: self._getOpFail(irc, channel), 60, + 'Bantracker_getop_%s' % channel) + + def _getOpFail(self, irc, channel): + for c in self.registryValue('autoremove.notify.channels', channel): + notice = ircmsgs.notice(c, "Failed to get op in %s" % channel) + irc.queueMsg(notice) + + def _getOpOK(self, channel): + try: + schedule.removeEvent('Bantracker_getop_%s' % channel) + except KeyError: + pass def removeBans(self, irc, channel, modes, deop=False): # send unban messages, with 4 modes max each. @@ -1096,6 +1109,7 @@ class Bantracker(callbacks.Plugin): if ircutils.nickEqual(irc.nick, param[1]): opped = self.opped[channel] = mode[0] == '+' if opped == True: + self._getOpOK(channel) # check if we have bans to remove if channel in self.pendingBanremoval: modes = self.pendingBanremoval.pop(channel) diff --git a/Bantracker/test.py b/Bantracker/test.py index 6322f00..6799e6e 100644 --- a/Bantracker/test.py +++ b/Bantracker/test.py @@ -507,7 +507,7 @@ class BantrackerTestCase(ChannelPluginTestCase): cb = self.getCallback() self.feedBan('asd!*@*') self.assertNotError('duration 1 300') - pluginConf.autoremove.notify.channels().append('#test') + pluginConf.autoremove.notify.channels.set('#test') try: cb.autoRemoveBans(self.irc) msg = self.irc.takeMsg() @@ -518,7 +518,7 @@ class BantrackerTestCase(ChannelPluginTestCase): cb.autoRemoveBans(self.irc) self.assertFalse(self.irc.takeMsg()) finally: - del pluginConf.autoremove.notify.channels()[:] + pluginConf.autoremove.notify.channels.set('') def testAutoremoveStore(self): self.feedBan('asd!*@*') @@ -579,7 +579,7 @@ class BantrackerTestCase(ChannelPluginTestCase): def testOpDuration(self): cb = self.getCallback() self.feedBan('asd!*@*') - self.assertResponse('duration 1 1', "1 will be removed soon.") + self.assertNotError('duration 1 1') print 'waiting 2 secs ...' time.sleep(2) cb.autoRemoveBans(self.irc) @@ -589,5 +589,27 @@ class BantrackerTestCase(ChannelPluginTestCase): msg = self.irc.takeMsg() # unban msg self.assertEqual(str(msg).strip(), "MODE #test -bo asd!*@* :test") + def testOpFail(self): + import supybot.drivers as drivers + import supybot.schedule as schedule + + pluginConf.autoremove.notify.channels.set('#test') + try: + cb = self.getCallback() + self.feedBan('asd!*@*') + self.assertNotError('duration 1 1') + print 'waiting 4 secs ...' + time.sleep(2) + cb.autoRemoveBans(self.irc) + msg = self.irc.takeMsg() # op msg + self.assertEqual(str(msg).strip(), "PRIVMSG Chanserv :op #test test") + schedule.rescheduleEvent('Bantracker_getop_#test', 1) + time.sleep(2) + drivers.run() + msg = self.irc.takeMsg() # fail msg + self.assertEqual(str(msg).strip(), + "NOTICE #test :Failed to get op in #test") + finally: + pluginConf.autoremove.notify.channels.set('')