diff --git a/plugins/Markov.py b/plugins/Markov.py index 0dcc9896d..ca0afaf6a 100644 --- a/plugins/Markov.py +++ b/plugins/Markov.py @@ -55,19 +55,11 @@ import supybot.registry as registry import supybot.schedule as schedule 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.registerGroup(conf.supybot.plugins.Markov, 'randomSpeaking') conf.registerChannelValue(conf.supybot.plugins.Markov.randomSpeaking, - 'probability', Probability(0, """Determines the probability that will be - checked against to determine whether the bot should randomly say + 'probability', registry.Probability(0, """Determines the probability that + 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 bot will speak every time we make a check.""")) conf.registerChannelValue(conf.supybot.plugins.Markov.randomSpeaking, diff --git a/plugins/Observer.py b/plugins/Observer.py index 7e5e4aeec..2ef047d06 100644 --- a/plugins/Observer.py +++ b/plugins/Observer.py @@ -54,22 +54,9 @@ def configure(advanced): from supybot.questions import expect, anything, something, yn 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): List = callbacks.CanonicalNameSet - class ActiveObservers(registry.SpaceSeparatedListOfStrings): String = callbacks.canonicalName @@ -94,9 +81,9 @@ def registerObserver(name, regexpString='', what command will be run when this observer is executed.""")) if commandString: g.command.setValue(commandString) - conf.registerGlobalValue(g, 'probability', Probability(probability, """ - Determines what the probability of executing this observer is if it - matches.""")) + conf.registerGlobalValue(g, 'probability', + registry.Probability(probability, """ Determines what the probability + of executing this observer is if it matches.""")) g.probability.setValue(probability) conf.supybot.plugins.Observer.observers().add(name) return g diff --git a/src/registry.py b/src/registry.py index ae981fc46..73d05c604 100644 --- a/src/registry.py +++ b/src/registry.py @@ -413,6 +413,18 @@ class PositiveFloat(Float): else: 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): """Value is not a valid Python string.""" def set(self, s):