Example #1
0
def prof_post_chat_message_display(barejid, resource, message):
    enabled = prof.settings_string_get("say", "enabled", "off")
    current_recipient = prof.get_current_recipient()
    if enabled == "on" or (enabled == "active" and current_recipient == barejid):
        say(barejid + " says " + message)

    return message
Example #2
0
def prof_post_chat_message_display(barejid, resource, message):
    enabled = prof.settings_string_get("notifycmd", "enabled", "on")
    current_recipient = prof.get_current_recipient()
    if enabled == "on" or (enabled == "active"
                           and current_recipient == barejid):
        notifycmd(barejid, message)
    return message
Example #3
0
def _cmd_browser(url):
    global _lastlink
    link = None

    # use arg if supplied
    if (url != None):
        link = url
    else:
        jid = prof.get_current_recipient()

        # check if in chat window
        if (jid != None):

            # check for link from recipient
            if jid in _lastlink.keys():
                link = _lastlink[jid]
            else:
                prof.cons_show("No links found from " + jid)

        # not in chat window
        else:
            prof.cons_show("You must supply a URL to the /browser command")

    # open the browser if link found
    if (link != None):
        prof.cons_show("Opening " + link + " in browser")
        _open_browser(link)
Example #4
0
def _cmd_system(arg1=None, arg2=None):
    if not arg1:
        create_win()
        prof.win_focus(system_win)
    elif arg1 == "send":
        if arg2 == None:
            prof.cons_bad_cmd_usage("/system")
        else:
            room = prof.get_current_muc()
            recipient = prof.get_current_recipient()
            if room == None and recipient == None:
                prof.cons_show("You must be in a chat or muc window to send a system command")
                prof.cons_alert()
            else:
                result = _get_result(arg2)
                prof.send_line(u'\u000A' + result)
    elif arg1 == "exec":
        if arg2 == None:
            prof.cons_bad_cmd_usage("/system")
        else:
            create_win()
            prof.win_focus(system_win)
            _handle_win_input(system_win, arg2)
    else:
        prof.cons_bad_cmd_usage("/system")
Example #5
0
def _cmd_ascii(text):
    proc = subprocess.Popen(['figlet', '--', text], stdout=subprocess.PIPE)
    ascii_out = proc.communicate()[0].decode('utf-8')
    recipient = prof.get_current_recipient()
    room = prof.get_current_muc()
    if recipient:
        prof.send_line(u'\u000A' + ascii_out)
    elif room:
        prof.send_line(u'\u000A' + ascii_out)
    elif prof.current_win_is_console():
        prof.cons_show(u'\u000A' + ascii_out)
Example #6
0
def _cmd_ascii(text):
    proc = subprocess.Popen(['figlet', '--', text], stdout=subprocess.PIPE)
    ascii_out = proc.communicate()[0].decode('utf-8')
    recipient = prof.get_current_recipient()
    room = prof.get_current_muc()
    if recipient:
        prof.send_line(u'\u000A' + ascii_out)
    elif room:
        prof.send_line(u'\u000A' + ascii_out)
    elif prof.current_win_is_console():
        prof.cons_show(u'\u000A' + ascii_out)
