mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-12 05:02:32 +01:00
Changed Alias.freeze to Alias.lock.
This commit is contained in:
parent
6d3cb48c51
commit
2c779bd543
@ -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.
|
* Fixed sorting in Status' uptime database.
|
||||||
|
|
||||||
* Updated the Gameknot tests for expired games.
|
* Updated the Gameknot tests for expired games.
|
||||||
|
@ -160,23 +160,23 @@ class Alias(callbacks.Privmsg):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
filename = os.path.join(conf.dataDir, 'Aliases.db')
|
filename = os.path.join(conf.dataDir, 'Aliases.db')
|
||||||
# Schema: {name: [alias, frozen]}
|
# Schema: {name: [alias, locked]}
|
||||||
self.aliases = structures.PersistentDictionary(filename)
|
self.aliases = structures.PersistentDictionary(filename)
|
||||||
|
|
||||||
def __call__(self, irc, msg):
|
def __call__(self, irc, msg):
|
||||||
# Adding the aliases requires an Irc. So the first time we get called
|
# Adding the aliases requires an Irc. So the first time we get called
|
||||||
# with an Irc, we add our aliases and then delete ourselves :)
|
# with an Irc, we add our aliases and then delete ourselves :)
|
||||||
for (name, (alias, frozen)) in self.aliases.iteritems():
|
for (name, (alias, locked)) in self.aliases.iteritems():
|
||||||
self.addAlias(irc, name, alias, frozen)
|
self.addAlias(irc, name, alias, locked)
|
||||||
del self.__class__.__call__
|
del self.__class__.__call__
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
self.aliases.close()
|
self.aliases.close()
|
||||||
|
|
||||||
def freeze(self, irc, msg, args):
|
def lock(self, irc, msg, args):
|
||||||
"""<alias>
|
"""<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 = privmsgs.getArgs(args)
|
||||||
name = callbacks.canonicalName(name)
|
name = callbacks.canonicalName(name)
|
||||||
@ -185,12 +185,12 @@ class Alias(callbacks.Privmsg):
|
|||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
else:
|
else:
|
||||||
irc.error(msg, 'There is no such alias.')
|
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>
|
"""<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 = privmsgs.getArgs(args)
|
||||||
name = callbacks.canonicalName(name)
|
name = callbacks.canonicalName(name)
|
||||||
@ -199,10 +199,10 @@ class Alias(callbacks.Privmsg):
|
|||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
else:
|
else:
|
||||||
irc.error(msg, 'There is no such alias.')
|
irc.error(msg, 'There is no such alias.')
|
||||||
unfreeze = privmsgs.checkCapability(unfreeze, 'admin')
|
unlock = privmsgs.checkCapability(unlock, 'admin')
|
||||||
|
|
||||||
_invalidCharsRe = re.compile(r'[\[\]\s]')
|
_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):
|
if self._invalidCharsRe.search(name):
|
||||||
raise AliasError, 'Names cannot contain spaces or square brackets.'
|
raise AliasError, 'Names cannot contain spaces or square brackets.'
|
||||||
if conf.enablePipeSyntax and '|' in name:
|
if conf.enablePipeSyntax and '|' in name:
|
||||||
@ -217,24 +217,24 @@ class Alias(callbacks.Privmsg):
|
|||||||
s = 'A command with the name %r already exists.' % name
|
s = 'A command with the name %r already exists.' % name
|
||||||
raise AliasError, s
|
raise AliasError, s
|
||||||
if name in self.aliases:
|
if name in self.aliases:
|
||||||
(currentAlias, frozen) = self.aliases[name]
|
(currentAlias, locked) = self.aliases[name]
|
||||||
if frozen and currentAlias != alias:
|
if locked and currentAlias != alias:
|
||||||
raise AliasError, 'Alias %r is frozen.' % name
|
raise AliasError, 'Alias %r is locked.' % name
|
||||||
try:
|
try:
|
||||||
f = makeNewAlias(name, alias)
|
f = makeNewAlias(name, alias)
|
||||||
except RecursiveAlias:
|
except RecursiveAlias:
|
||||||
raise AliasError, 'You can\'t define a recursive alias.'
|
raise AliasError, 'You can\'t define a recursive alias.'
|
||||||
setattr(self.__class__, name, f)
|
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)
|
name = callbacks.canonicalName(name)
|
||||||
if hasattr(self, name) and self.isCommand(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)
|
delattr(self.__class__, name)
|
||||||
del self.aliases[name]
|
del self.aliases[name]
|
||||||
else:
|
else:
|
||||||
raise AliasError, 'That alias is frozen.'
|
raise AliasError, 'That alias is locked.'
|
||||||
else:
|
else:
|
||||||
raise AliasError, 'There is no such alias.'
|
raise AliasError, 'There is no such alias.'
|
||||||
|
|
||||||
@ -259,7 +259,7 @@ class Alias(callbacks.Privmsg):
|
|||||||
def remove(self, irc, msg, args):
|
def remove(self, irc, msg, args):
|
||||||
"""<name>
|
"""<name>
|
||||||
|
|
||||||
Removes the given alias, if unfrozen.
|
Removes the given alias, if unlocked.
|
||||||
"""
|
"""
|
||||||
name = privmsgs.getArgs(args)
|
name = privmsgs.getArgs(args)
|
||||||
try:
|
try:
|
||||||
|
@ -106,7 +106,7 @@ class Lookup(callbacks.Privmsg):
|
|||||||
db.commit()
|
db.commit()
|
||||||
cb = irc.getCallback('Alias')
|
cb = irc.getCallback('Alias')
|
||||||
if cb is not None:
|
if cb is not None:
|
||||||
cb.removeAlias(name, evenIfFrozen=True)
|
cb.removeAlias(name, evenIfLocked=True)
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
except sqlite.DatabaseError:
|
except sqlite.DatabaseError:
|
||||||
irc.error(msg, 'No such lookup exists.')
|
irc.error(msg, 'No such lookup exists.')
|
||||||
@ -128,7 +128,7 @@ class Lookup(callbacks.Privmsg):
|
|||||||
cb = irc.getCallback('Alias')
|
cb = irc.getCallback('Alias')
|
||||||
if cb is not None:
|
if cb is not None:
|
||||||
try:
|
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:
|
except sys.modules[cb.__module__].AliasError, e:
|
||||||
pass
|
pass
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
@ -158,7 +158,7 @@ class Lookup(callbacks.Privmsg):
|
|||||||
cb = irc.getCallback('Alias')
|
cb = irc.getCallback('Alias')
|
||||||
if cb is not None:
|
if cb is not None:
|
||||||
try:
|
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:
|
except sys.modules[cb.__module__].AliasError, e:
|
||||||
irc.error(msg, str(e))
|
irc.error(msg, str(e))
|
||||||
return
|
return
|
||||||
|
@ -64,8 +64,8 @@ def configure(onStart, afterConnect, advanced):
|
|||||||
prompt = 'Would you like to add another RSS feed?'
|
prompt = 'Would you like to add another RSS feed?'
|
||||||
name = something('What\'s the name of the website?')
|
name = something('What\'s the name of the website?')
|
||||||
url = something('What\'s the URL of the RSS feed?')
|
url = something('What\'s the URL of the RSS feed?')
|
||||||
onStart.append('alias %s "rss %s"' % (name, url))
|
onStart.append('alias add %s "rss %s"' % (name, url))
|
||||||
onStart.append('freeze %s' % name)
|
onStart.append('alias lock %s' % name)
|
||||||
|
|
||||||
class RSS(callbacks.Privmsg):
|
class RSS(callbacks.Privmsg):
|
||||||
threaded = True
|
threaded = True
|
||||||
|
@ -122,10 +122,10 @@ class AliasTestCase(ChannelPluginTestCase, PluginDocumentation):
|
|||||||
|
|
||||||
def testAddRemoveAlias(self):
|
def testAddRemoveAlias(self):
|
||||||
cb = self.irc.getCallback('Alias')
|
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.assertResponse('foobar', 'sbbone')
|
||||||
self.assertRaises(Alias.AliasError, cb.removeAlias, 'foobar')
|
self.assertRaises(Alias.AliasError, cb.removeAlias, 'foobar')
|
||||||
cb.removeAlias('foobar', evenIfFrozen=True)
|
cb.removeAlias('foobar', evenIfLocked=True)
|
||||||
self.failIf('foobar' in cb.aliases)
|
self.failIf('foobar' in cb.aliases)
|
||||||
self.assertNoResponse('foobar', 2)
|
self.assertNoResponse('foobar', 2)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user