Esempio n. 1
0
                           "You should add one (e.g. '*****@*****.**')"
                           " and subscribe to it's presence to activate your"
                           " blog.")
                return
        self.compose_message(recipient, subject)

    def compose_message(self,
                        recipient=None,
                        subject=None,
                        level=None,
                        body=None):
        composer = Composer(self, recipient)
        return composer.start(subject, level, body)

    def send_message(self, recipient, subject, body):
        m = pyxmpp.Message(to_jid=recipient,
                           stanza_type="normal",
                           subject=subject,
                           body=body)
        self.cjc.stream.send(m)
        self.info("Your entry has been sent to Jogger.PL")


ui.CommandTable(
    "jogger_pl", 50,
    (ui.Command("jogger_pl", Plugin.cmd_jogger_pl, "/jogger_pl subject",
                "Compose an antry to your Jogger.pl blog",
                ("text")), )).install()

# vi: sts=4 et sw=4
Esempio n. 2
0
        q.newTextChild(q.ns(),"version",d["version"])
        if d["os"]:
            q.newTextChild(q.ns(),"os",d["os"])
        self.cjc.stream.send(iq)

    def version_response(self,stanza):
        version_string=u"%s: " % (stanza.get_from(),)
        name=stanza.xpath_eval("v:query/v:name",{"v":"jabber:iq:version"})
        if name:
            version_string += name[0].getContent().decode("utf-8")
        version=stanza.xpath_eval("v:query/v:version",{"v":"jabber:iq:version"})
        if version:
            version_string += u"/" + version[0].getContent().decode("utf-8")
        os=stanza.xpath_eval("v:query/v:os",{"v":"jabber:iq:version"})
        if os:
            version_string += u" (%s)" % (os[0].getContent().decode("utf-8"),)
        self.info(version_string)

    def version_error(self,stanza):
        self.error(u"Version query error from %s: %s" % (stanza.get_from(),
                        stanza.get_error().serialize()))

ui.CommandTable("version",50,(
    ui.Command("version",Plugin.cmd_version,
        "/version [jid]",
        "Queries software version of given entity"
        " or displays version of the client",
        ("user",)),
    )).install()
# vi: sts=4 et sw=4
Esempio n. 3
0
                return
        else:
            subject = None

        body = args.all()
        if not body:
            self.error("Message body not given")
            return

        items = [item for item in items if item.jid.node]

        self.info(u"Sending message to: %s",
                  u", ".join([unicode(item.jid) for item in items]))

        for item in items:
            m = pyxmpp.Message(to_jid=item.jid, body=body, subject=subject)
            self.cjc.stream.send(m)


ui.CommandTable("multicast", 50, (ui.Command(
    "multi_message", Plugin.cmd_multi_message,
    "/multi_message ((-group regexp) | (-state available|unavailable|online|offline|away|xa|chat|error) | -subscription (none|to|from|both) )...  message",
    "Send message to multiple users from roster. The message will be sent"
    " to all users matching all the given conditions. At least one condition"
    " must be provided.", roster_filter_cmd_args + (
        "-subject opaque",
        "text",
    )), )).install()

# vi: sts=4 et sw=4
Esempio n. 4
0
        if fr.bare() == self.cjc.stream.me.bare():
            self.debug("Ignoring own presence subscription change request")
            return
        typ = stanza.get_type()
        self.cjc.status_buf.append_themed("presence.%s" % (typ, ),
                                          {"user": fr})
        p = stanza.make_accept_response()
        self.cjc.stream.send(p)


