예제 #1
0
파일: plugin.py 프로젝트: affix/Fedbot
    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()
예제 #2
0
파일: plugin.py 프로젝트: affix/Fedbot
    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()
예제 #3
0
파일: plugin.py 프로젝트: Affix/Fedbot
    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()
예제 #4
0
파일: plugin.py 프로젝트: Affix/Fedbot
    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))
예제 #5
0
파일: plugin.py 프로젝트: affix/Fedbot
    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))
예제 #6
0
파일: plugin.py 프로젝트: affix/Fedbot
    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))
예제 #7
0
파일: plugin.py 프로젝트: Affix/Fedbot
    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))
예제 #8
0
파일: plugin.py 프로젝트: Affix/Fedbot
    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()