def add(self, irc, msg, args): """<name> [<probability>] <regexp> <command> Calls <command> when <regexp> matches a given message. Before being called, <command> has the standard substitute applied to it, as well as having $1, $2, etc. replaced by the appropriate groups of the regexp. If <probability> is not given, it defaults to 1; otherwise it should be a floating point probability that the observer will execute if it matches. """ if len(args) < 3: raise callbacks.ArgumentError try: probability = float(args[1]) del args[1] except ValueError: probability = 1.0 (name, regexp, command) = ircmsgs.getArgs(args, required=3) if not registry.isValidRegistryName(name): irc.error( 'That\'s not a valid observer name. Please be sure ' 'there are no spaces in the name.', Raise=True) registerObserver(name, regexp, command, probability) irc.replySuccess()
def enable(self, irc, msg, args, channel): """[<channel>] <name> Enables the observer <name> in <channel>. <channel> is only necessary if the message isn't sent in the channel itself. """ name = ircmsgs.getArgs(args) if name not in self.registryValue('observers'): irc.error('There is no observer %s.' % name, Raise=True) self.registryValue('observers.active', channel).append(name) irc.replySuccess()
def disable(self, irc, msg, args, channel): """[<channel>] <name> Disables the observer <name> in <channel>. <channel> is only necessary if the message isn't sent in the channel itself. """ name = ircmsgs.getArgs(args) try: self.registryValue('observers.active', channel).remove(name) irc.replySuccess() except (KeyError, ValueError): irc.error('The observer %s was not active on %s.' % (name,channel))
def disable(self, irc, msg, args, channel): """[<channel>] <name> Disables the observer <name> in <channel>. <channel> is only necessary if the message isn't sent in the channel itself. """ name = ircmsgs.getArgs(args) try: self.registryValue('observers.active', channel).remove(name) irc.replySuccess() except (KeyError, ValueError): irc.error('The observer %s was not active on %s.' % (name, channel))
def info(self, irc, msg, args): """<name> Returns the relevant information on the observer specified by <name>. """ name = ircmsgs.getArgs(args) if name not in self.registryValue('observers'): irc.error('That\'s not a valid observer.', Raise=True) g = self.registryValue('observers.%s' % name, value=False) regexp = g() command = g.command() probability = g.probability() irc.reply('%s matches the regular expression %s and ' 'runs the command %s with a probability of %s' % (name, regexp, command, probability))
def add(self, irc, msg, args): """<name> [<probability>] <regexp> <command> Calls <command> when <regexp> matches a given message. Before being called, <command> has the standard substitute applied to it, as well as having $1, $2, etc. replaced by the appropriate groups of the regexp. If <probability> is not given, it defaults to 1; otherwise it should be a floating point probability that the observer will execute if it matches. """ if len(args) < 3: raise callbacks.ArgumentError try: probability = float(args[1]) del args[1] except ValueError: probability = 1.0 (name, regexp, command) = ircmsgs.getArgs(args, required=3) if not registry.isValidRegistryName(name): irc.error('That\'s not a valid observer name. Please be sure ' 'there are no spaces in the name.', Raise=True) registerObserver(name, regexp, command, probability) irc.replySuccess()