Esempio n. 1
0
    def _add_gist_commands(self):
        """ Adds persisted gists as commands (on startup). """

        for url in self.gist_urls[:]:
            code = get_code_from_url(url)
            name = basename(url)
            path = self._save_code_to_plugin(name, code)
            for requirement in self._get_requirements(path):
                self._install(requirement)
            if path is not None:
                self._load_plugin_from_path(path)

        return
Esempio n. 2
0
    def add(self, user, args):
        """ Define a bot command, or other hooks from chat.

        This command lets extend the bot, by adding bot commands, or other
        hooks through the chat interface. New commands can be added as shown
        below ::

            ,add command_name
            def main():
                ''' Clears the screen!

                This command is intended to be used when you want to
                divert attention of the users from the previous
                discussion.
                '''

                print '\\n' * 80

        The commands can be added to a gist and the *raw* url can be passed
        to this command, like so ::

            ,add <raw-gist-url>

        For more information, look at
        http://punchagan.github.io/childrens-park/plugins.html#plugins

        """

        if not args:
            return "Didn't get any arguments for the command!"

        # Check if first word in args is a URL.
        first_arg = args.split()[0]

        if is_url(first_arg):
            url = first_arg
            code = get_code_from_url(url)
            name = basename(url)

        else:
            name = first_arg
            code = args[len(name):].strip()

        path = self._save_code_to_plugin(name, code)
        if path is not None:
            self._load_plugin_from_path(path)

        self.message_queue.append('%s registered command %s' % (user, name))

        return