Пример #1
0
def get_last_message_time(buffer):
    lines = weechat.hdata_pointer(weechat.hdata_get("buffer"), buffer,
                                  "own_lines")
    line = weechat.hdata_pointer(weechat.hdata_get("lines"), lines,
                                 "last_line")
    while line:
        line_data = weechat.hdata_pointer(weechat.hdata_get("line"), line,
                                          "data")
        tags_count = weechat.hdata_integer(weechat.hdata_get("line_data"),
                                           line_data, "tags_count")
        tags = [
            weechat.hdata_string(weechat.hdata_get("line_data"), line_data,
                                 "{}|tags_array".format(i))
            for i in range(tags_count)
        ]
        irc_tags = [t for t in tags if t.startswith("irc_")]
        if len(irc_tags) > 0:
            break
        line = weechat.hdata_pointer(weechat.hdata_get("line"), line,
                                     "prev_line")
    if not line:
        return None
    # TODO: get timestamp with millisecond granularity
    ts = weechat.hdata_time(weechat.hdata_get("line_data"), line_data, "date")
    t = datetime.datetime.fromtimestamp(ts, tz=datetime.timezone.utc)
    return t
Пример #2
0
def count_lines(ptr_window,ptr_buffer):
    global filter_status

    hdata_buf = weechat.hdata_get('buffer')
    hdata_lines = weechat.hdata_get('lines')
    lines = weechat.hdata_pointer(hdata_buf, ptr_buffer, 'lines') # own_lines, mixed_lines
    lines_count = weechat.hdata_integer(hdata_lines, lines, 'lines_count')

    hdata_window = weechat.hdata_get('window')
    hdata_winscroll = weechat.hdata_get('window_scroll')
    window_scroll = weechat.hdata_pointer(hdata_window, ptr_window, 'scroll')
    lines_after = weechat.hdata_integer(hdata_winscroll, window_scroll, 'lines_after')
    window_height = weechat.window_get_integer(weechat.current_window(), 'win_chat_height')

    filtered = 0
    filtered_before = 0
    filtered_after = 0
    # if filter is disabled, don't count.
    if (OPTIONS['count_filtered_lines'].lower() == 'off') and filter_status == 1:
        filtered, filtered_before,filtered_after = count_filtered_lines(ptr_buffer,lines_count,lines_after)
        lines_count = lines_count - filtered
#        lines_after = lines_after - filtered_after

    if lines_count > window_height:
        differential = lines_count - window_height
        percent = max(int(round(100. * (differential - lines_after) / differential)), 0)
    else:
        percent = 100

    # get current position
    current_line = lines_count - lines_after

    return lines_after,lines_count,percent,current_line, filtered, filtered_before, filtered_after
Пример #3
0
def unhide_buffer_cb(data, signal, signal_data):
    """Unhide a buffer on new activity.

    This callback unhides a buffer in which a new message has been received.
    If configuration option ``unhide_low`` is enabled,
    buffers with only low priority messages (like JOIN, PART, etc.) will be unhidden as well.

    :param data: Pointer
    :param signal: Signal sent by Weechat
    :param signal_data: Data sent with signal
    :returns: Callback return value expected by Weechat.
    """
    hotlist = hotlist_dict()
    line_data = weechat.hdata_pointer(weechat.hdata_get('line'), signal_data, 'data')
    buffer = weechat.hdata_pointer(weechat.hdata_get('line_data'), line_data, 'buffer')

    if not buffer in hotlist.keys():
        # just some background noise
        return WEECHAT_RC_OK

    if (weechat.config_get_plugin("unhide_low") == "on"
            and hotlist[buffer]["count_low"] > 0
            or hotlist[buffer]["count_message"] > 0
            or hotlist[buffer]["count_private"] > 0
            or hotlist[buffer]["count_highlight"] > 0):
        remove_keep_alive(buffer)
        weechat.buffer_set(buffer, "hidden", "0")

    return WEECHAT_RC_OK