def _get(subject):
    if subject == "recipient":
        prof.win_create(plugin_win, _handle_win_input)
        recipient = prof.get_current_recipient()
        if recipient:
            prof.win_focus(plugin_win)
            prof.win_show(plugin_win,
                          "called -> prof.get_current_recipient: " + recipient)
        else:
            prof.win_focus(plugin_win)
            prof.win_show(plugin_win,
                          "called -> prof_get_current_recipient: <none>")
    elif subject == "room":
        prof.win_create(plugin_win, _handle_win_input)
        room = prof.get_current_muc()
        if room:
            prof.win_focus(plugin_win)
            prof.win_show(plugin_win,
                          "called -> prof_get_current_muc: " + room)
            nick = prof.get_room_nick(room)
            if nick:
                prof.win_focus(plugin_win)
                prof.win_show(
                    plugin_win,
                    "called -> prof_get_room_nick('" + room + "'): " + nick)
        else:
            prof.win_focus(plugin_win)
            prof.win_show(plugin_win, "called -> prof_get_current_muc: <none>")
    elif subject == "nick":
        prof.win_create(plugin_win, _handle_win_input)
        nick = prof.get_current_nick()
        if nick:
            prof.win_focus(plugin_win)
            prof.win_show(plugin_win,
                          "called -> prof_get_current_nick: " + nick)
        else:
            prof.win_focus(plugin_win)
            prof.win_show(plugin_win,
                          "called -> prof_get_current_nick: <none>")
    elif subject == "occupants":
        prof.win_create(plugin_win, _handle_win_input)
        occupants = prof.get_current_occupants()
        if occupants:
            prof.win_focus(plugin_win)
            prof.win_show(plugin_win, "called -> prof_get_current_occupants:")
            for occupant in occupants:
                prof.win_show(plugin_win, occupant)
        else:
            prof.win_focus(plugin_win)
            prof.win_show(plugin_win,
                          "called -> prof_get_current_occupants: <none>")
    else:
        prof.cons_bad_cmd_usage("/python-test")
Example #8
0
def _cmd_copy(msg_index):
    if msg_index is None:
        msg_index = 0
    else:
        msg_index = int(msg_index)

    jid = prof.get_current_recipient()
    msg_list = _get_messages(jid)

    if abs(msg_index) >= len(msg_list):
        prof.chat_show(jid,"Error: message with that index is not stored and cannot be copied to clipboard.")
        return

    msg = msg_list[abs(int(msg_index))]
    pyperclip.copy(msg)
    prof.chat_show(jid, "Copied message '" + msg + "'.")
Example #9
0
def _handle_send(command=None):
    if command == None:
        prof.cons_bad_cmd_usage("/system")
        return

    room = prof.get_current_muc()
    recipient = prof.get_current_recipient()
    if room == None and recipient == None:
        prof.cons_show("You must be in a chat or muc window to send a system command")
        prof.cons_alert()
        return

    result = _get_result(command)
    newline = prof.settings_boolean_get("system", "newline", True)
    if len(result.splitlines()) > 1 and newline:
        prof.send_line(u'\u000A' + result)
    else:
        prof.send_line(result)
Example #10
0
def _handle_send(command=None):
    if command == None:
        prof.cons_bad_cmd_usage("/system")
        return

    room = prof.get_current_muc()
    recipient = prof.get_current_recipient()
    if room == None and recipient == None:
        prof.cons_show(
            "You must be in a chat or muc window to send a system command")
        prof.cons_alert()
        return

    result = _get_result(command)
    newline = prof.settings_boolean_get("system", "newline", True)
    if len(result.splitlines()) > 1 and newline:
        prof.send_line(u'\u000A' + result)
    else:
        prof.send_line(result)
Example #11
0
def prof_post_chat_message_display(barejid, resource, message):
    current_jid = prof.get_current_recipient()
    _process_message(barejid, current_jid, message)
