Exemplo n.º 1
0
def test_strings():
    """Test string functions."""
    check(weechat.charset_set('iso-8859-15') == 1)
    check(weechat.charset_set('') == 1)
    check(weechat.iconv_to_internal('iso-8859-15', 'abc') == 'abc')
    check(weechat.iconv_from_internal('iso-8859-15', 'abcd') == 'abcd')
    check(weechat.gettext('abcdef') == 'abcdef')
    check(weechat.ngettext('file', 'files', 1) == 'file')
    check(weechat.ngettext('file', 'files', 2) == 'files')
    check(weechat.strlen_screen('abcd') == 4)
    check(weechat.string_match('abcdef', 'abc*', 0) == 1)
    check(weechat.string_match('abcdef', 'abc*', 1) == 1)
    check(weechat.string_match('ABCDEF', 'abc*', 1) == 0)
    check(weechat.string_match_list('abcdef', '*,!abc*', 0) == 0)
    check(weechat.string_match_list('ABCDEF', '*,!abc*', 1) == 1)
    check(weechat.string_match_list('def', '*,!abc*', 0) == 1)
    check(weechat.string_eval_path_home('test ${abc}', {}, {'abc': '123'}, {}) == 'test 123')
    check(weechat.string_mask_to_regex('test*mask') == 'test.*mask')
    check(weechat.string_has_highlight('my test string', 'test,word2') == 1)
    check(weechat.string_has_highlight_regex('my test string', 'test|word2') == 1)
    check(weechat.string_format_size(0) == '0 bytes')
    check(weechat.string_format_size(1) == '1 byte')
    check(weechat.string_format_size(2097152) == '2.10 MB')
    check(weechat.string_format_size(420000000) == '420.00 MB')
    check(weechat.string_remove_color('test', '?') == 'test')
    check(weechat.string_is_command_char('/test') == 1)
    check(weechat.string_is_command_char('test') == 0)
    check(weechat.string_input_for_buffer('test') == 'test')
    check(weechat.string_input_for_buffer('/test') == '')
    check(weechat.string_input_for_buffer('//test') == '/test')
    check(weechat.string_eval_expression("100 > 50", {}, {}, {"type": "condition"}) == '1')
    check(weechat.string_eval_expression("-50 < 100", {}, {}, {"type": "condition"}) == '1')
    check(weechat.string_eval_expression("18.2 > 5", {}, {}, {"type": "condition"}) == '1')
    check(weechat.string_eval_expression("0xA3 > 2", {}, {}, {"type": "condition"}) == '1')
    check(weechat.string_eval_expression("${buffer.full_name}", {}, {}, {}) == 'core.weechat')
Exemplo n.º 2
0
def test_strings():
    """Test string functions."""
    check(weechat.charset_set('iso-8859-15') == 1)
    check(weechat.charset_set('') == 1)
    check(weechat.iconv_to_internal('iso-8859-15', 'abc') == 'abc')
    check(weechat.iconv_from_internal('iso-8859-15', 'abcd') == 'abcd')
    check(weechat.gettext('abcdef') == 'abcdef')
    check(weechat.ngettext('file', 'files', 1) == 'file')
    check(weechat.ngettext('file', 'files', 2) == 'files')
    check(weechat.strlen_screen('abcd') == 4)
    check(weechat.string_match('abcdef', 'abc*', 0) == 1)
    check(weechat.string_match('abcdef', 'abc*', 1) == 1)
    check(weechat.string_match('ABCDEF', 'abc*', 1) == 0)
    check(weechat.string_match_list('abcdef', '*,!abc*', 0) == 0)
    check(weechat.string_match_list('ABCDEF', '*,!abc*', 1) == 1)
    check(weechat.string_match_list('def', '*,!abc*', 0) == 1)
    check(
        weechat.string_eval_path_home('test ${abc}', {}, {'abc': '123'}, {}) ==
        'test 123')
    check(weechat.string_mask_to_regex('test*mask') == 'test.*mask')
    check(weechat.string_has_highlight('my test string', 'test,word2') == 1)
    check(
        weechat.string_has_highlight_regex('my test string', 'test|word2') ==
        1)
    check(weechat.string_format_size(0) == '0 bytes')
    check(weechat.string_format_size(1) == '1 byte')
    check(weechat.string_format_size(2097152) == '2.10 MB')
    check(weechat.string_format_size(420000000) == '420.00 MB')
    check(weechat.string_remove_color('test', '?') == 'test')
    check(weechat.string_is_command_char('/test') == 1)
    check(weechat.string_is_command_char('test') == 0)
    check(weechat.string_input_for_buffer('test') == 'test')
    check(weechat.string_input_for_buffer('/test') == '')
    check(weechat.string_input_for_buffer('//test') == '/test')
    check(
        weechat.string_eval_expression("100 > 50", {}, {},
                                       {"type": "condition"}) == '1')
    check(
        weechat.string_eval_expression("-50 < 100", {}, {},
                                       {"type": "condition"}) == '1')
    check(
        weechat.string_eval_expression("18.2 > 5", {}, {},
                                       {"type": "condition"}) == '1')
    check(
        weechat.string_eval_expression("0xA3 > 2", {}, {},
                                       {"type": "condition"}) == '1')
    check(
        weechat.string_eval_expression("${buffer.full_name}", {}, {}, {}) ==
        'core.weechat')