Пример #4
0
def bufsave_cmd(data, buffer, args):
    filename = weechat.buffer_get_string(
        buffer, 'localvar_server') + '.' + weechat.buffer_get_string(
            buffer,
            'localvar_channel')[1:] + '-' + time.strftime('%y_%m_%d') + '.log'
    filename = weechat.string_eval_path_home('%h/logs/' + filename, {}, {}, {})
    try:
        fp = open(filename, 'w')
    except:
        weechat.prnt('', 'Error writing to target file!')
        return weechat.WEECHAT_RC_OK
    own_lines = weechat.hdata_pointer(weechat.hdata_get('buffer'), buffer,
                                      'own_lines')
    if own_lines:
        line = weechat.hdata_pointer(weechat.hdata_get('lines'), own_lines,
                                     'first_line')
        hdata_line = weechat.hdata_get('line')
        hdata_line_data = weechat.hdata_get('line_data')
        while line:
            data = weechat.hdata_pointer(hdata_line, line, 'data')
            if data:
                date = weechat.hdata_time(hdata_line_data, data, 'date')
                if not isinstance(date, str):
                    date = time.strftime('%F %T', time.localtime(int(date)))
                fp.write('{0} {1} {2}\n'.format(
                    date,
                    cstrip(
                        weechat.hdata_string(hdata_line_data, data, 'prefix')),
                    cstrip(
                        weechat.hdata_string(hdata_line_data, data,
                                             'message'))))
            line = weechat.hdata_move(hdata_line, line, 1)
    fp.close()
    return weechat.WEECHAT_RC_OK
Пример #5
0
def get_time_from_line(ptr_buffer):
    lines = weechat.hdata_pointer(weechat.hdata_get('buffer'), ptr_buffer, 'own_lines')

    if lines:
        line = weechat.hdata_pointer(weechat.hdata_get('lines'), lines, 'last_line')
        last_read_line = weechat.hdata_pointer(weechat.hdata_get('lines'), lines, 'last_read_line')
        # last line already read?
        while line != last_read_line:
            hdata_line = weechat.hdata_get('line')
            hdata_line_data = weechat.hdata_get('line_data')

            data = weechat.hdata_pointer(hdata_line, line, 'data')

            date_last_line = weechat.hdata_time(hdata_line_data, data, 'date')
            displayed = weechat.hdata_char(hdata_line_data, data, 'displayed')
            # message hidden?
            if not displayed and OPTIONS['ignore_hidden'].lower() == 'on':
                prev_line = weechat.hdata_pointer(hdata_line, line, 'prev_line')
                line = prev_line
                continue

            # buffer empty?
            if not date_last_line:
                return 0

            get_current_ticks = time.time()

            time_gone = get_current_ticks - date_last_line
            if int(OPTIONS['time']) < time_gone:
                return 1
            else:
                return 0
    return 0
Пример #6
0
def count_lines(ptr_window, ptr_buffer):
    global filter_status

    hdata_buf = weechat.hdata_get("buffer")
    hdata_lines = weechat.hdata_get("lines")
    lines = weechat.hdata_pointer(hdata_buf, ptr_buffer, "lines")  # own_lines, mixed_lines
    lines_count = weechat.hdata_integer(hdata_lines, lines, "lines_count")

    hdata_window = weechat.hdata_get("window")
    hdata_winscroll = weechat.hdata_get("window_scroll")
    window_scroll = weechat.hdata_pointer(hdata_window, ptr_window, "scroll")
    lines_after = weechat.hdata_integer(hdata_winscroll, window_scroll, "lines_after")
    window_height = weechat.window_get_integer(weechat.current_window(), "win_chat_height")

    filtered = 0
    filtered_before = 0
    filtered_after = 0
    # if filter is disabled, don't count.
    if (OPTIONS["count_filtered_lines"].lower() == "off") and filter_status == 1:
        filtered, filtered_before, filtered_after = count_filtered_lines(ptr_buffer, lines_count, lines_after)
        lines_count = lines_count - filtered
    #        lines_after = lines_after - filtered_after

    if lines_count > window_height:
        differential = lines_count - window_height
        percent = max(int(round(100.0 * (differential - lines_after) / differential)), 0)
    else:
        percent = 100

    # get current position
    current_line = lines_count - lines_after

    return lines_after, lines_count, percent, current_line, filtered, filtered_before, filtered_after
Пример #7
0
def count_lines(winpointer, bufpointer):

    hdata_buf = weechat.hdata_get('buffer')
    hdata_lines = weechat.hdata_get('lines')
    lines = weechat.hdata_pointer(hdata_buf, bufpointer,
                                  'lines')  # own_lines, mixed_lines
    lines_count = weechat.hdata_integer(hdata_lines, lines, 'lines_count')

    hdata_window = weechat.hdata_get('window')
    hdata_winscroll = weechat.hdata_get('window_scroll')
    window_scroll = weechat.hdata_pointer(hdata_window, winpointer, 'scroll')
    lines_after = weechat.hdata_integer(hdata_winscroll, window_scroll,
                                        'lines_after')
    window_height = weechat.window_get_integer(weechat.current_window(),
                                               'win_chat_height')

    if lines_count > window_height:
        differential = lines_count - window_height
        percent = max(
            int(round(100. * (differential - lines_after) / differential)), 0)
    else:
        percent = 100
    #weechat.prnt('', " : lines_count "+str(lines_count)+" window_height "+str(window_height)+" lines after "+str(lines_after))
    current_line = lines_count - lines_after
    return lines_after, lines_count, percent, current_line