def cmd_pythontest(arg1=None, arg2=None, arg3=None, arg4=None, arg5=None):
    if arg1 == "consalert":
        create_win()
        prof.win_focus(plugin_win)
        prof.cons_alert()
        prof.win_show(plugin_win, "called -> prof.cons_alert")
    elif arg1 == "consshow":
        if arg2 != None:
            create_win()
            prof.win_focus(plugin_win)
            prof.cons_show(arg2)
            prof.win_show(plugin_win, "called -> prof.cons_show: " + arg2)
        else:
            prof.cons_bad_cmd_usage("/python-test")
    elif arg1 == "consshow_t":
        if arg2 == None or arg3 == None or arg4 == None or arg5 == None:
            prof.cons_bad_cmd_usage("/python-test");
        else:
            group = None if arg2 == "none" else arg2
            key = None if arg3 == "none" else arg3
            dflt = None if arg4 == "none" else arg4
            message = arg5
            create_win()
            prof.win_focus(plugin_win)
            prof.cons_show_themed(group, key, dflt, message)
            prof.win_show(plugin_win, "called -> prof.cons_show_themed: " + arg2 + ", " + arg3 + ", " + arg4 + ", " + arg5)
    elif arg1 == "constest":
        res = prof.current_win_is_console()
        create_win()
        prof.win_focus(plugin_win)
        if res:
            prof.win_show(plugin_win, "called -> prof.current_win_is_console: true")
        else:
            prof.win_show(plugin_win, "called -> prof.current_win_is_console: false")
    elif arg1 == "winshow":
        if arg2 != None:
            create_win()
            prof.win_focus(plugin_win)
            prof.win_show(plugin_win, arg2)
            prof.win_show(plugin_win, "called -> prof.win_show: " + arg2)
        else:
            prof.cons_bad_cmd_usage("/python-test")
    elif arg1 == "winshow_t":
        if arg2 == None or arg3 == None or arg4 == None or arg5 == None:
            prof.cons_bad_cmd_usage("/python-test");
        else:
            group = None if arg2 == "none" else arg2
            key = None if arg3 == "none" else arg3
            dflt = None if arg4 == "none" else arg4
            message = arg5
            create_win()
            prof.win_focus(plugin_win)
            prof.win_show_themed(plugin_win, group, key, dflt, message)
            prof.win_show(plugin_win, "called -> prof_win_show_themed: " + arg2 + ", " + arg3 + ", " + arg4 + ", " + arg5)
    elif arg1 == "sendline":
        if arg2 != None:
            create_win()
            prof.win_focus(plugin_win)
            prof.send_line(arg2)
            prof.win_show(plugin_win, "called -> prof.send_line: " + arg2)
        else:
            prof.cons_bad_cmd_usage("/python-test")
    elif arg1 == "notify":
        if arg2 != None:
            create_win()
            prof.win_focus(plugin_win)
            prof.notify(arg2, 5000, "python-test plugin")
            prof.win_show(plugin_win, "called -> prof.notify: " + arg2)
        else:
            prof.cons_bad_cmd_usage("/python-test")
    elif arg1 == "get":
        if arg2 == None:
            prof.cons_bad_cmd_usage("/python-test")
        elif arg2 == "recipient":
            create_win()
            recipient = prof.get_current_recipient();
            if recipient != None:
                prof.win_focus(plugin_win)
                prof.win_show(plugin_win, "called -> prof.get_current_recipient: " + recipient)
            else:
                prof.win_focus(plugin_win)
                prof.win_show(plugin_win, "called -> prof_get_current_recipient: <none>")
        elif arg2 == "room":
            create_win()
            room = prof.get_current_muc()
            if room != None:
                prof.win_focus(plugin_win)
                prof.win_show(plugin_win, "called -> prof_get_current_muc: " + room)
            else:
                prof.win_focus(plugin_win)
                prof.win_show(plugin_win, "called -> prof_get_current_muc: <none>")
        else:
            prof.cons_bad_cmd_usage("/python-test")
    elif arg1 == "log":
        if arg2 == None:
            prof.cons_bad_cmd_usage("/python-test")
        elif arg2 == "debug":
            if arg3 == None:
                prof.cons_bad_cmd_usage("/python-test")
            else:
                create_win()
                prof.win_focus(plugin_win)
                prof.log_debug(arg3)
                prof.win_show(plugin_win, "called -> prof.log_debug: " + arg3)
        elif arg2 == "info":
            if arg3 == None:
                prof.cons_bad_cmd_usage("/python-test")
            else:
                create_win()
                prof.win_focus(plugin_win)
                prof.log_info(arg3)
                prof.win_show(plugin_win, "called -> prof.log_info: " + arg3)
        elif arg2 == "warning":
            if arg3 == None:
                prof.cons_bad_cmd_usage("/python-test")
            else:
                create_win()
                prof.win_focus(plugin_win)
                prof.log_warning(arg3)
                prof.win_show(plugin_win, "called -> prof.log_warning: " + arg3)
        elif arg2 == "error":
            if arg3 == None:
                prof.cons_bad_cmd_usage("/python-test")
            else:
                create_win()
                prof.win_focus(plugin_win)
                prof.log_error(arg3)
                prof.win_show(plugin_win, "called -> prof.log_error: " + arg3)
        else:
            prof.cons_bad_cmd_usage("/python-test")
    elif arg1 == "count":
        create_win()
        prof.win_focus(plugin_win)
        prof.win_show(plugin_win, "Count: " + str(count))
    else:
        prof.cons_bad_cmd_usage("/python-test")
