Changed Alias.freeze to Alias.lock.

This commit is contained in:
Jeremy Fincher 2003-11-25 10:19:40 +00:00
parent 6d3cb48c51
commit 2c779bd543
5 changed files with 29 additions and 25 deletions

View File

@ -1,3 +1,7 @@
* Fixed bug in RSS.configure; no aliases could be added.
* Changed Alias.freeze to Alias.lock.
* Fixed sorting in Status' uptime database.
* Updated the Gameknot tests for expired games.

View File

@ -160,23 +160,23 @@ class Alias(callbacks.Privmsg):
def __init__(self):
callbacks.Privmsg.__init__(self)
filename = os.path.join(conf.dataDir, 'Aliases.db')
# Schema: {name: [alias, frozen]}
# Schema: {name: [alias, locked]}
self.aliases = structures.PersistentDictionary(filename)
def __call__(self, irc, msg):
# Adding the aliases requires an Irc. So the first time we get called
# with an Irc, we add our aliases and then delete ourselves :)
for (name, (alias, frozen)) in self.aliases.iteritems():
self.addAlias(irc, name, alias, frozen)
for (name, (alias, locked)) in self.aliases.iteritems():
self.addAlias(irc, name, alias, locked)
del self.__class__.__call__
def die(self):
self.aliases.close()
def freeze(self, irc, msg, args):
def lock(self, irc, msg, args):
"""<alias>
'Freezes' an alias so that no one else can change it.
Locks an alias so that no one else can change it.
"""
name = privmsgs.getArgs(args)
name = callbacks.canonicalName(name)
@ -185,12 +185,12 @@ class Alias(callbacks.Privmsg):
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, 'There is no such alias.')
freeze = privmsgs.checkCapability(freeze, 'admin')
lock = privmsgs.checkCapability(lock, 'admin')
def unfreeze(self, irc, msg, args):
def unlock(self, irc, msg, args):
"""<alias>
'Unfreezes' an alias so that people can define new aliases over it.
Unlocks an alias so that people can define new aliases over it.
"""
name = privmsgs.getArgs(args)
name = callbacks.canonicalName(name)
@ -199,10 +199,10 @@ class Alias(callbacks.Privmsg):
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, 'There is no such alias.')
unfreeze = privmsgs.checkCapability(unfreeze, 'admin')
unlock = privmsgs.checkCapability(unlock, 'admin')
_invalidCharsRe = re.compile(r'[\[\]\s]')
def addAlias(self, irc, name, alias, freeze=False):
def addAlias(self, irc, name, alias, lock=False):
if self._invalidCharsRe.search(name):
raise AliasError, 'Names cannot contain spaces or square brackets.'
if conf.enablePipeSyntax and '|' in name:
@ -217,24 +217,24 @@ class Alias(callbacks.Privmsg):
s = 'A command with the name %r already exists.' % name
raise AliasError, s
if name in self.aliases:
(currentAlias, frozen) = self.aliases[name]
if frozen and currentAlias != alias:
raise AliasError, 'Alias %r is frozen.' % name
(currentAlias, locked) = self.aliases[name]
if locked and currentAlias != alias:
raise AliasError, 'Alias %r is locked.' % name
try:
f = makeNewAlias(name, alias)
except RecursiveAlias:
raise AliasError, 'You can\'t define a recursive alias.'
setattr(self.__class__, name, f)
self.aliases[name] = [alias, freeze]
self.aliases[name] = [alias, lock]
def removeAlias(self, name, evenIfFrozen=False):
def removeAlias(self, name, evenIfLocked=False):
name = callbacks.canonicalName(name)
if hasattr(self, name) and self.isCommand(name):
if evenIfFrozen or not self.aliases[name][1]:
if evenIfLocked or not self.aliases[name][1]:
delattr(self.__class__, name)
del self.aliases[name]
else:
raise AliasError, 'That alias is frozen.'
raise AliasError, 'That alias is locked.'
else:
raise AliasError, 'There is no such alias.'
@ -259,7 +259,7 @@ class Alias(callbacks.Privmsg):
def remove(self, irc, msg, args):
"""<name>
Removes the given alias, if unfrozen.
Removes the given alias, if unlocked.
"""
name = privmsgs.getArgs(args)
try:

View File

@ -106,7 +106,7 @@ class Lookup(callbacks.Privmsg):
db.commit()
cb = irc.getCallback('Alias')
if cb is not None:
cb.removeAlias(name, evenIfFrozen=True)
cb.removeAlias(name, evenIfLocked=True)
irc.reply(msg, conf.replySuccess)
except sqlite.DatabaseError:
irc.error(msg, 'No such lookup exists.')
@ -128,7 +128,7 @@ class Lookup(callbacks.Privmsg):
cb = irc.getCallback('Alias')
if cb is not None:
try:
cb.addAlias(irc, name, 'lookup %s @1' % name, freeze=True)
cb.addAlias(irc, name, 'lookup %s @1' % name, lock=True)
except sys.modules[cb.__module__].AliasError, e:
pass
irc.reply(msg, conf.replySuccess)
@ -158,7 +158,7 @@ class Lookup(callbacks.Privmsg):
cb = irc.getCallback('Alias')
if cb is not None:
try:
cb.addAlias(irc, name, 'lookup %s @1' % name, freeze=True)
cb.addAlias(irc, name, 'lookup %s @1' % name, lock=True)
except sys.modules[cb.__module__].AliasError, e:
irc.error(msg, str(e))
return

View File

@ -64,8 +64,8 @@ def configure(onStart, afterConnect, advanced):
prompt = 'Would you like to add another RSS feed?'
name = something('What\'s the name of the website?')
url = something('What\'s the URL of the RSS feed?')
onStart.append('alias %s "rss %s"' % (name, url))
onStart.append('freeze %s' % name)
onStart.append('alias add %s "rss %s"' % (name, url))
onStart.append('alias lock %s' % name)
class RSS(callbacks.Privmsg):
threaded = True

View File

@ -122,10 +122,10 @@ class AliasTestCase(ChannelPluginTestCase, PluginDocumentation):
def testAddRemoveAlias(self):
cb = self.irc.getCallback('Alias')
cb.addAlias(self.irc, 'foobar', 'echo sbbone', freeze=True)
cb.addAlias(self.irc, 'foobar', 'echo sbbone', lock=True)
self.assertResponse('foobar', 'sbbone')
self.assertRaises(Alias.AliasError, cb.removeAlias, 'foobar')
cb.removeAlias('foobar', evenIfFrozen=True)
cb.removeAlias('foobar', evenIfLocked=True)
self.failIf('foobar' in cb.aliases)
self.assertNoResponse('foobar', 2)