Пример #8
0
def count_filtered_lines(ptr_buffer, lines_count, lines_after):
    filtered_before = 0
    filtered_after = 0
    filtered = 0

    lines = weechat.hdata_pointer(weechat.hdata_get("buffer"), ptr_buffer, "own_lines")
    counter = 0
    current_position = lines_count - lines_after

    if lines:
        line = weechat.hdata_pointer(weechat.hdata_get("lines"), lines, "first_line")
        hdata_line = weechat.hdata_get("line")
        hdata_line_data = weechat.hdata_get("line_data")

        while line:
            data = weechat.hdata_pointer(hdata_line, line, "data")
            if data:
                #                message = weechat.hdata_string(hdata_line_data, data, 'message')
                displayed = weechat.hdata_char(hdata_line_data, data, "displayed")
                if displayed == 0:
                    #                    weechat.prnt('','%d - %s - %s' % (counter, displayed, message))
                    if counter < current_position:
                        filtered_before += 1
                    else:
                        filtered_after += 1
            counter += 1
            line = weechat.hdata_move(hdata_line, line, 1)

    filtered = filtered_before + filtered_after
    return filtered, filtered_before, filtered_after
Пример #9
0
def fill_last_lines(buffer):
    last_lines.append(get_input_line(buffer, -1))
    hdata = w.hdata_get("buffer")
    lines = w.hdata_pointer(hdata, buffer, "own_lines")

    found = 0
    processed = 0
    lines_limit = int(w.config_get_plugin("lines"))
    raw_lines_limit = int(w.config_get_plugin("raw_lines"))
    line  = w.hdata_pointer(w.hdata_get('lines'), lines, "last_line")

    while found < lines_limit and processed < raw_lines_limit and line != "":
        line_data = w.hdata_pointer(w.hdata_get('line'), line, "data")

        count = w.hdata_integer(w.hdata_get("line_data"), line_data, "tags_count")
        if count == 0:
            processed += 1
            continue

        tag = w.hdata_string(w.hdata_get('line_data'), line_data, "0|tags_array")
        if tag == 'irc_privmsg':
            message = w.hdata_string(w.hdata_get('line_data'), line_data, "message")
            last_lines.append(message)
            found += 1
        line = w.hdata_pointer(w.hdata_get('line'), line, "prev_line")
        processed += 1

    last_lines.append(get_input_line(buffer, 1))
Пример #10
0
def count_filtered_lines(ptr_buffer, lines_count, lines_after):
    filtered_before = 0
    filtered_after = 0
    filtered = 0

    lines = weechat.hdata_pointer(weechat.hdata_get('buffer'), ptr_buffer,
                                  'own_lines')
    counter = 0
    current_position = lines_count - lines_after

    if lines:
        line = weechat.hdata_pointer(weechat.hdata_get('lines'), lines,
                                     'first_line')
        hdata_line = weechat.hdata_get('line')
        hdata_line_data = weechat.hdata_get('line_data')

        while line:
            data = weechat.hdata_pointer(hdata_line, line, 'data')
            if data:
                #                message = weechat.hdata_string(hdata_line_data, data, 'message')
                displayed = weechat.hdata_char(hdata_line_data, data,
                                               'displayed')
                if displayed == 0:
                    #                    weechat.prnt('','%d - %s - %s' % (counter, displayed, message))
                    if counter < current_position:
                        filtered_before += 1
                    else:
                        filtered_after += 1
            counter += 1
            line = weechat.hdata_move(hdata_line, line, 1)

    filtered = filtered_before + filtered_after
    return filtered, filtered_before, filtered_after