ui.CommandTable("presence", 50, (
    ui.Command(
        "online", Plugin.cmd_online,
        "/online [-to jid] [-keep | -clear] [-priority n] [description]",
        "Set availability to 'online' with optional description."
        " '-to' option directs the presence to given user,"
        " '-keep' forces keeping current status description,"
        " '-clear' clears it, '-priority' allows setting the priority"
        " to an integer in range -128 to 127.",
        ("-to jid", "-keep", "-clear", "-priority opaque", "text")),
    ui.CommandAlias("back", "online"),
    ui.Command(
        "away", Plugin.cmd_away,
        "/away [-to jid] [-keep | -clear] [-priority n] [description]",
        "Set availability to 'away' with optional description."
        " '-to' option directs the presence to given user,"
        " '-keep' forces keeping current status description,"
        " '-clear' clears it, '-priority' allows setting the priority"
        " to an integer in range -128 to 127.",
        ("-to jid", "-keep", "-clear", "-priority opaque", "text")),
    ui.Command(
Esempio n. 5
0
            ui.run_command("whois", args)
        finally:
            self.buffer.activate_command_table()

    def cmd_info(self, args):
        self.buffer.deactivate_command_table()
        try:
            if not args.get():
                args = ui.CommandArgs(self.peer.as_unicode())
            ui.run_command("info", args)
        finally:
            self.buffer.activate_command_table()


ui.CommandTable("chat buffer", 50, (
    ui.Command("me", Conversation.cmd_me, "/me text", "Sends /me text",
               ("text", )),
    ui.Command("close", Conversation.cmd_close, "/close",
               "Closes current chat buffer"),
    ui.Command("whois", Conversation.cmd_whois, "/whois [options] [user]",
               None),
    ui.Command("info", Conversation.cmd_info, "/info [options] [user]", None),
)).install()


class Plugin(PluginBase):
    def __init__(self, app, name):
        PluginBase.__init__(self, app, name)
        self.conversations = {}
        cjc_globals.theme_manager.set_default_attrs(theme_attrs)
        cjc_globals.theme_manager.set_default_formats(theme_formats)
        self.available_settings = {
Esempio n. 6
0
                "roster.list_group", params)

        if formatted_list:
            params = {"roster_groups": formatted_list}
            self.cjc.status_buf.append_themed("roster.list", params)
        else:
            self.error("No roster items matches your filter")
        self.cjc.status_buf.update()


roster_filter_cmd_args = ("-group opaque", "-jid opaque", "-state opaque",
                          "-name opaque", "-subscription opaque")

ui.CommandTable("roster", 50, (
    ui.Command(
        "add", Plugin.cmd_add, "/add [-group group]... jid [name]",
        "Add a user to the roster (this doesn't automatically subscribe to his presence).",
        ("-group opaque", "user", "text")),
    ui.Command("remove", Plugin.cmd_remove, "/remove user",
               "Remove user from the roster.", ("user", )),
    ui.Command("rename", Plugin.cmd_rename, "/rename user name",
               "Change visible name of a user in the roster.",
               ("user", "text")),
    ui.Command("group", Plugin.cmd_group, "/group user [+|-]group...",
               "Change groups a user from roster belongs to.",
               ("user", "text")),
    ui.Command("list", Plugin.cmd_list, (
        "/list [-group regexp]..."
        " [-jid regexp]..."
        " [-state available|unavailable|online|offline|away|xa|chat|error]... "
        " [[-name] regexp]..."), "List roster items", roster_filter_cmd_args +
               ("opaque", )),
Esempio n. 7
0
            if item.jid in self.cjc.roster:
                local_item = self.cjc.roster.get_item_by_jid(item.jid)
            else:
                self.info(u"Adding entry: %s (%s)", unicode(item.jid),
                          unicode(item.name))
                local_item = self.cjc.roster.add_item(item.jid,
                                                      name=item.name,
                                                      groups=item.groups)
                iq = local_item.make_roster_push()
                self.cjc.stream.send(iq)

            if item.subscription in (
                    'both', 'to') and local_item.subscription in ('none',
                                                                  'from'):
                self.info(u"Sending supscription request to: %s",
                          unicode(local_item.jid))
                p = pyxmpp.Presence(stanza_type='subscribe',
                                    to_jid=local_item.jid)
                self.cjc.stream.send(p)


ui.CommandTable("roster_ei", 50, (
    ui.Command("export_roster", Plugin.cmd_export_roster,
               "/export_roster filename", "Export roster as an XML file.",
               ("filename", )),
    ui.Command("import_roster", Plugin.cmd_import_roster,
               "/import_roster filename", "Import roster as an XML file.",
               ("filename", )),
)).install()
# vi: sts=4 et sw=4
Esempio n. 8
0
        for h in handlers:
            s=h.split(":",1)
            if len(s)!=2:
                continue
            ev,command=s
            try:
                if re.match(ev,event):
                    if command:
                        ui.run_command(command)
                    return
            except re.error:
                continue

ui.CommandTable("events",95,(
    ui.Command("beep",Plugin.cmd_beep,
        "/shell [pattern...]",
        "Play a 'beep' through a terminal beeper. If patterns are given they are interpreted as"
        " a sequence of 0.1s pauses (characters ' ', '.', '_') and beeps (any other character)"
        " there is a 1s pause beetween patterns."),
    ui.Command("add_event",Plugin.cmd_add_event,
        "/add_event regexp command",
        "Add an event handler. Regexp is regular expression to match events"
        " (usually just an event name) and command is a CJC command (without"
        " leading '/') to execute on the event.",
        ("event","command")),
    ui.Command("show_events",Plugin.cmd_show_events,
        "/show_events",
        "Display active event handlers."),
    )).install()
# vi: sts=4 et sw=4
Esempio n. 9
0
        if not active_window.buffer:
            return "", []
        try:
            muc_room = active_buffer._muc_room
        except AttributeError:
            return "", []

        matches = []
        for w in muc_room.room_state.users.keys():
            if w.startswith(word):
                matches.append([w, 1])
        return self.make_result("", word, matches)


ui.CommandTable("muc buffer", 51, (
    ui.Command("me", Room.cmd_me, "/me text", "Sends /me text", ("text", )),
    ui.Command("subject", Room.cmd_subject, "/subject text",
               "Sets the subject of the room", ("text", )),
    ui.Command("nick", Room.cmd_nick, "/nick text",
               "Changes the nickname used", ("text", )),
    ui.Command("who", Room.cmd_who, "/who ", "Lists users in this room",
               ("text", )),
    ui.Command("query", Room.cmd_query, "/query nick", "Starts a private chat",
               ("muc_nick", )),
    ui.CommandAlias("topic", "subject"),
    ui.Command("leave", Room.cmd_leave, "/leave [jid]", "Leave the chat room",
               ("jid", )),
    ui.Command("configure", Room.cmd_configure, "/configure",
               "Configure the room"),
    ui.Command("close", Room.cmd_close, "/close",
               "Closes current chat buffer"),
Esempio n. 10
0
            data = unicode(data, "utf-8", "replace")
        else:
            data = ` data `
        self.buffer.append_themed("xmlconsole." + dir, data)
        self.buffer.update()

    def unload(self):
        logging.getLogger("pyxmpp.Stream.in").removeHandler(
            self.data_in_handler)
        logging.getLogger("pyxmpp.Stream.in").removeHandler(
            self.data_out_handler)
        ui.uninstall_cmdtable("xmlconsole buffer")
        ui.uninstall_cmdtable("xmlconsole")
        self.cjc.remove_event_handler("stream created", self.ev_stream_created)
        self.cjc.remove_event_handler("stream closed", self.ev_stream_closed)
        self.cmd_close(None)
        return True


ui.CommandTable("xmlconsole buffer", 51,
                (ui.Command("close", Plugin.cmd_close, "/close",
                            "Closes current chat buffer"), )).install()

ui.CommandTable("xmlconsole", 51, (
    ui.Command("xmlconsole", Plugin.cmd_xmlconsole, "/xmlconsole",
               "Open raw XML console"),
    ui.Command("rawxml", Plugin.cmd_rawxml, "/rawxml xmlstring",
               "Send raw xml element"),
)).install()
# vi: sts=4 et sw=4
Esempio n. 11
0
        jid = args.shift()
        if not jid:
            if self.cjc.stream:
                jid = JID(self.cjc.stream.me.domain)
            else:
                jid = self.cjc.settings['jid']
            node = None
        else:
            jid = JID(jid)
            node = args.shift()
        args.finish()
        buffer = DiscoBuffer(self, jid, node)
        buffer.start_disco()

    def unload(self):
        ui.uninstall_cmdtable("disco buffer")
        ui.uninstall_cmdtable("disco")
        return True


ui.CommandTable("disco buffer", 51,
                (ui.Command("close", DiscoBuffer.cmd_close, "/close",
                            "Closes current disco buffer"), )).install()

ui.CommandTable("disco", 51, (ui.Command(
    "disco", Plugin.cmd_disco, "/disco",
    "Do the Services Discovery on the selected JID and node (own server by default)"
), )).install()

# vi: sts=4 et sw=4
Esempio n. 12
0
            self.buffer.append_themed("error", "Not connected!")
            return

        body = args.all()
        if not body:
            self.buffer.append_themed(
                "error", u"Message composition not supported yet"
                " - you must include message body on the command line")
            return

        self.plugin.send_message(self.last_sender, subject, body,
                                 self.last_thread)


ui.CommandTable("message buffer", 50, (
    ui.Command("close", Conversation.cmd_close, "/close",
               "Closes current chat buffer"),
    ui.Command(
        "reply", Conversation.cmd_reply, "/reply [-subject subject] [text]",
        "Reply to the last message in window", ("-subject opaque", "text")),
)).install()


class Plugin(PluginBase):
    def __init__(self, app, name):
        PluginBase.__init__(self, app, name)
        self.conversations = {}
        cjc_globals.theme_manager.set_default_attrs(theme_attrs)
        cjc_globals.theme_manager.set_default_formats(theme_formats)
        self.available_settings = {
            "buffer": ("How received messages should be put in buffers"
                       " (single|separate|per-user|per-thread)",
Esempio n. 13
0
class Test(threading.Thread):
    def __init__(self, plugin, name):
        threading.Thread.__init__(self, name=name)
        self.plugin = plugin
        self.buffer = ui.TextBuffer(name)
        ui.activate_cmdtable("test buffer", self)
        self.stop_it = 0

    def cmd_close(self, args):
        args.finish()
        self.stop_it = 1
        self.buffer.close()


ui.CommandTable("test buffer", 50, (ui.Command(
    "close", Test.cmd_close, "/close", "Closes current test"), )).install()


class ScrollTest(Test):
    def __init__(self, plugin):
        Test.__init__(self, plugin, "Scroll test")

    def run(self):
        self.plugin.info("Test thread started")
        for i in range(0, 200):
            if self.plugin.cjc.exiting:
                break
            if self.stop_it:
                break
            self.buffer.append_line("line %i" % (i + 1, ))
        self.buffer.update()
Esempio n. 14
0
            "warning": self.warning,
            "error": self.error
        }
        try:
            try:
                r = eval(code, vars, vars)
            except SyntaxError:
                r = None
                exec code in vars
        except:
            self.logger.exception("Exception caught in /python code")
            return
        if r is not None:
            self.info(repr(r))


ui.CommandTable("python", 50, (ui.Command(
    "python", Plugin.cmd_python, "/python code|expression",
    "Executes given python code or expression.\n"
    "In the code's namespace following names are defined:\n"
    "  cjc -- CJC Application object.\n"
    "  debug(str,args) -- Passes str%args to debug output.\n"
    "  info(str,args) -- Prints str%args as an info message to the status window.\n"
    "  warning(str,args) -- Prints str%args as a warning message to the status window.\n"
    "  error(str,args) -- Prints str%args as an error message to the status window.\n"
    "If expression is given and evaluates to not None then"
    " it's result will be printed."
    " '/python expression' is equivalent to '/python info(expression)'",
    ("opaque", )), )).install()
# vi: sts=4 et sw=4
Esempio n. 15
0
                        pipe.write(s)
                except (OSError, IOError), e:
                    self.error("Pipe read failed: %s" % (e, ))
            finally:
                ret = pipe.close()
                if ret:
                    self.command_returned(command, ret)
        finally:
            if term:
                cjc_globals.screen.prog_mode()


ui.CommandTable("shell", 50, (
    ui.Command(
        "shell", Plugin.cmd_shell, "/shell [-noterm] command [arg...]",
        "Executes given shelll command. If -noterm option is used"
        " then the command is not given access to the terminal and the screen"
        " is not refreshed after command exits.", ("-noterm", "opaque")),
    ui.Command(
        "pipe_in", Plugin.cmd_pipe_in, "/pipe_in command [arg...]",
        "Takes shell command output as user input. If -noterm option is used"
        " then the command is not given access to the terminal and the screen"
        " is not refreshed after command exits.", ("-noterm", "opaque")),
    ui.Command(
        "pipe_out", Plugin.cmd_pipe_out, "/pipe_out command [arg...]",
        "Feeds shell command with current buffer content. If -noterm"
        " option is used then the command is not given access to the"
        " terminal and the screen is not refreshed after command exits.",
        ("-noterm", "opaque")),
)).install()
# vi: sts=4 et sw=4
Esempio n. 16
0
        for categories in vcard.categories:
            msg += u" Categories:  %s\n" % (u", ".join(categories.keywords),)
        for note in vcard.note:
            msg += u" Note:        %s\n" % (note.value,)
        for sound in vcard.sound:
            if sound.uri:
                msg += u" Sound:       %s\n" % (sound.uri,)
            else:
                msg += u" Sound:       cannot play\n"
        for uid in vcard.uid:
            msg += u" User id:     %s\n" % (uid.value,)
        for url in vcard.url:
            msg += u" URL:         %s\n" % (url.value,)
        for desc in vcard.desc:
            msg += u" Description: %s\n" % (desc.value,)
        self.info(msg)


    def vcard_error(self,stanza):
        err=stanza.get_error()
        self.error(u"vCard query error from %s: %s" % (stanza.get_from(),
                        err.get_message()))

ui.CommandTable("vcard",50,(
    ui.Command("whois",Plugin.cmd_whois,
        "/whois jid",
        "Displays information about an entity.",
        ("user",)),
    )).install()
# vi: sts=4 et sw=4