Move the Probability class to src/registry.py

This commit is contained in:
James Vega 2004-11-28 08:05:56 +00:00
parent 7eed44eef7
commit 9a3d196986
3 changed files with 17 additions and 26 deletions

View File

@ -55,19 +55,11 @@ import supybot.registry as registry
import supybot.schedule as schedule import supybot.schedule as schedule
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
class Probability(registry.Float):
"""Value must be a floating-point number between 0 and 1."""
def setValue(self, v):
if v < 0 or v > 1:
self.error()
else:
registry.Float.setValue(self, float(v))
conf.registerPlugin('Markov') conf.registerPlugin('Markov')
conf.registerGroup(conf.supybot.plugins.Markov, 'randomSpeaking') conf.registerGroup(conf.supybot.plugins.Markov, 'randomSpeaking')
conf.registerChannelValue(conf.supybot.plugins.Markov.randomSpeaking, conf.registerChannelValue(conf.supybot.plugins.Markov.randomSpeaking,
'probability', Probability(0, """Determines the probability that will be 'probability', registry.Probability(0, """Determines the probability that
checked against to determine whether the bot should randomly say will be checked against to determine whether the bot should randomly say
something. If 0, the bot will never say anything on it's own. If 1, the something. If 0, the bot will never say anything on it's own. If 1, the
bot will speak every time we make a check.""")) bot will speak every time we make a check."""))
conf.registerChannelValue(conf.supybot.plugins.Markov.randomSpeaking, conf.registerChannelValue(conf.supybot.plugins.Markov.randomSpeaking,

View File

@ -54,22 +54,9 @@ def configure(advanced):
from supybot.questions import expect, anything, something, yn from supybot.questions import expect, anything, something, yn
conf.registerPlugin('Observer', True) conf.registerPlugin('Observer', True)
class Probability(registry.Float):
"""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):
if not 0 < v <= 1:
self.error()
else:
self.__parent.setValue(v)
class Observers(registry.SpaceSeparatedListOfStrings): class Observers(registry.SpaceSeparatedListOfStrings):
List = callbacks.CanonicalNameSet List = callbacks.CanonicalNameSet
class ActiveObservers(registry.SpaceSeparatedListOfStrings): class ActiveObservers(registry.SpaceSeparatedListOfStrings):
String = callbacks.canonicalName String = callbacks.canonicalName
@ -94,9 +81,9 @@ def registerObserver(name, regexpString='',
what command will be run when this observer is executed.""")) what command will be run when this observer is executed."""))
if commandString: if commandString:
g.command.setValue(commandString) g.command.setValue(commandString)
conf.registerGlobalValue(g, 'probability', Probability(probability, """ conf.registerGlobalValue(g, 'probability',
Determines what the probability of executing this observer is if it registry.Probability(probability, """ Determines what the probability
matches.""")) of executing this observer is if it matches."""))
g.probability.setValue(probability) g.probability.setValue(probability)
conf.supybot.plugins.Observer.observers().add(name) conf.supybot.plugins.Observer.observers().add(name)
return g return g

View File

@ -413,6 +413,18 @@ class PositiveFloat(Float):
else: else:
super(PositiveFloat, self).setValue(v) super(PositiveFloat, self).setValue(v)
class Probability(Float):
"""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):
if 0 <= v <= 1:
self.__parent.setValue(v)
else:
self.error()
class String(Value): class String(Value):
"""Value is not a valid Python string.""" """Value is not a valid Python string."""
def set(self, s): def set(self, s):