Пример #11
0
def bufsave_cmd(data, buffer, args):
    ''' Callback for /bufsave command '''

    filename_raw = args

    if not filename_raw:
        w.command('', '/help %s' % SCRIPT_COMMAND)
        return w.WEECHAT_RC_OK

    filename = w.string_eval_path_home(filename_raw, {}, {}, {})

    if exists(filename):
        w.prnt('', 'Error: target file already exists!')
        return w.WEECHAT_RC_OK

    try:
        fp = open(filename, 'w')
    except:
        w.prnt('', 'Error writing to target file!')
        return w.WEECHAT_RC_OK

    version = w.info_get('version_number', '') or 0
    if int(version) >= 0x00030600:
        # use hdata with WeeChat >= 0.3.6 (direct access to data, very fast)
        own_lines = w.hdata_pointer(w.hdata_get('buffer'), buffer, 'own_lines')
        if own_lines:
            line = w.hdata_pointer(w.hdata_get('lines'), own_lines,
                                   'first_line')
            hdata_line = w.hdata_get('line')
            hdata_line_data = w.hdata_get('line_data')
            while line:
                data = w.hdata_pointer(hdata_line, line, 'data')
                if data:
                    date = w.hdata_time(hdata_line_data, data, 'date')
                    # since WeeChat 0.3.9, hdata_time returns long instead of string
                    if not isinstance(date, str):
                        date = time.strftime('%F %T',
                                             time.localtime(int(date)))
                    fp.write('%s %s %s\n' %(\
                            date,
                            cstrip(w.hdata_string(hdata_line_data, data, 'prefix')),
                            cstrip(w.hdata_string(hdata_line_data, data, 'message')),
                            ))
                line = w.hdata_move(hdata_line, line, 1)
    else:
        # use infolist with WeeChat <= 0.3.5 (full duplication of lines, slow and uses memory)
        infolist = w.infolist_get('buffer_lines', buffer, '')
        while w.infolist_next(infolist):
            fp.write('%s %s %s\n' %(\
                    w.infolist_time(infolist, 'date'),
                    cstrip(w.infolist_string(infolist, 'prefix')),
                    cstrip(w.infolist_string(infolist, 'message')),
                    ))
        w.infolist_free(infolist)

    fp.close()

    return w.WEECHAT_RC_OK
Пример #12
0
def bufsave_cmd(data, buffer, args):
    ''' Callback for /bufsave command '''

    filename_raw = args

    if not filename_raw:
        w.command('', '/help %s' %SCRIPT_COMMAND)
        return w.WEECHAT_RC_OK
    
    filename = w.string_eval_path_home(filename_raw, {}, {}, {})

    if exists(filename):
        w.prnt('', 'Error: target file already exists!')
        return w.WEECHAT_RC_OK

    try:
        fp = open(filename, 'w')
    except:
        w.prnt('', 'Error writing to target file!')
        return w.WEECHAT_RC_OK

    version = w.info_get('version_number', '') or 0
    if int(version) >= 0x00030600:
        # use hdata with WeeChat >= 0.3.6 (direct access to data, very fast)
        own_lines = w.hdata_pointer(w.hdata_get('buffer'), buffer, 'own_lines')
        if own_lines:
            line = w.hdata_pointer(w.hdata_get('lines'), own_lines, 'first_line')
            hdata_line = w.hdata_get('line')
            hdata_line_data = w.hdata_get('line_data')
            while line:
                data = w.hdata_pointer(hdata_line, line, 'data')
                if data:
                    date = w.hdata_time(hdata_line_data, data, 'date')
                    # since WeeChat 0.3.9, hdata_time returns long instead of string
                    if not isinstance(date, str):
                        date = time.strftime('%F %T', time.localtime(int(date)))
                    fp.write('%s %s %s\n' %(\
                            date,
                            cstrip(w.hdata_string(hdata_line_data, data, 'prefix')),
                            cstrip(w.hdata_string(hdata_line_data, data, 'message')),
                            ))
                line = w.hdata_move(hdata_line, line, 1)
    else:
        # use infolist with WeeChat <= 0.3.5 (full duplication of lines, slow and uses memory)
        infolist = w.infolist_get('buffer_lines', buffer, '')
        while w.infolist_next(infolist):
            fp.write('%s %s %s\n' %(\
                    w.infolist_time(infolist, 'date'),
                    cstrip(w.infolist_string(infolist, 'prefix')),
                    cstrip(w.infolist_string(infolist, 'message')),
                    ))
        w.infolist_free(infolist)

    fp.close()

    return w.WEECHAT_RC_OK
Пример #13
0
def test12(data, buffer, arg):
    own_lines = weechat.hdata_pointer(weechat.hdata_get("buffer"), buffer,
                                      'own_lines')
    line = weechat.hdata_pointer(weechat.hdata_get('lines'), own_lines,
                                 'last_line')
    hdata_line_data = weechat.hdata_get('line_data')
    hdata_line = weechat.hdata_get('line')
    d = weechat.hdata_pointer(hdata_line, line, 'data')
    weechat.prnt(buffer, weechat.hdata_string(hdata_line_data, d, 'message'))
    weechat.prnt(buffer, weechat.hdata_string(hdata_line_data, d, 'prefix'))
    return weechat.WEECHAT_RC_OK
