mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-10-03 01:48:52 +02:00
Fix the bugs in #1032945, Observer.list exceptions and exceptions when adding
an observer after a plugin reload.
This commit is contained in:
parent
ff86d2cccd
commit
ed61675016
@ -56,11 +56,15 @@ def configure(advanced):
|
|||||||
|
|
||||||
class Probability(registry.Float):
|
class Probability(registry.Float):
|
||||||
"""Value must be a floating point number in the range (0, 1]."""
|
"""Value must be a floating point number in the range (0, 1]."""
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.__parent = super(Probability, self)
|
||||||
|
self.__parent.__init__(*args, **kwargs)
|
||||||
|
|
||||||
def setValue(self, v):
|
def setValue(self, v):
|
||||||
if not 0 < v <= 1:
|
if not 0 < v <= 1:
|
||||||
self.error()
|
self.error()
|
||||||
else:
|
else:
|
||||||
super(Probability, self).setValue(v)
|
self.__parent.setValue(v)
|
||||||
|
|
||||||
class Observers(registry.SpaceSeparatedListOfStrings):
|
class Observers(registry.SpaceSeparatedListOfStrings):
|
||||||
List = callbacks.CanonicalNameSet
|
List = callbacks.CanonicalNameSet
|
||||||
@ -77,7 +81,7 @@ conf.registerGlobalValue(conf.supybot.plugins.Observer, 'observers',
|
|||||||
conf.registerChannelValue(conf.supybot.plugins.Observer.observers, 'active',
|
conf.registerChannelValue(conf.supybot.plugins.Observer.observers, 'active',
|
||||||
ActiveObservers([], """Determines what observers are
|
ActiveObservers([], """Determines what observers are
|
||||||
active on a channel."""))
|
active on a channel."""))
|
||||||
|
|
||||||
|
|
||||||
def registerObserver(name, regexpString='',
|
def registerObserver(name, regexpString='',
|
||||||
commandString='', probability=1.0):
|
commandString='', probability=1.0):
|
||||||
@ -102,11 +106,15 @@ class Observer(callbacks.Privmsg):
|
|||||||
commandCalled = False
|
commandCalled = False
|
||||||
def _isValidObserverName(self, name):
|
def _isValidObserverName(self, name):
|
||||||
return name != 'active' and registry.isValidRegistryName(name)
|
return name != 'active' and registry.isValidRegistryName(name)
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.__parent = super(Observer, self)
|
||||||
|
self.__parent.__init__()
|
||||||
|
|
||||||
def callCommand(self, *args, **kwargs):
|
def callCommand(self, *args, **kwargs):
|
||||||
self.commandCalled = True
|
self.commandCalled = True
|
||||||
super(Observer, self).callCommand(*args, **kwargs)
|
self.__parent.callCommand(*args, **kwargs)
|
||||||
|
|
||||||
def doPrivmsg(self, irc, msg):
|
def doPrivmsg(self, irc, msg):
|
||||||
if self.commandCalled:
|
if self.commandCalled:
|
||||||
self.commandCalled = False
|
self.commandCalled = False
|
||||||
@ -134,7 +142,7 @@ class Observer(callbacks.Privmsg):
|
|||||||
command = command.replace('$%s' % i, group)
|
command = command.replace('$%s' % i, group)
|
||||||
tokens = callbacks.tokenize(command, channel=channel)
|
tokens = callbacks.tokenize(command, channel=channel)
|
||||||
Owner.processTokens(irc, msg, tokens)
|
Owner.processTokens(irc, msg, tokens)
|
||||||
|
|
||||||
def list(self, irc, msg, args):
|
def list(self, irc, msg, args):
|
||||||
"""[<channel>]
|
"""[<channel>]
|
||||||
|
|
||||||
@ -152,7 +160,7 @@ class Observer(callbacks.Privmsg):
|
|||||||
# We don't sort because order matters.
|
# We don't sort because order matters.
|
||||||
else:
|
else:
|
||||||
observers = self.registryValue('observers')
|
observers = self.registryValue('observers')
|
||||||
utils.sortBy(str.lower, observers)
|
observers = utils.sorted(observers, key=str.lower)
|
||||||
if observers:
|
if observers:
|
||||||
irc.reply(utils.commaAndify(observers))
|
irc.reply(utils.commaAndify(observers))
|
||||||
else:
|
else:
|
||||||
@ -184,7 +192,7 @@ class Observer(callbacks.Privmsg):
|
|||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
irc.error('The observer %s was not active on %s.' % (name,channel))
|
irc.error('The observer %s was not active on %s.' % (name,channel))
|
||||||
disable = privmsgs.checkChannelCapability(disable, 'op')
|
disable = privmsgs.checkChannelCapability(disable, 'op')
|
||||||
|
|
||||||
def info(self, irc, msg, args):
|
def info(self, irc, msg, args):
|
||||||
"""<name>
|
"""<name>
|
||||||
|
|
||||||
@ -200,7 +208,7 @@ class Observer(callbacks.Privmsg):
|
|||||||
irc.reply('%s matches the regular expression %s and '
|
irc.reply('%s matches the regular expression %s and '
|
||||||
'runs the command %s with a probability of %s' %
|
'runs the command %s with a probability of %s' %
|
||||||
(name, regexp, command, probability))
|
(name, regexp, command, probability))
|
||||||
|
|
||||||
def add(self, irc, msg, args):
|
def add(self, irc, msg, args):
|
||||||
"""<name> [<probability>] <regexp> <command>
|
"""<name> [<probability>] <regexp> <command>
|
||||||
|
|
||||||
@ -232,7 +240,7 @@ class Observer(callbacks.Privmsg):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Class = Observer
|
Class = Observer
|
||||||
|
@ -427,7 +427,7 @@ def sortBy(f, L):
|
|||||||
def sorted(iterable, cmp=None, key=None, reversed=False):
|
def sorted(iterable, cmp=None, key=None, reversed=False):
|
||||||
L = list(iterable)
|
L = list(iterable)
|
||||||
if key is not None:
|
if key is not None:
|
||||||
assert cmp is not None, 'Can\'t use both cmp and key.'
|
assert cmp is None, 'Can\'t use both cmp and key.'
|
||||||
sortBy(key, L)
|
sortBy(key, L)
|
||||||
else:
|
else:
|
||||||
L.sort(cmp)
|
L.sort(cmp)
|
||||||
|
@ -51,6 +51,10 @@ class ObserverTestCase(ChannelPluginTestCase):
|
|||||||
self.assertResponse('testing, 1 2 3' , '1')
|
self.assertResponse('testing, 1 2 3' , '1')
|
||||||
self.assertNotError('observer disable digits')
|
self.assertNotError('observer disable digits')
|
||||||
|
|
||||||
|
def testList(self):
|
||||||
|
self.assertNotError('add foo m/foo/i echo I saw foo.')
|
||||||
|
self.assertRegexp('observer list', 'foo')
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user