diff --git a/src/Admin.py b/src/Admin.py index 15ff2b879..a119c1840 100755 --- a/src/Admin.py +++ b/src/Admin.py @@ -44,7 +44,9 @@ import textwrap import conf import ircdb +import utils import ircmsgs +import ircutils import privmsgs import callbacks @@ -179,6 +181,57 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg): s = 'You can\'t remove capabilities you don\'t have.' irc.error(msg, s) + def ignore(self, irc, msg, args): + """ + + Ignores or, if a nick is given, ignores whatever hostmask + that nick is currently using. + """ + arg = privmsgs.getArgs(args) + if ircutils.isUserHostmask(arg): + hostmask = arg + else: + try: + hostmask = irc.state.nickToHostmask(arg) + except KeyError: + irc.error(msg, 'I can\'t find a hostmask for %s' % arg) + return + conf.ignores.append(hostmask) + irc.reply(msg, conf.replySuccess) + + def unignore(self, irc, msg, args): + """ + + Ignores or, if a nick is given, ignores whatever hostmask + that nick is currently using. + """ + arg = privmsgs.getArgs(args) + if ircutils.isUserHostmask(arg): + hostmask = arg + else: + try: + hostmask = irc.state.nickToHostmask(arg) + except KeyError: + irc.error(msg, 'I can\'t find a hostmask for %s' % arg) + return + try: + conf.ignores.remove(hostmask) + while hostmask in conf.ignores: + conf.ignores.remove(hostmask) + irc.reply(msg, conf.replySuccess) + except ValueError: + irc.error(msg, '%s wasn\'t in conf.ignores.' % hostmask) + + def ignores(self, irc, msg, args): + """takes no arguments + + Returns the hostmasks currently being globally ignored. + """ + if conf.ignores: + irc.reply(msg, utils.commaAndify(map(repr, conf.ignores))) + else: + irc.reply(msg, 'I\'m not currently globally ignoring anyone.') + def setprefixchar(self, irc, msg, args): """ diff --git a/test/test_Admin.py b/test/test_Admin.py index 93ec9cf0e..c819c5580 100644 --- a/test/test_Admin.py +++ b/test/test_Admin.py @@ -31,8 +31,29 @@ from test import * +import conf + class AdminTestCase(PluginTestCase, PluginDocumentation): - plugins = ('Admin', 'Misc') + plugins = ('Admin',) + def testIgnoreUnignore(self): + try: + self.assertNotError('admin ignore foo!bar@baz') + self.assertError('admin ignore alsdkfjlasd') + self.assertNotError('admin unignore foo!bar@baz') + self.assertError('admin unignore foo!bar@baz') + finally: + conf.ignores = [] + + def testIgnores(self): + try: + self.assertNotError('admin ignores') + self.assertNotError('admin ignore foo!bar@baz') + self.assertNotError('admin ignores') + self.assertNotError('admin ignore foo!bar@baz') + self.assertNotError('admin ignores') + finally: + conf.ignores = [] + def testSetprefixchar(self): self.assertNotError('setprefixchar $') self.assertResponse('getprefixchar', "'$'")