Пример #14
0
def logexport_export_cmd(buff, exportFile, mustExportLine):
    """ Called when an export function is called, as `/logexport time`.

    `exportFile` is the name of the file to which we will export.

    `mustExportLine`, when fed a message line (ie. `timestamp, prefix, msg`),
    should return `True` iff this line should be included in the export. The
    lines will be fed one by one starting from the most recent.
    When all the lines that should be exported have been checked, this function
    should raise `StopExport` to avoid looping uselessly through all the
    backlog.
    It is eventually called with `None, None, None` when the top of the backlog
    is reached, and could raise an exception at this time if something went
    wrong.
    """

    cBuffer = weechat.hdata_get('buffer')
    lines = weechat.hdata_pointer(cBuffer, buff, 'lines')
    # 'lines' and not 'own_lines': match what the user sees.

    cLine = weechat.hdata_pointer(weechat.hdata_get('lines'), lines,
                                  'last_line')
    hdata_line = weechat.hdata_get('line')
    hdata_line_data = weechat.hdata_get('line_data')

    gathered = []
    reachedTop = True  # Only False if we `break` at some point
    while cLine:
        data = weechat.hdata_pointer(hdata_line, cLine, 'data')
        if data:
            timestamp = weechat.hdata_time(hdata_line_data, data, 'date')
            prefix = weechat.hdata_string(hdata_line_data, data, 'prefix')
            msg = weechat.hdata_string(hdata_line_data, data, 'message')

            try:
                if mustExportLine(timestamp, prefix, msg):
                    gathered.append(LogLine(timestamp, prefix, msg))
            except StopExport:
                reachedTop = False
                break

        cLine = weechat.hdata_pointer(hdata_line, cLine, 'prev_line')

    if reachedTop:
        # Give `mustExportLine` the chance to signal something went wrong.
        mustExportLine(None, None, None)

    html = renderHtml(gathered[::-1], buff)
    writeFile(html, formatFilePath(exportFile))
Пример #15
0
def hotlist_item_cb(data, item, window):
    priorities = {}
    titles = {}

    hdata_hotlist = w.hdata_get('hotlist')
    ptr_hotlist = w.hdata_get_list(hdata_hotlist, 'gui_hotlist')
    while ptr_hotlist:
        priority = w.hdata_integer(hdata_hotlist, ptr_hotlist, 'priority')
        buffer = w.hdata_pointer(hdata_hotlist, ptr_hotlist, 'buffer')
        count = w.hdata_integer(
            hdata_hotlist, ptr_hotlist, '%d|count' % GUI_HOTLIST_MESSAGE)
        number = w.buffer_get_integer(buffer, 'number')
        name = w.buffer_get_string(buffer, 'short_name')

        if priority != GUI_HOTLIST_LOW:
            priorities[number] = priority
            titles[number] = '%d:%s' % (number, name)
            if count:
                titles[number] += '(%d)' % count

        ptr_hotlist = w.hdata_move(hdata_hotlist, ptr_hotlist, 1)

    items = []
    for number, priority in sorted(priorities.items()):
        items.append('%s %s %s' % (
            w.color(COLORS[priority]),
            titles[number],
            w.color('reset')))
    return ' '.join(items)
Пример #16
0
def exclude_server():
    global OPTIONS
    for server_exclude in OPTIONS['server_exclude'].split(','):
        if server_exclude == '*':  # show buffer for all server
            weechat.command(
                '', '/buffer unhide -all')  # simply unload script, no!? :-)
            break

        # search exclude server in list of servers
        hdata = weechat.hdata_get('irc_server')
        servers = weechat.hdata_get_list(hdata, 'irc_servers')
        if int(version) >= 0x03040000:
            server = weechat.hdata_search(
                hdata,
                servers,
                '${irc_server.name} =* ${server_name}',
                {},
                {'server_name': server_exclude},
                {},
                1,
            )
        else:
            server = weechat.hdata_search(
                hdata,
                servers,
                '${irc_server.name} =* %s' % server_exclude,
                1,
            )
        if server:
            #            is_connected    = weechat.hdata_integer(hdata, server, "is_connected")
            #            nick_modes      = weechat.hdata_string(hdata, server, "nick_modes")
            buffer_ptr = weechat.hdata_pointer(hdata, server, 'buffer')
            weechat.command(buffer_ptr, '/allchan -current /buffer unhide')
    return