Exemplo n.º 3
0
def match_against_nicklist(server, channel, hostmask):
    """Compare the hostmask against all users in the channel"""

    infolist = w.infolist_get("irc_nick", "", "{},{}".format(server, channel))

    if "$a:" in hostmask or "$~a" in hostmask:
        field = "account"
        hostmask = hostmask.replace("$a:", "")
        hostfield = False
    else:
        field = "host"
        hostfield = True

    extban_unreg = hostmask == "$~a"
    matches = []

    while w.infolist_next(infolist):
        name = w.infolist_string(infolist, "name")

        if hostfield:
            host = name + "!" + w.infolist_string(infolist, field)
        else:
            host = w.infolist_string(infolist, field)

        if ((extban_unreg and host == "*") or
            (not extban_unreg and w.string_match(host, hostmask, 0))):
            matches.append(name)

    w.infolist_free(infolist)
    return matches
Exemplo n.º 4
0
def match_against_nicklist(server, channel, hostmask):
    """Compare the hostmask against all users in the channel"""

    infolist = w.infolist_get("irc_nick", "", "{},{}".format(server, channel))

    if "$a:" in hostmask or "$~a" in hostmask:
        field = "account"
        hostmask = hostmask.replace("$a:", "")
        hostfield = False
    else:
        field = "host"
        hostfield = True

    extban_unreg = hostmask == "$~a"
    matches = []

    while w.infolist_next(infolist):
        name = w.infolist_string(infolist, "name")

        if hostfield:
            host = name + "!" + w.infolist_string(infolist, field)
        else:
            host = w.infolist_string(infolist, field)

        if ((extban_unreg and host == "*") or
            (not extban_unreg and w.string_match(host, hostmask, 0))):
            matches.append(name)

    w.infolist_free(infolist)
    return matches
Exemplo n.º 5
0
def fmt_prefix(data):
    """Read and transform the prefix as per user settings"""

    fmt = w.config_get_plugin("prefix")

    if "_script_name_" in fmt:
        fmt = fmt.replace("_script_name_", SCRIPT_NAME)
    if "_setter_" in fmt:
        fmt = fmt.replace("_setter_", data["setter"])
    if "_prefix_network_" in fmt:
        fmt = fmt.replace(
            "_prefix_network_",
            w.config_string(w.config_get("weechat.look.prefix_network")))
    col = w.config_get_plugin("prefix_color")

    pfcol = w.color(col)
    reset = w.color("reset")

    if w.string_match(fmt, "[*]", 0):
        fmt = fmt.replace("[", "{}[{}".format(pfcol, reset)).replace(
            "]", "{}]{}".format(pfcol, reset))
    else:
        fmt = "{}{}{}".format(pfcol, fmt, reset)

    return fmt
Exemplo n.º 6
0
def message_callback(data, buffer, date, tags, displayed, highlight, prefix,
                     message):
    nick = get_sender(tags, prefix)

    if should_send(buffer, tags, nick, int(highlight)):
        message = '%s%s%s' % (nick, weechat.config_get_plugin('separator'),
                              message)

        if int(highlight):
            buffer_names = get_buffer_names(buffer)
            send_message(buffer_names[0] or buffer_names[1], message)
        elif not (weechat.string_match(message, "->*", 0)
                  or weechat.string_match(message, "<--*", 0)):
            send_message('Private Message', message)

    return weechat.WEECHAT_RC_OK
Exemplo n.º 7
0
def check_nicklist_cb(data, modifier, modifier_data, string):
    ''' The callback that checks if nicklist should be displayed '''

    buffer = w.window_get_pointer(modifier_data, "buffer")
    if buffer:
        buffer_name = w.buffer_get_string(buffer, 'plugin') + '.' + w.buffer_get_string(buffer, 'name')
        buffers_list = w.config_get_plugin('buffers')
        if w.config_get_plugin('action') == 'show':
            for buffer_mask in buffers_list.split(','):
                if w.string_match(buffer_name, buffer_mask, 1):
                    return "1"
            return "0"
        else:
            for buffer_mask in buffers_list.split(','):
                if w.string_match(buffer_name, buffer_mask, 1):
                    return "0"
            return "1"
    return "1"
Exemplo n.º 8
0
def check_nicklist_cb(data, modifier, modifier_data, string):
    """ The callback that checks if nicklist should be displayed """

    buffer = w.window_get_pointer(modifier_data, "buffer")
    if buffer:
        buffer_name = w.buffer_get_string(buffer, "plugin") + "." + w.buffer_get_string(buffer, "name")
        buffers_list = w.config_get_plugin("buffers")
        if w.config_get_plugin("action") == "show":
            for buffer_mask in buffers_list.split(","):
                if w.string_match(buffer_name, buffer_mask, 1):
                    return "1"
            return "0"
        else:
            for buffer_mask in buffers_list.split(","):
                if w.string_match(buffer_name, buffer_mask, 1):
                    return "0"
            return "1"
    return "1"
