mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 02:49:27 +01:00
Make Observer remember the active observers. Only allow admins to add/remove
observers. Make sure we remove the observer from the active lists when remove is called.
This commit is contained in:
parent
1f4bef43ac
commit
06307abee1
@ -58,7 +58,7 @@ class Observers(registry.SpaceSeparatedListOfStrings):
|
|||||||
List = callbacks.CanonicalNameSet
|
List = callbacks.CanonicalNameSet
|
||||||
|
|
||||||
class ActiveObservers(registry.SpaceSeparatedListOfStrings):
|
class ActiveObservers(registry.SpaceSeparatedListOfStrings):
|
||||||
String = callbacks.canonicalName
|
List = callbacks.CanonicalNameSet
|
||||||
|
|
||||||
conf.registerPlugin('Observer')
|
conf.registerPlugin('Observer')
|
||||||
conf.registerGlobalValue(conf.supybot.plugins.Observer, 'observers',
|
conf.registerGlobalValue(conf.supybot.plugins.Observer, 'observers',
|
||||||
@ -93,7 +93,10 @@ def unregisterObserver(name):
|
|||||||
g.unregister(name)
|
g.unregister(name)
|
||||||
g().remove(name)
|
g().remove(name)
|
||||||
if name in g.active():
|
if name in g.active():
|
||||||
g.active().remove(name)
|
g = g.active().remove(name)
|
||||||
|
for (_, ga) in g.active.getValues(getChildren=True):
|
||||||
|
if name in ga():
|
||||||
|
ga().remove(name)
|
||||||
|
|
||||||
def getObserver(irc, msg, args, state):
|
def getObserver(irc, msg, args, state):
|
||||||
if args[0] != 'active' and registry.isValidRegistryName(args[0]):
|
if args[0] != 'active' and registry.isValidRegistryName(args[0]):
|
||||||
@ -174,7 +177,7 @@ class Observer(callbacks.Privmsg):
|
|||||||
"""
|
"""
|
||||||
if name not in self.registryValue('observers'):
|
if name not in self.registryValue('observers'):
|
||||||
irc.error('There is no observer %s.' % name, Raise=True)
|
irc.error('There is no observer %s.' % name, Raise=True)
|
||||||
self.registryValue('observers.active', channel).append(name)
|
self.registryValue('observers.active', channel).add(name)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
enable = wrap(enable, [('checkChannelCapability', 'op'), 'observer'])
|
enable = wrap(enable, [('checkChannelCapability', 'op'), 'observer'])
|
||||||
|
|
||||||
@ -225,7 +228,7 @@ class Observer(callbacks.Privmsg):
|
|||||||
"""
|
"""
|
||||||
registerObserver(name, regexp, command, probability)
|
registerObserver(name, regexp, command, probability)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
add = wrap(add, ['observer',
|
add = wrap(add, ['admin', 'observer',
|
||||||
optional('float', 1.0),
|
optional('float', 1.0),
|
||||||
('regexpMatcher', False),
|
('regexpMatcher', False),
|
||||||
'text'])
|
'text'])
|
||||||
@ -240,7 +243,7 @@ class Observer(callbacks.Privmsg):
|
|||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
irc.error('That observer does not exist.')
|
irc.error('That observer does not exist.')
|
||||||
remove = wrap(remove, ['observer'])
|
remove = wrap(remove, ['admin', 'observer'])
|
||||||
|
|
||||||
|
|
||||||
Class = Observer
|
Class = Observer
|
||||||
|
@ -72,8 +72,12 @@ class ObserverTestCase(ChannelPluginTestCase):
|
|||||||
def testRemove(self):
|
def testRemove(self):
|
||||||
self.assertNotError('add foo m/foo/i echo I saw foo.')
|
self.assertNotError('add foo m/foo/i echo I saw foo.')
|
||||||
self.assertRegexp('observer list', 'foo')
|
self.assertRegexp('observer list', 'foo')
|
||||||
|
self.assertNotError('observer enable foo')
|
||||||
self.assertNotError('remove foo')
|
self.assertNotError('remove foo')
|
||||||
self.assertRegexp('observer list', 'no relevant')
|
self.assertRegexp('observer list', 'no relevant')
|
||||||
|
g = conf.supybot.plugins.Observer.observers
|
||||||
|
# This works in IRC. Not sure why it's failing in the test suite
|
||||||
|
self.failIf('foo' in conf.get(g.active, self.channel))
|
||||||
|
|
||||||
def testObserverWithEmptyGroup(self):
|
def testObserverWithEmptyGroup(self):
|
||||||
self.assertNotError('add foo m/foo(bar)?/i echo I saw foo.')
|
self.assertNotError('add foo m/foo(bar)?/i echo I saw foo.')
|
||||||
|
Loading…
Reference in New Issue
Block a user