Пример #17
0
def layout_apply_cb(data, buffer, command):
    if weechat.config_string_to_boolean(
            weechat.config_get_plugin("layout_apply")):
        m = LAYOUT_APPLY_RE.match(command)
        if m:
            layout_name = m.group(1) or "default"
            hdata_layout = weechat.hdata_get("layout")
            layouts = weechat.hdata_get_list(hdata_layout, "gui_layouts")
            layout = weechat.hdata_search(hdata_layout, layouts,
                                          "${layout.name} == " + layout_name,
                                          1)
            if layout:
                hdata_layout_buffer = weechat.hdata_get("layout_buffer")
                layout_buffer = weechat.hdata_pointer(hdata_layout, layout,
                                                      "layout_buffers")
                while layout_buffer:
                    plugin_name = weechat.hdata_string(hdata_layout_buffer,
                                                       layout_buffer,
                                                       "plugin_name")
                    buffer_name = weechat.hdata_string(hdata_layout_buffer,
                                                       layout_buffer,
                                                       "buffer_name")
                    full_name = "{}.{}".format(plugin_name, buffer_name)

                    buffer = weechat.buffer_search("==", full_name)
                    if not buffer:
                        buffer_open_full_name(full_name, noswitch=True)

                    layout_buffer = weechat.hdata_move(hdata_layout_buffer,
                                                       layout_buffer, 1)
    return weechat.WEECHAT_RC_OK
Пример #18
0
def test12(data, buffer, arg):
    own_lines = weechat.hdata_pointer(weechat.hdata_get("buffer"), buffer,
                                      'own_lines')
    #line = weechat.hdata_pointer(weechat.hdata_get("lines"), own_lines, "last_line")
    #line_data = weechat.hdata_pointer(weechat.hdata_get("line"), line, "data")
    #hdata = weechat.hdata_get("line_data")
    #data = weechat.hdata_pointer(hdata.line, pointer, 'data')
    weechat.prnt("", str(own_lines))
    return weechat.WEECHAT_RC_OK
Пример #19
0
def hdata_server(server_to_search):
    hdata = weechat.hdata_get('irc_server')
    hdata_servers = weechat.hdata_get_list(hdata,'irc_servers')
    server = weechat.hdata_search(hdata, hdata_servers,'${irc_server.name} =* %s' % server_to_search, 1)
    if server:
        is_connected = weechat.hdata_integer(hdata, server, 'is_connected')
        nick_modes = weechat.hdata_string(hdata, server, 'nick_modes')
        buffer_ptr = weechat.hdata_pointer(hdata, server, 'buffer')
    return
Пример #20
0
def hdata_server(server_to_search):
    hdata = weechat.hdata_get('irc_server')
    hdata_servers = weechat.hdata_get_list(hdata, 'irc_servers')
    server = weechat.hdata_search(
        hdata, hdata_servers, '${irc_server.name} =* %s' % server_to_search, 1)
    if server:
        is_connected = weechat.hdata_integer(hdata, server, 'is_connected')
        nick_modes = weechat.hdata_string(hdata, server, 'nick_modes')
        buffer_ptr = weechat.hdata_pointer(hdata, server, 'buffer')
    return
Пример #21
0
def get_buffers():
	''' Get a list of all the buffers in weechat. '''
	hdata  = weechat.hdata_get('buffer')
	buffer = weechat.hdata_get_list(hdata, "gui_buffers");

	result = []
	while buffer:
		number = weechat.hdata_integer(hdata, buffer, 'number')
		result.append((number, buffer))
		buffer = weechat.hdata_pointer(hdata, buffer, 'next_buffer')
	return hdata, result
Пример #22
0
def count_lines(ptr_window, ptr_buffer):
    global filter_status

    hdata_buf = weechat.hdata_get('buffer')
    hdata_lines = weechat.hdata_get('lines')
    lines = weechat.hdata_pointer(hdata_buf, ptr_buffer,
                                  'lines')  # own_lines, mixed_lines
    lines_count = weechat.hdata_integer(hdata_lines, lines, 'lines_count')

    hdata_window = weechat.hdata_get('window')
    hdata_winscroll = weechat.hdata_get('window_scroll')
    window_scroll = weechat.hdata_pointer(hdata_window, ptr_window, 'scroll')
    lines_after = weechat.hdata_integer(hdata_winscroll, window_scroll,
                                        'lines_after')
    window_height = weechat.window_get_integer(weechat.current_window(),
                                               'win_chat_height')

    filtered = 0
    filtered_before = 0
    filtered_after = 0
    # if filter is disabled, don't count.
    if (OPTIONS['count_filtered_lines'].lower()
            == 'off') and filter_status == 1:
        filtered, filtered_before, filtered_after = count_filtered_lines(
            ptr_buffer, lines_count, lines_after)
        lines_count = lines_count - filtered


#        lines_after = lines_after - filtered_after

    if lines_count > window_height:
        differential = lines_count - window_height
        percent = max(
            int(round(100. * (differential - lines_after) / differential)), 0)
    else:
        percent = 100

    # get current position
    current_line = lines_count - lines_after

    return lines_after, lines_count, percent, current_line, filtered, filtered_before, filtered_after
