예제 #1
0
def _cmd_paste(arg1=None, arg2=None):
    if not arg1:
        root = tk.Tk(baseName="")
        root.withdraw()
        result = root.clipboard_get()
        newline = prof.settings_boolean_get("paste", "newline", True)
        if len(result.splitlines()) > 1 and newline:
            prof.send_line(u'\u000A' + result)
        else:
            prof.send_line(result)

        return

    if arg1 == "newline":
        if not arg2:
            prof.cons_show("")
            newline = prof.settings_boolean_get("paste", "newline", True)
            if newline:
                prof.cons_show("paste.py newline: on")
            else:
                prof.cons_show("paste.py newline: off")
        elif arg2 == "on":
            prof.settings_boolean_set("paste", "newline", True)
            prof.cons_show("paste.py newline enabled.")
        elif arg2 == "off":
            prof.settings_boolean_set("paste", "newline", False)
            prof.cons_show("paste.py newline disabled.")
        else:
            prof.cons_bad_cmd_usage("/paste")

        return

    prof.cons_bad_cmd_usage("/paste")
예제 #2
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")
예제 #3
0
def _cmd_paste(arg1=None, arg2=None):
    if not arg1:
        root = tk.Tk(baseName="")
        root.withdraw()
        result = root.clipboard_get()
        newline = prof.settings_boolean_get("paste", "newline", True)
        if len(result.splitlines()) > 1 and newline:
            prof.send_line(u'\u000A' + result)
        else:
            prof.send_line(result)

        return

    if arg1 == "newline":
        if not arg2:
            prof.cons_show("")
            newline = prof.settings_boolean_get("paste", "newline", True)
            if newline:
                prof.cons_show("paste.py newline: on")
            else:
                prof.cons_show("paste.py newline: off")
        elif arg2 == "on":
            prof.settings_boolean_set("paste", "newline", True)
            prof.cons_show("paste.py newline enabled.")
        elif arg2 == "off":
            prof.settings_boolean_set("paste", "newline", False)
            prof.cons_show("paste.py newline disabled.")
        else:
            prof.cons_bad_cmd_usage("/paste")

        return

    prof.cons_bad_cmd_usage("/paste")
예제 #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")
예제 #5
0
def _cmd_python(msg):
    if msg:
        prof.cons_show("python-test: /python command called, arg = " + msg)
    else:
        prof.cons_show("python-test: /python command called with no arg")
    prof.cons_alert()
    prof.notify("python-test: notify", 2000, "Plugins")
    prof.send_line("/vercheck")
    prof.cons_show("python-test: sent \"/vercheck\" command")
예제 #6
0
def _sendline(line):
    if not line:
        prof.cons_bad_cmd_usage("/python-test")
        return

    prof.win_create(plugin_win, _handle_win_input)
    prof.win_focus(plugin_win)
    prof.send_line(line)
    prof.win_show(plugin_win, "called -> prof.send_line: " + line)
예제 #7
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)
예제 #8
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)
예제 #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)
예제 #10
0
def _cmd_imgur(arg1):
    if arg1 == "screenshot":
        file_path = "/tmp/_prof_screenshot.png"
        if sys.platform == "darwin":
            subprocess.call("screencapture " + file_path, shell=True)
        else:
            subprocess.call("scrot " + file_path, shell=True)
    else:
        try:
            file_path = path.expanduser(arg1)
        except IOError as ioe:
            prof.cons_show('Could not find file at ' + file_path)
            return
    try:
        data = client.upload_from_path(file_path, config=None, anon=True)
        prof.send_line(data['link'])
    except ImgurClientError as e:
        prof.log_error('Could not upload to Imgur - ' + e.error_message)
        prof.log_error('Imgur status code - ' + e.status_code)
예제 #11
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)
예제 #12
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)
예제 #13
0
def _cmd_paste():
    clipboard = gtk.Clipboard()
    result = clipboard.wait_for_text()
    prof.send_line(u'\u000A' + result)
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))
예제 #15
0
def prof_post_chat_message_display(barejid, resource, message):
    if bot_state:
        if barejid not in bot_session:
            bot_session[barejid] = bot.create_session()
        response = bot_session[barejid].think(message)
        prof.send_line("/msg " + barejid + " " + response)
예제 #16
0
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")
예제 #17
0
파일: paste.py 프로젝트: seamus-45/dotfiles
def _cmd_paste():
    clipboard = gtk.Clipboard()
    result = clipboard.wait_for_text()
    prof.send_line(u'\u000A' + result)
예제 #18
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)
예제 #19
0
def prof_post_chat_message_display(barejid, resource, message):
    if bot_state:
        if barejid not in bot_session:
            bot_session[barejid] = bot.create_session()
        response = bot_session[barejid].think(message)
        prof.send_line("/msg " + barejid + " " + response)
예제 #20
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))