Exemplo n.º 9
0
def bas_signal_buffer_opened_cb(data, signal, signal_data):
    buffer = signal_data
    name = "%s.%s" % (weechat.buffer_get_string(buffer, "plugin"), weechat.buffer_get_string(buffer, "name"))
    options = weechat.infolist_get("option", "", "%s.buffer.*" % CONFIG_FILE_NAME)
    if options:
        while weechat.infolist_next(options):
            option = weechat.infolist_string(options, "option_name")
            value = weechat.infolist_string(options, "value")
            if option:
                pos = option.rfind(".")
                if pos > 0:
                    buffer_mask = option[0:pos]
                    property = option[pos + 1 :]
                    if buffer_mask and property:
                        if weechat.string_match(name, buffer_mask, 1):
                            weechat.buffer_set(buffer, property, value)
        weechat.infolist_free(options)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 10
0
def bas_signal_buffer_opened_cb(data, signal, signal_data):
    buffer = signal_data
    name = "%s.%s" % (weechat.buffer_get_string(buffer, "plugin"),
                      weechat.buffer_get_string(buffer, "name"))
    options = weechat.infolist_get("option", "", "%s.buffer.*" % CONFIG_FILE_NAME)
    if options:
        while weechat.infolist_next(options):
            option = weechat.infolist_string(options, "option_name")
            value = weechat.infolist_string(options, "value")
            if option:
                pos = option.rfind(".")
                if pos > 0:
                    buffer_mask = option[0:pos]
                    property = option[pos+1:]
                    if buffer_mask and property:
                        if weechat.string_match(name, buffer_mask, 1):
                            weechat.buffer_set(buffer, property, value)
        weechat.infolist_free(options)
    return weechat.WEECHAT_RC_OK
Exemplo n.º 11
0
def bas_apply_options_for_buffer(buffer):
    full_name = weechat.buffer_get_string(buffer, "full_name")
    options = weechat.infolist_get("option", "",
                                   "%s.buffer.*" % CONFIG_FILE_NAME)
    if not options:
        return

    while weechat.infolist_next(options):
        option = weechat.infolist_string(options, "option_name")
        value = weechat.infolist_string(options, "value")
        if option:
            pos = option.rfind(".")
            if pos > 0:
                buffer_mask = option[0:pos]
                property = option[pos + 1:]
                if buffer_mask and property:
                    if weechat.string_match(full_name, buffer_mask, 1):
                        weechat.buffer_set(buffer, property, value)

    weechat.infolist_free(options)
Exemplo n.º 12
0
def bas_apply_options_for_buffer(buffer):
    full_name = weechat.buffer_get_string(buffer, "full_name")
    options = weechat.infolist_get("option", "",
                                   "%s.buffer.*" % CONFIG_FILE_NAME)
    if not options:
        return

    while weechat.infolist_next(options):
        option = weechat.infolist_string(options, "option_name")
        value = weechat.infolist_string(options, "value")
        if option:
            pos = option.rfind(".")
            if pos > 0:
                buffer_mask = option[0:pos]
                property = option[pos+1:]
                if buffer_mask and property:
                    if weechat.string_match(full_name, buffer_mask, 1):
                        weechat.buffer_set(buffer, property, value)

    weechat.infolist_free(options)
Exemplo n.º 13
0
def show_nicks_cb(data, signal, signal_data):
    global nicklist

    buffer = weechat.buffer_search('python', 'hipchat_nicks')
    if not buffer:
        return weechat.WEECHAT_RC_OK

    weechat.command("", "/buffer " + weechat.buffer_get_string(buffer, "name"))
    args = weechat.buffer_get_string(buffer, 'localvar_hipchat_args')

    idx = 0
    nicks = sorted(nicklist.items())
    for name, nick in nicks:
        line = '@{name} - {fullname}'.format(name=encode(name), fullname=encode(nick['name']))
        if not args or weechat.string_match(line, args, 0):
            weechat.prnt_y(buffer, idx, line)

            idx += 1

    return weechat.WEECHAT_RC_OK
Exemplo n.º 14
0
def fmt_prefix(data):
    """Read and transform the prefix as per user settings"""

    fmt = w.config_get_plugin("prefix")

    if "_script_name_" in fmt:
        fmt = fmt.replace("_script_name_", SCRIPT_NAME)
    if "_setter_" in fmt:
        fmt = fmt.replace("_setter_", data["setter"])
    if "_prefix_network_" in fmt:
        fmt = fmt.replace("_prefix_network_", w.config_string(w.config_get("weechat.look.prefix_network")))
    col = w.config_get_plugin("prefix_color")


    pfcol = w.color(col)
    reset = w.color("reset")

    if w.string_match(fmt, "[*]", 0):
        fmt = fmt.replace("[", "{}[{}".format(pfcol, reset)).replace("]", "{}]{}".format(pfcol, reset))
    else:
        fmt = "{}{}{}".format(pfcol, fmt, reset)

    return fmt