Example #13
0
def _cmd_ascii(text):
    recipient = prof.get_current_recipient()
    if recipient:
        proc = subprocess.Popen(['figlet', '--', text], stdout=subprocess.PIPE)
        ascii_out = proc.communicate()[0].decode('utf-8')
        prof.send_line(u'\u000A' + ascii_out)
Example #14
0
def _timer_test():
    prof.cons_show("python-test: timer fired.")
    recipient = prof.get_current_recipient()
    if recipient:
        prof.cons_show("  current recipient = " + recipient)
    prof.cons_alert()
Example #15
0
def _parse_args(arg1=None, arg2=None, arg3=None):
    """ Parse arguments given in command window

    arg1: start || end
    arg2: muc || jid (optional)

    Starts or ends an encrypted chat session

    """
    account = ProfOmemoUser().account
    fulljid = ProfOmemoUser().fulljid

    if arg1 == 'on':
        _set_omemo_enabled_setting(True)

    elif arg1 == 'off':
        _set_omemo_enabled_setting(False)

    elif arg1 == 'start':
        # ensure we are in a chat window

        current_recipient = prof.get_current_recipient()

        if not current_recipient and arg2 != current_recipient:
            log.info('Opening Chat Window for {0}'.format(arg2))
            prof.send_line('/msg {0}'.format(arg2))

        recipient = arg2 or current_recipient
        if recipient:
            log.info('Start OMEMO session with: {0}'.format(recipient))
            _start_omemo_session(recipient)

    elif arg1 == 'end':
        # ensure we are in a chat window
        jid = arg2 or prof.get_current_muc() or prof.get_current_recipient()
        log.info('Ending OMEMO session with: {0}'.format(jid))
        if jid:
            _end_omemo_session(jid)

    elif arg1 == 'set':
        if arg2 == 'message_prefix':
            if arg3 is not None:
                _set_omemo_message_char(arg3)

    elif arg1 == 'account':
        prof.cons_show('Account: {0}'.format(account))

    elif arg1 == 'status':
        enabled = _get_omemo_enabled_setting()
        prof.cons_show('OMEMO Plugin Enabled: {0}'.format(enabled))

    elif arg1 == 'fulljid':
        prof.cons_show('Current JID: {0}'.format(fulljid))

    elif arg1 == 'show_devices' and arg2 is not None:
        account = arg2
        omemo_state = ProfOmemoState()
        prof.cons_show('Requesting Devices...')
        devices = omemo_state.device_list_for(account)
        prof.cons_show('Devices: {0}'.format(devices))
        prof.cons_show('{0}: {1}'.format(account, ', '.join(devices)))

    elif arg1 == 'reset_devicelist' and arg2 is not None:
        contact_jid = arg2
        if contact_jid != ProfOmemoUser.account:
            omemo_state = ProfOmemoState()
            omemo_state.set_devices(contact_jid, [])
            _query_device_list(contact_jid)

    elif arg1 == 'fingerprints':
        if arg2:
            contact_jid = query_jid = arg2
        else:
            # The local account is identified as '-1' in the OMEMO database
            contact_jid = ProfOmemoUser.account
            query_jid = '-1'
        omemo_state = ProfOmemoState()

        fingerprints = omemo_state.getFingerprints(query_jid)
        prof.cons_show('Fingerprints for account: {0}'.format(contact_jid))

        for record in fingerprints:
            _id, recipient_id, public_key, trust = record
            fpr = binascii.hexlify(public_key)
            fpr = human_hash(fpr[2:])

            prof.cons_show(' {0}'.format(fpr))

    else:
        prof.cons_show('Argument {0} not supported.'.format(arg1))
