예제 #1
0
파일: text.py 프로젝트: dpk/duxlot
def create_api_commands(public):
    services = api.text()

    def takes(service, kind):
        if hasattr(service, "argument"):
            return kind == service.argument
        return False

    for name in services:
        if name == "name":
            continue

        def create(name):
            canonicalised = name.strip("_").replace("_", "-")

            @duxlot.named(canonicalised)
            def api_command(env):
                if "limit" in env:
                    limit = env.limit
                else:
                    limit = 360

                arg = env.arg
                if (not arg) and takes(services[name], "link"):
                    if env.sender in env.database.cache.links:
                        arg = env.database.cache.links[env.sender]

                if takes(services[name], "tz"):
                    a, b = zone_from_nick(env, env.nick)
                    arg = ":%s :%s %s" % (a, b, arg)

                # @@ Service type? (irc, web, etc.)
                text = services[name](
                    text=arg,
                    maximum={
                        "bytes": limit,
                        "lines": 3
                    }
                )

                found_links = api.regex_link.findall(text)
                if found_links:
                    with env.database.context("links") as links:
                        links[env.sender] = found_links.pop()

                text = text.rstrip("\n")
                for line in text.split("\n"):
                    env.say(line)
            api_command.__doc__ = services[name].__doc__
        create(name)
예제 #2
0
파일: console.py 프로젝트: dpk/duxlot
    def setup(self):
        print("Loading duxlot API configuration...")
        api.clock.cache_timezones_data()
        api.unicode.cache_unicode_data()

        services = api.text()
        services = services.copy()
        del services["name"]

        for name in services:
            def create(name):
                def command(text):
                    return services[name](
                        text=text,
                        maximum={
                            "bytes": 1024,
                            "lines": 3
                        }
                    )
                return command
            self.commands[name] = create(name)
예제 #3
0
파일: console.py 프로젝트: dpk/duxlot
    def setup(self):
        print("Loading duxlot API configuration...")
        api.clock.cache_timezones_data()
        api.unicode.cache_unicode_data()

        services = api.text()
        services = services.copy()
        del services["name"]

        for name in services:

            def create(name):
                def command(text):
                    return services[name](text=text,
                                          maximum={
                                              "bytes": 1024,
                                              "lines": 3
                                          })

                return command

            self.commands[name] = create(name)