Beispiel #1
0
def build_admin(env):
    if env.event == "PRIVMSG":
        env.admin = duxlot.Storage()

        env.admin.owner = env.nick == env.options("admin-owner")
        admin_user = (env.nick in env.options("admin-users"))

        env.admin.user = env.admin.owner or admin_user
        env.admin.channel = env.sender in env.options("admin-channels")
        env.admin.place = env.private or env.admin.channel

    return env
Beispiel #2
0
Datei: irc.py Projekt: dpk/duxlot
def create_irc_env(public, message):
    proto = public()
    env = duxlot.Storage(proto.copy())

    env.message = message
    env.event = message["command"]

    if "prefix" in message:
        env.nick = message["prefix"]["nick"]

    if env.event == "PRIVMSG":
        env.sender = message["parameters"][0]
        env.text = message["parameters"][1]
        if "address" in public.data:
            env.limit = 498 - len(env.sender + public.data["address"])

        prefix = public.options("prefix", "channels").get(env.sender)
        if prefix is None:
            prefix = public.options("prefix", "channels").get("", ".")  # @@
        env.prefix = prefix

        if env.text.startswith(prefix):
            sans_prefix = env.text[len(prefix):]

            if " " in sans_prefix:
                env.command, env.arg = sans_prefix.split(" ", 1)
            else:
                env.command, env.arg = sans_prefix, ""

        env.private = env.sender == public.options("nick")
        if env.private:
            env.sender = env.nick

    if "sender" in env:

        def say(text):
            public.msg(env.sender, text)

        env.say = say

    if ("nick" in env) and ("sender" in env):

        def reply(text):
            public.msg(env.sender, env.nick + ": " + text)

        env.reply = reply

    # @@ this shouldn't really be here...
    for builder in duxlot.builders:
        env = builder(env)

    return env
Beispiel #3
0
Datei: irc.py Projekt: dpk/duxlot
    def tasks(self):
        self.main = duxlot.Storage()

        for name, method in task.methods.items():
            setattr(self.main, name, method)

        while True:
            parameters = self.private.queue["main"].get()
            name, arguments = parameters[0], parameters[1:]
            debug("Got task:", name, arguments)

            if name in self.main:
                try:
                    getattr(self.main, name)(self, *arguments)
                except Exception as err:
                    debug("Task Error:", name, err)
Beispiel #4
0
Datei: irc.py Projekt: dpk/duxlot
    def create_private(self):
        private = duxlot.Storage()

        private.command = self.commands.spawn
        # private.events is set later on
        # private.named is set later on
        private.queue = {
            "main": self.processes.queue,
            "send": self.processes["send"].queue,
            "messages": self.processes["messages"].queue,
            "events": self.processes["events"].queue,
            "schedule": self.processes["schedule"].queue
        }
        # private.socket is set in process.Process

        return private
Beispiel #5
0
Datei: irc.py Projekt: dpk/duxlot
    def create_public(self):
        public = duxlot.Storage()

        public.data = self.manager.dict()
        public.data.stamp = 0
        public.database = duxlot.database(
            duxlot.config.path(self.config.base + ".database"),
            self.manager.Namespace())
        public.debug = debug
        public.options = options.Options(self.config.name, self.manager,
                                         public)

        def schedule(*args):
            self.private.queue["schedule"].put(args)

        public.schedule = schedule

        def task(*args):
            self.private.queue["schedule"].put((0, ) + args)

        public.task = task

        def send(*args):
            if not all(isinstance(arg, str) for arg in args):
                debug("Error: public.send:", args)
                return

            if len(args) > 1:
                args = list(args)
                args[-1] = ":" + args[-1]

            octets = " ".join(args).encode("utf-8", "replace")
            self.processes["send"].queue.put(octets)

        public.send = send

        def msg(*args):
            send("PRIVMSG", *args)

        public.msg = msg

        return public