Admin refactored ignore/unignore/ignores to ignore add/remove/list, and changed tests accordingly.

This commit is contained in:
Ali Afshar 2005-03-25 14:03:44 +00:00
parent 890d92df0e
commit 4e7a00d504
2 changed files with 46 additions and 44 deletions

View File

@ -291,44 +291,46 @@ class Admin(callbacks.Plugin):
irc.error(s) irc.error(s)
remove = wrap(remove, ['otherUser','lowered']) remove = wrap(remove, ['otherUser','lowered'])
def ignore(self, irc, msg, args, hostmask, expires): class ignore(callbacks.Commands):
"""<hostmask|nick> [<expires>]
Ignores <hostmask> or, if a nick is given, ignores whatever hostmask def add(self, irc, msg, args, hostmask, expires):
that nick is currently using. <expires> is a "seconds from now" value """<hostmask|nick> [<expires>]
that determines when the ignore will expire; if, for instance, you wish
for the ignore to expire in an hour, you could give an <expires> of
3600. If no <expires> is given, the ignore will never automatically
expire.
"""
ircdb.ignores.add(hostmask, expires)
irc.replySuccess()
ignore = wrap(ignore, ['hostmask', additional('expiry', 0)])
def unignore(self, irc, msg, args, hostmask): Ignores <hostmask> or, if a nick is given, ignores whatever hostmask
"""<hostmask|nick> that nick is currently using. <expires> is a "seconds from now" value
that determines when the ignore will expire; if, for instance, you wish
Ignores <hostmask> or, if a nick is given, ignores whatever hostmask for the ignore to expire in an hour, you could give an <expires> of
that nick is currently using. 3600. If no <expires> is given, the ignore will never automatically
""" expire.
try: """
ircdb.ignores.remove(hostmask) ircdb.ignores.add(hostmask, expires)
irc.replySuccess() irc.replySuccess()
except KeyError: add = wrap(add, ['hostmask', additional('expiry', 0)])
irc.error('%s wasn\'t in the ignores database.' % hostmask)
unignore = wrap(unignore, ['hostmask'])
def ignores(self, irc, msg, args): def remove(self, irc, msg, args, hostmask):
"""takes no arguments """<hostmask|nick>
Returns the hostmasks currently being globally ignored. Ignores <hostmask> or, if a nick is given, ignores whatever hostmask
""" that nick is currently using.
# XXX Add the expirations. """
if ircdb.ignores.hostmasks: try:
irc.reply(format('%L', (map(repr,ircdb.ignores.hostmasks)))) ircdb.ignores.remove(hostmask)
else: irc.replySuccess()
irc.reply('I\'m not currently globally ignoring anyone.') except KeyError:
ignores = wrap(ignores) irc.error('%s wasn\'t in the ignores database.' % hostmask)
remove = wrap(remove, ['hostmask'])
def list(self, irc, msg, args):
"""takes no arguments
Returns the hostmasks currently being globally ignored.
"""
# XXX Add the expirations.
if ircdb.ignores.hostmasks:
irc.reply(format('%L', (map(repr,ircdb.ignores.hostmasks))))
else:
irc.reply('I\'m not currently globally ignoring anyone.')
list = wrap(list)
Class = Admin Class = Admin

View File

@ -48,18 +48,18 @@ class AdminTestCase(PluginTestCase):
getAfterJoinMessages() getAfterJoinMessages()
self.assertRegexp('channels', '#bar, #Baz, and #foo') self.assertRegexp('channels', '#bar, #Baz, and #foo')
def testIgnoreUnignore(self): def testIgnoreAddRemove(self):
self.assertNotError('admin ignore foo!bar@baz') self.assertNotError('admin ignore add foo!bar@baz')
self.assertError('admin ignore alsdkfjlasd') self.assertError('admin ignore add alsdkfjlasd')
self.assertNotError('admin unignore foo!bar@baz') self.assertNotError('admin ignore remove foo!bar@baz')
self.assertError('admin unignore foo!bar@baz') self.assertError('admin ignore remove foo!bar@baz')
def testIgnores(self): def testIgnoreList(self):
self.assertNotError('admin ignores') self.assertNotError('admin ignore list')
self.assertNotError('admin ignore foo!bar@baz') self.assertNotError('admin ignore add foo!bar@baz')
self.assertNotError('admin ignores') self.assertNotError('admin ignore list')
self.assertNotError('admin ignore foo!bar@baz') self.assertNotError('admin ignore add foo!bar@baz')
self.assertNotError('admin ignores') self.assertRegexp('admin ignore list', 'foo')
def testCapabilityAdd(self): def testCapabilityAdd(self):
self.assertError('capability add foo bar') self.assertError('capability add foo bar')