Пример #23
0
def handle_hotlist_change(data, signal, signal_data):
    buffer = signal_data

    if buffer:
        sync_buffer_hotlist(buffer)
        return weechat.WEECHAT_RC_OK

    hdata = weechat.hdata_get("buffer")
    buffer = weechat.hdata_get_list(hdata, "gui_buffers")
    while buffer:
        full_name = weechat.hdata_string(hdata, buffer, "full_name")
        short_name = weechat.hdata_string(hdata, buffer, "short_name")
        hotlist = weechat.hdata_pointer(hdata, buffer, "hotlist")
        if not hotlist and full_name.startswith(
                "irc.") and not full_name.startswith("irc.server."):
            # Trim "irc." prefix and ".<target>" suffix to obtain server name
            server_name = full_name.replace("irc.", "",
                                            1)[:-len(short_name) - 1]
            send_buffer_read(buffer, server_name, short_name)
        buffer = weechat.hdata_pointer(hdata, buffer, "next_buffer")
    return weechat.WEECHAT_RC_OK
Пример #24
0
def count_lines(winpointer, bufpointer):

    hdata_buf = weechat.hdata_get("buffer")
    hdata_lines = weechat.hdata_get("lines")
    lines = weechat.hdata_pointer(hdata_buf, bufpointer, "lines")  # own_lines, mixed_lines
    lines_count = weechat.hdata_integer(hdata_lines, lines, "lines_count")

    hdata_window = weechat.hdata_get("window")
    hdata_winscroll = weechat.hdata_get("window_scroll")
    window_scroll = weechat.hdata_pointer(hdata_window, winpointer, "scroll")
    lines_after = weechat.hdata_integer(hdata_winscroll, window_scroll, "lines_after")
    window_height = weechat.window_get_integer(weechat.current_window(), "win_chat_height")

    if lines_count > window_height:
        differential = lines_count - window_height
        percent = max(int(round(100.0 * (differential - lines_after) / differential)), 0)
    else:
        percent = 100
    # weechat.prnt('', " : lines_count "+str(lines_count)+" window_height "+str(window_height)+" lines after "+str(lines_after))
    current_line = lines_count - lines_after
    return lines_after, lines_count, percent, current_line
Пример #25
0
def exclude_server(server):
    global OPTIONS
    for server_exclude in OPTIONS['server_exclude'].split(','):
        if server_exclude == '*':                                               # show buffer for all server
            weechat.command('','/buffer unhide -all')                           # simply unload script, no!? :-)
            break

        # search exclude server in list of servers
        hdata = weechat.hdata_get('irc_server')
        servers = weechat.hdata_get_list(hdata, 'irc_servers')
        server = weechat.hdata_search(hdata, servers, '${irc_server.name} =* %s' % server_exclude, 1)
        if server:
#            is_connected    = weechat.hdata_integer(hdata, server, "is_connected")
#            nick_modes      = weechat.hdata_string(hdata, server, "nick_modes")
            buffer_ptr = weechat.hdata_pointer(hdata, server, 'buffer')
            weechat.command(buffer_ptr,'/allchan -current /buffer unhide')
    return
Пример #26
0
def buffer_open_full_name_irc_cb(data, signal, hashtable):
    full_name = hashtable["full_name"]
    noswitch = bool(int(hashtable.get("noswitch", "0")))

    m = IRC_SERVER_RE.match(full_name)
    if m:
        server = m.group(1)
        irc_server_open(server, noswitch)
        return weechat.WEECHAT_RC_OK_EAT

    m = IRC_BUFFER_RE.match(full_name)
    if m:
        server = m.group(1)
        name = m.group(2)

        hdata_irc_server = weechat.hdata_get("irc_server")
        irc_servers = weechat.hdata_get_list(hdata_irc_server, "irc_servers")
        irc_server = weechat.hdata_search(hdata_irc_server, irc_servers,
                                          "${irc_server.name} == " + server, 1)
        if irc_server:
            is_connected = bool(
                weechat.hdata_integer(hdata_irc_server, irc_server,
                                      "is_connected"))
            is_connecting = bool(
                weechat.hdata_pointer(hdata_irc_server, irc_server,
                                      "hook_connect"))
            if is_connected:
                irc_buffer_open(server, name, noswitch)
            else:
                irc_server_connected_opens[server].add((name, noswitch))
                if not is_connecting:
                    irc_server_open(server, noswitch)
        else:
            error("unknown server {}".format(server))

        return weechat.WEECHAT_RC_OK_EAT

    return weechat.WEECHAT_RC_OK