def _parse_args(arg1=None, arg2=None, arg3=None):
    """ Parse arguments given in command window

    arg1: start || end
    arg2: muc || jid (optional)

    Starts or ends an encrypted chat session

    """
    account = ProfOmemoUser().account
    fulljid = ProfOmemoUser().fulljid

    if arg1 == 'on':
        _set_omemo_enabled_setting(True)

    elif arg1 == 'off':
        _set_omemo_enabled_setting(False)

    elif arg1 == 'start':
        # ensure we are in a chat window

        current_recipient = prof.get_current_recipient()

        if not current_recipient and arg2 != current_recipient:
            log.info('Opening Chat Window for {0}'.format(arg2))
            prof.send_line('/msg {0}'.format(arg2))

        recipient = arg2 or current_recipient
        if recipient:
            log.info('Start OMEMO session with: {0}'.format(recipient))
            _start_omemo_session(recipient)

    elif arg1 == 'end':
        # ensure we are in a chat window
        jid = arg2 or prof.get_current_muc() or prof.get_current_recipient()
        log.info('Ending OMEMO session with: {0}'.format(jid))
        if jid:
            _end_omemo_session(jid)

    elif arg1 == 'set':
        if arg2 == 'message_prefix':
            if arg3 is not None:
                _set_omemo_message_char(arg3)

    elif arg1 == 'account':
        prof.cons_show('Account: {0}'.format(account))

    elif arg1 == 'status':
        enabled = _get_omemo_enabled_setting()
        prof.cons_show('OMEMO Plugin Enabled: {0}'.format(enabled))

    elif arg1 == 'fulljid':
        prof.cons_show('Current JID: {0}'.format(fulljid))

    elif arg1 == 'show_devices' and arg2 is not None:
        account = arg2
        omemo_state = ProfOmemoState()
        prof.cons_show('Requesting Devices...')
        devices = omemo_state.device_list_for(account)
        prof.cons_show('Devices: {0}'.format(devices))
        prof.cons_show('{0}: {1}'.format(account, ', '.join(devices)))

    elif arg1 == 'reset_devicelist' and arg2 is not None:
        contact_jid = arg2
        if contact_jid != ProfOmemoUser.account:
            omemo_state = ProfOmemoState()
            omemo_state.set_devices(contact_jid, [])
            _query_device_list(contact_jid)

    elif arg1 == 'fingerprints':
        if arg2:
            contact_jid = query_jid = arg2
        else:
            # The local account is identified as '-1' in the OMEMO database
            contact_jid = ProfOmemoUser.account
            query_jid = '-1'
        omemo_state = ProfOmemoState()

        fingerprints = omemo_state.getFingerprints(query_jid)
        prof.cons_show('Fingerprints for account: {0}'.format(contact_jid))

        for record in fingerprints:
            _id, recipient_id, public_key, trust = record
            fpr = binascii.hexlify(public_key)
            fpr = human_hash(fpr[2:])

            prof.cons_show(' {0}'.format(fpr))

    else:
        prof.cons_show('Argument {0} not supported.'.format(arg1))
Example #17
0
def _cmd_ascii(text):
    recipient = prof.get_current_recipient()
    if recipient:
        proc = subprocess.Popen(['figlet', '--', text], stdout=subprocess.PIPE)
        ascii_out = proc.communicate()[0].decode('utf-8')
        prof.send_line(u'\u000A' + ascii_out)
Example #18
0
def prof_post_chat_message_display(barejid, resource, message):
    current_jid = prof.get_current_recipient()
    _process_message(barejid, current_jid, message)