Пример #27
0
def build_list(data, item, window):
    # Setup variables
    # First retrieve the `hdata`s, then get relevant lists
    buffer_hdata = weechat.hdata_get('buffer')
    server_hdata = weechat.hdata_get('irc_server')
    hotlist_hdata = weechat.hdata_get('hotlist')
    buffer_pointer = weechat.hdata_get_list(buffer_hdata, 'gui_buffers')
    server_pointer = weechat.hdata_get_list(server_hdata, 'irc_servers')
    bar_width = weechat.config_integer(
        weechat.config_get('weechat.bar.buffers.size'))
    buflist = ''

    # Start looping through the buffers
    while buffer_pointer:
        # Grab the hotlist and priority level for the current buffer
        hotlist_pointer = weechat.hdata_pointer(buffer_hdata, buffer_pointer,
                                                "hotlist")
        if hotlist_pointer:
            priority = weechat.hdata_integer(hotlist_hdata, hotlist_pointer,
                                             'priority')
        else:
            priority = 0

        # Setup the info variables for the current buffer
        nick = weechat.buffer_get_string(buffer_pointer, "localvar_nick")
        name = weechat.buffer_get_string(buffer_pointer, "short_name")
        full_name = weechat.buffer_get_string(buffer_pointer, "name")
        plugin = weechat.buffer_get_string(buffer_pointer, "plugin")
        buffer_type = weechat.buffer_get_string(buffer_pointer,
                                                "localvar_type")
        server = weechat.buffer_get_string(buffer_pointer, 'localvar_server')
        icon_color = weechat.buffer_get_string(buffer_pointer,
                                               "localvar_icon_color") or 0
        current_buffer = 1 if weechat.current_buffer() == buffer_pointer else 0

        # Setup info variables for next buffer
        next_pointer = weechat.hdata_move(buffer_hdata, buffer_pointer, 1)
        next_type = weechat.buffer_get_string(next_pointer, "plugin")

        # Start building!

        # Draw icons for non-IRC buffers - core, script, fset, etc
        # You can set an `icon_color` localvar to override the `color.icon` option for a particular buffer when it's active
        # This isn't exactly ideal. Another option would be to use a localvar for each buffer that gets an icon, and then do a check for that
        if plugin != 'irc':
            if current_buffer:
                if icon_color:
                    buflist += weechat.color(icon_color)
                else:
                    buflist += weechat.color(option_values['color.icon'])
            else:
                buflist += weechat.color(option_values['color.default_fg'])

            buflist += "●  "
            buflist += weechat.color(option_values['color.default_fg'])

            # Add a newline if the next buffer is the start of IRC buffers
            if next_type == 'irc':
                buflist += '\n'
        # Start adding other buffers
        else:
            # Add separator between servers
            if option_values[
                    'look.server_separator'] == '1' and buffer_type == 'server':
                buflist += '─' * bar_width + '\n'
            # Print the appropriate color for the current buffer, as well as an icon for the current buffer
            if current_buffer:
                buflist += weechat.color(option_values['color.current_fg'])
                buflist += "●"
            elif priority == 1:
                buflist += weechat.color(
                    option_values['color.hotlist_message'])
            elif priority == 2:
                buflist += weechat.color(
                    option_values['color.hotlist_private'])
            elif priority == 3:
                buflist += weechat.color(
                    option_values['color.hotlist_highlight'])
            else:
                buflist += weechat.color(option_values['color.default_fg'])

            # Spacing between icon and name
            if current_buffer:
                buflist += ' '
            else:
                buflist += '  '
            if buffer_type != 'server':
                buflist += '   '
            if buffer_type == 'private':
                buflist += '  '

            # Add the nick prefix (@, +, etc)
            nick_prefix = get_nick_prefix(buffer_pointer)
            buflist += nick_prefix

            # Add the buffer name
            buflist += name

            # Add nick modes next to server buffers, if any are set
            if buffer_type == 'server':
                # Search for and retrieve a pointer for the server
                pointer = weechat.hdata_search(
                    server_hdata, server_pointer,
                    '${irc_server.name} == ' + server, 1)

                # Then get the nick modes for that server
                nick_modes = weechat.hdata_string(server_hdata, pointer,
                                                  'nick_modes')

                if nick_modes:
                    buflist += ' (+{})'.format(nick_modes)

            # Add the newline after each buffer
            buflist += '\n'

        # Move to the next buffer
        buffer_pointer = weechat.hdata_move(buffer_hdata, buffer_pointer, 1)

    # All done. Return the list
    return buflist