Пример #1
0
def reorder_buffers():
    global buffers
    bufcopy = dict(buffers)
    priolist = []
    while len(bufcopy):
        priolist.append(max(bufcopy, key=bufcopy.get))
        bufcopy.pop(max(bufcopy, key=bufcopy.get))
    pointerlist = {}
    infolist = wee.infolist_get("buffer", "", "")
    while wee.infolist_next(infolist): # go through the buffers and jot down relevant pointers
        for name in priolist:
            try:
                bufname = wee.infolist_string(infolist, "name").split('.', 1)[1]
            except IndexError:
                bufname = wee.infolist_string(infolist, "name")
            if name == bufname:
                if name in pointerlist:
                    pointerlist[name].append(
                            wee.infolist_pointer(infolist, "pointer"))
                else:
                    pointerlist[name] = [wee.infolist_pointer(
                        infolist, "pointer")]

    index = 1
    if(maintop):
        index += 1
    for name in priolist:
        if name in pointerlist:
            for pointer in pointerlist[name]:
                wee.buffer_set(pointer, "number", str(index))
                index += 1
    return
Пример #2
0
def command_main(data, buffer, args):
  infolist = w.infolist_get("buffer", "", "")
  buffer_groups = {}
  results = []
  buffer_count = 0
  merge_count = 0
  numbers = set()
  while w.infolist_next(infolist):
    bplugin = w.infolist_string(infolist, "plugin_name")
    bname = w.infolist_string(infolist, "name")
    bpointer = w.infolist_pointer(infolist, "pointer")
    bnumber = w.infolist_integer(infolist, "number")
    btype = w.buffer_get_string(bpointer, 'localvar_type')
    if not bnumber in numbers:
      numbers.add(bnumber)
    else:
      merge_count += 1

    if btype == 'server':
      bdesc = 'servers'
    elif btype == 'channel':
      bdesc = 'channels'
    elif btype == 'private':
      bdesc = 'queries'
    else:
      bdesc = bplugin

    buffer_groups.setdefault(bdesc,[]).append({'name': bname, 'pointer': bpointer})

  w.infolist_free(infolist)

  infolist = w.infolist_get("window", "", "")
  windows_v = set()
  windows_h = set()
  windows = set()
  while w.infolist_next(infolist):
    window = w.infolist_pointer(infolist, "pointer")
    window_w = w.infolist_integer(infolist, "width_pct")
    window_h = w.infolist_integer(infolist, "height_pct")
    windows.add(window)
    if window_h == 100 and window_w != 100:
      windows_v.add(window)
    elif window_w == 100 and window_h != 100:
      windows_h.add(window)
    #else: #both 100%, thus no splits
  w.infolist_free(infolist)

  window_count = len(windows)

  for desc, buffers in buffer_groups.iteritems():
    buffer_count += len(buffers)
    results.append('%i %s' % (len(buffers), desc))

  buffer_stats = ', '.join(sorted(results, key = lambda item: (int(item.partition(' ')[0]) if item[0].isdigit() else float('inf'), item),reverse=True)) # descending numerical sort of strings
  stats_string = '%i buffers (%i merged): %s; %i windows' % (buffer_count, merge_count, buffer_stats, window_count)
  if '-split' in args:
    stats_string += ": %i vertically / %i horizontally split" % (len(windows_v), len(windows_h))
  w.command("", "/input insert %s" % stats_string)
  return w.WEECHAT_RC_OK
Пример #3
0
def get_all_buffers():
    '''Returns list with pointers of all open buffers.'''
    buffers = []
    infolist = w.infolist_get('buffer', '', '')
    while w.infolist_next(infolist):
        buffer_type = w.buffer_get_string(w.infolist_pointer(infolist, 'pointer'), 'localvar_type')
        if buffer_type == 'private': # we only close private message buffers for now
            buffers.append(w.infolist_pointer(infolist, 'pointer'))
    w.infolist_free(infolist)
    return buffers
Пример #4
0
def get_all_buffers():
    """Returns list with pointers of all open buffers."""
    buffers = []
    infolist = w.infolist_get("buffer", "", "")
    while w.infolist_next(infolist):
        buffer_type = w.buffer_get_string(w.infolist_pointer(infolist, "pointer"), "localvar_type")
        if buffer_type == "private":  # we only close private message buffers for now
            buffers.append(w.infolist_pointer(infolist, "pointer"))
    w.infolist_free(infolist)
    return buffers
Пример #5
0
def command_main(data, buffer, args):
  infolist = w.infolist_get("buffer", "", "")
  buffer_groups = {}
  results = []
  buffer_count = 0
  merge_count = 0
  numbers = set()
  while w.infolist_next(infolist):
    bplugin = w.infolist_string(infolist, "plugin_name")
    bname = w.infolist_string(infolist, "name")
    bpointer = w.infolist_pointer(infolist, "pointer")
    bnumber = w.infolist_integer(infolist, "number")
    if not bnumber in numbers:
      numbers.add(bnumber)
    else:
      merge_count += 1
    btype = bplugin
    if bplugin == 'irc':
      if  'server.' in bname:
        btype = '%s servers' % btype
      elif '#' in bname:
        btype = '%s channels' % btype
      else:
        btype = '%s queries' % btype
      
    buffer_groups.setdefault(btype,[]).append({'name': bname, 'pointer': bpointer})

  w.infolist_free(infolist)

  infolist = w.infolist_get("window", "", "")
  windows_v = set()
  windows_h = set()
  windows = set()
  while w.infolist_next(infolist):
    window = w.infolist_pointer(infolist, "pointer")
    window_w = w.infolist_integer(infolist, "width_pct")
    window_h = w.infolist_integer(infolist, "height_pct")
    windows.add(window)
    if window_h == 100 and window_w != 100:
      windows_v.add(window)
    elif window_w == 100 and window_h != 100:
      windows_h.add(window)
    #else: #both 100%, thus no splits
  w.infolist_free(infolist)
    
  window_count = len(windows)

  for bplugin, buffers in buffer_groups.iteritems():
    buffer_count += len(buffers)
    results.append('%i %s' % (len(buffers), bplugin))

  buffer_stats = ', '.join(sorted(results))
  stats_string = '%i windows used (%i vertically / %i horizontally split). %i (of which %i merged) buffers open: %s' % (window_count, len(windows_v), len(windows_h), buffer_count, merge_count, buffer_stats)
  w.command("", "/input insert %s" % stats_string)
  return w.WEECHAT_RC_OK
Пример #6
0
def allquery_command_cb(data, buffer, args):
    """ Callback for /allquery command """
    args = args.strip()
    if args == "":
        weechat.command("", "/help %s" % SCRIPT_COMMAND)
        return weechat.WEECHAT_RC_OK
    argv = args.split(" ")

    exclude_nick = None

    if argv[0].startswith("-exclude="):
        exclude_nick = make_list(argv[0])
        command = " ".join(argv[1::])
    else:
        command = args
    if not command.startswith("/"):
        weechat.command("", "/help %s" % SCRIPT_COMMAND)
        return weechat.WEECHAT_RC_OK

    infolist = weechat.infolist_get("buffer", "", "")
    while weechat.infolist_next(infolist):
        if weechat.infolist_string(infolist, "plugin_name") == "irc":
            ptr = weechat.infolist_pointer(infolist, "pointer")
            server = weechat.buffer_get_string(ptr, "localvar_server")
            query = weechat.buffer_get_string(ptr, "localvar_channel")
            execute_command = re.sub(r'\b\$nick\b', query, command)
            if weechat.buffer_get_string(ptr, "localvar_type") == "private":
                if exclude_nick is not None:
                    if not query in exclude_nick:
                        weechat.command(ptr, execute_command)
                else:
                    weechat.command(ptr, execute_command)
    weechat.infolist_free(infolist)
    return weechat.WEECHAT_RC_OK
Пример #7
0
def save_query_buffer_to_file():
    global query_buffer_list

    ptr_infolist_buffer = weechat.infolist_get("buffer", "", "")

    while weechat.infolist_next(ptr_infolist_buffer):
        ptr_buffer = weechat.infolist_pointer(ptr_infolist_buffer, "pointer")

        type = weechat.buffer_get_string(ptr_buffer, "localvar_type")
        if type == "private":
            server = weechat.buffer_get_string(ptr_buffer, "localvar_server")
            channel = weechat.buffer_get_string(ptr_buffer, "localvar_channel")
            query_buffer_list.insert(0, "%s %s" % (server, channel))

    weechat.infolist_free(ptr_infolist_buffer)

    filename = get_filename_with_path()

    if len(query_buffer_list):
        try:
            f = open(filename, "w")
            i = 0
            while i < len(query_buffer_list):
                f.write("%s\n" % query_buffer_list[i])
                i = i + 1
            f.close()
        except:
            weechat.prnt(
                "", '%s%s: Error writing query buffer to "%s"' % (weechat.prefix("error"), SCRIPT_NAME, filename)
            )
            raise
    else:  # no query buffer(s). remove file
        if os.path.isfile(filename):
            os.remove(filename)
    return
Пример #8
0
def get_matching_buffers(input):
    """ Return list with buffers matching user input """
    global buffers_pos
    list = []
    if len(input) == 0:
        buffers_pos = 0
    input = input.lower()
    infolist = weechat.infolist_get("buffer", "", "")
    while weechat.infolist_next(infolist):
        if weechat.config_get_plugin("short_name") == "on":
            name = weechat.infolist_string(infolist, "short_name")
        else:
            name = weechat.infolist_string(infolist, "name")
        number = weechat.infolist_integer(infolist, "number")
        matching = name.lower().find(input) >= 0
        if not matching and input[-1] == ' ':
            matching = name.lower().endswith(input.strip())
        if not matching and input.isdigit():
            matching = str(number).startswith(input)
        if len(input) == 0 or matching:
            list.append({"number": number, "name": name})
            if len(input) == 0 and weechat.infolist_pointer(infolist, "pointer") == weechat.current_buffer():
                buffers_pos = len(list) - 1
    weechat.infolist_free(infolist)
    return list
Пример #9
0
def hotlist_dict():
    """Return the contents of the hotlist as a dictionary.

    The returned dictionary has the following structure:
    >>> hotlist = {
    ...     "0x0": {                    # string representation of the buffer pointer
    ...         "count_low": 0,
    ...         "count_message": 0,
    ...         "count_private": 0,
    ...         "count_highlight": 0,
    ...     }
    ... }
    """
    hotlist = {}
    infolist = weechat.infolist_get("hotlist", "", "")
    while weechat.infolist_next(infolist):
        buffer_pointer = weechat.infolist_pointer(infolist, "buffer_pointer")
        hotlist[buffer_pointer] = {}
        hotlist[buffer_pointer]["count_low"] = weechat.infolist_integer(
            infolist, "count_00")
        hotlist[buffer_pointer]["count_message"] = weechat.infolist_integer(
            infolist, "count_01")
        hotlist[buffer_pointer]["count_private"] = weechat.infolist_integer(
            infolist, "count_02")
        hotlist[buffer_pointer]["count_highlight"] = weechat.infolist_integer(
            infolist, "count_03")
    weechat.infolist_free(infolist)
    return hotlist
Пример #10
0
def get_help_command(plugin, input_cmd, input_args):
    """Get help for command in input."""
    global cmdhelp_settings
    if input_cmd == 'set' and input_args:
        return get_help_option(input_args)
    infolist = weechat.infolist_get('hook', '', 'command,%s' % input_cmd)
    cmd_plugin_name = ''
    cmd_command = ''
    cmd_args = ''
    cmd_desc = ''
    while weechat.infolist_next(infolist):
        cmd_plugin_name = (weechat.infolist_string(infolist, 'plugin_name') or
                           'core')
        cmd_command = weechat.infolist_string(infolist, 'command')
        cmd_args = weechat.infolist_string(infolist, 'args_nls')
        cmd_desc = weechat.infolist_string(infolist, 'description')
        if weechat.infolist_pointer(infolist, 'plugin') == plugin:
            break
    weechat.infolist_free(infolist)
    if cmd_plugin_name == 'alias':
        return '%sAlias %s%s%s => %s%s' % (
            weechat.color(cmdhelp_settings['color_alias']),
            weechat.color(cmdhelp_settings['color_alias_name']),
            cmd_command,
            weechat.color(cmdhelp_settings['color_alias']),
            weechat.color(cmdhelp_settings['color_alias_value']),
            cmd_desc,
        )
    if input_args:
        cmd_args = get_command_arguments(input_args, cmd_args)
    if not cmd_args:
        return None
    return '%s%s' % (weechat.color(cmdhelp_settings['color_arguments']),
                     cmd_args)
Пример #11
0
def save_query_buffer_to_file():
    global query_buffer_list

    ptr_infolist_buffer = weechat.infolist_get('buffer', '', '')

    while weechat.infolist_next(ptr_infolist_buffer):
        ptr_buffer = weechat.infolist_pointer(ptr_infolist_buffer,'pointer')

        type = weechat.buffer_get_string(ptr_buffer, 'localvar_type')
        if type == 'private':
            server = weechat.buffer_get_string(ptr_buffer, 'localvar_server')
            channel = weechat.buffer_get_string(ptr_buffer, 'localvar_channel')
            query_buffer_list.insert(0,"%s %s" % (server,channel))

    weechat.infolist_free(ptr_infolist_buffer)

    filename = get_filename_with_path()

    if len(query_buffer_list):
        try:
            f = open(filename, 'w')
            i = 0
            while i < len(query_buffer_list):
                f.write('%s\n' % query_buffer_list[i])
                i = i + 1
            f.close()
        except:
            weechat.prnt('','%s%s: Error writing query buffer to "%s"' % (weechat.prefix('error'), SCRIPT_NAME, filename))
            raise
    else:       # no query buffer(s). remove file
        if os.path.isfile(filename):
            os.remove(filename)
    return
Пример #12
0
def bas_config_option_cb(data, option, value):
    if not weechat.config_boolean(bas_options["look_instant"]):
        return weechat.WEECHAT_RC_OK

    if not weechat.config_get(option):  # option was deleted
        return weechat.WEECHAT_RC_OK

    option = option[len("%s.buffer." % CONFIG_FILE_NAME):]

    pos = option.rfind(".")
    if pos > 0:
        buffer_mask = option[0:pos]
        property = option[pos+1:]
        if buffer_mask and property:
            buffers = weechat.infolist_get("buffer", "", buffer_mask)

            if not buffers:
                return weechat.WEECHAT_RC_OK

            while weechat.infolist_next(buffers):
                buffer = weechat.infolist_pointer(buffers, "pointer")
                weechat.buffer_set(buffer, property, value)

            weechat.infolist_free(buffers)

    return weechat.WEECHAT_RC_OK
Пример #13
0
    def disable_logging(self):
        """Return the previous logger level and set the buffer logger level
        to 0. If it was already 0, return None."""
        # If previous_log_level has not been previously set, return the level
        # we detect now.
        if not hasattr(self, 'previous_log_level'):
            infolist = weechat.infolist_get('logger_buffer', '', '')

            buf = self.buffer()
            previous_log_level = 0

            while weechat.infolist_next(infolist):
                if weechat.infolist_pointer(infolist, 'buffer') == buf:
                    previous_log_level = weechat.infolist_integer(
                        infolist, 'log_level')
                    if self.is_logged():
                        weechat.command(buf, '/mute logger disable')
                        self.print_buffer(
                            'Logs have been temporarily disabled for the session. They will be restored upon finishing the OTR session.')
                        break

            weechat.infolist_free(infolist)

            return previous_log_level

        # If previous_log_level was already set, it means we already altered it
        # and that we just detected an already modified logging level.
        # Return the pre-existing value so it doesn't get lost, and we can
        # restore it later.
        else:
            return self.previous_log_level
Пример #14
0
def update_title(data, signal, signal_data):
    ''' The callback that adds title. '''

    if w.config_get_plugin('short_name') == 'on':
        title = w.buffer_get_string(w.current_buffer(), 'short_name')
    else:
        title = w.buffer_get_string(w.current_buffer(), 'name')

    hotlist = w.infolist_get('hotlist', '', '')
    hot_text = ''
    while w.infolist_next(hotlist):
        priority = w.infolist_integer(hotlist, 'priority')
        if priority >= int(w.config_get_plugin('title_priority')):
            number = w.infolist_integer(hotlist, 'buffer_number')
            thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer')
            name = w.buffer_get_string(thebuffer, 'short_name')

            hot_text += ' %s' % number
    if hot_text:
        title += ' [A:%s]' % hot_text
    w.infolist_free(hotlist)

    w.window_set_title(title)

    return w.WEECHAT_RC_OK
Пример #15
0
def format_option(match):
    """Replace ${xxx} by its value in option format."""
    global cmdhelp_settings, cmdhelp_option_infolist, cmdhelp_option_infolist_fields
    string = match.group()
    end = string.find('}')
    if end < 0:
        return string
    field = string[2:end]
    color1 = ''
    color2 = ''
    pos = field.find(':')
    if pos:
        color1 = field[0:pos]
        field = field[pos+1:]
    if color1:
        color1 = weechat.color(color1)
        color2 = weechat.color(cmdhelp_settings['color_option_help'])
    fieldtype = cmdhelp_option_infolist_fields.get(field, '')
    if fieldtype == 'i':
        string = str(weechat.infolist_integer(cmdhelp_option_infolist, field))
    elif fieldtype == 's':
        string = weechat.infolist_string(cmdhelp_option_infolist, field)
    elif fieldtype == 'p':
        string = weechat.infolist_pointer(cmdhelp_option_infolist, field)
    elif fieldtype == 't':
        string = weechat.infolist_time(cmdhelp_option_infolist, field)
    return '%s%s%s' % (color1, string, color2)
Пример #16
0
def format_option(match):
    """Replace ${xxx} by its value in option format."""
    global cmdhelp_settings, cmdhelp_option_infolist
    global cmdhelp_option_infolist_fields
    string = match.group()
    end = string.find('}')
    if end < 0:
        return string
    field = string[2:end]
    color1 = ''
    color2 = ''
    pos = field.find(':')
    if pos:
        color1 = field[0:pos]
        field = field[pos+1:]
    if color1:
        color1 = weechat.color(color1)
        color2 = weechat.color(cmdhelp_settings['color_option_help'])
    fieldtype = cmdhelp_option_infolist_fields.get(field, '')
    if fieldtype == 'i':
        string = str(weechat.infolist_integer(cmdhelp_option_infolist, field))
    elif fieldtype == 's':
        string = weechat.infolist_string(cmdhelp_option_infolist, field)
    elif fieldtype == 'p':
        string = weechat.infolist_pointer(cmdhelp_option_infolist, field)
    elif fieldtype == 't':
        date = weechat.infolist_time(cmdhelp_option_infolist, field)
        # since WeeChat 2.2, infolist_time returns a long integer instead of
        # a string
        if not isinstance(date, str):
            date = time.strftime('%F %T', time.localtime(int(date)))
        string = date
    return '%s%s%s' % (color1, string, color2)
Пример #17
0
def check_buffer_timer_cb(data, remaining_calls):
    global WEECHAT_VERSION,whitelist

    # search for buffers in hotlist
    ptr_infolist = weechat.infolist_get("hotlist", "", "")
    while weechat.infolist_next(ptr_infolist):
        ptr_buffer = weechat.infolist_pointer(ptr_infolist, "buffer_pointer")
        localvar_name = weechat.buffer_get_string(ptr_buffer, 'localvar_name')
        # buffer in whitelist? go to next buffer
        buf_type = weechat.buffer_get_string(ptr_buffer,'localvar_type')
        # buffer is a query buffer?
        if OPTIONS['ignore_query'].lower() == 'on' and buf_type == 'private':
            continue
        # buffer in whitelist?
        if localvar_name in whitelist:
            continue
        if ptr_buffer:
            if get_time_from_line(ptr_buffer):
                if OPTIONS['clear'].lower() == 'hotlist' or OPTIONS['clear'].lower() == 'all':
                    weechat.buffer_set(ptr_buffer, "hotlist", '-1')
                if OPTIONS['clear'].lower() == 'unread' or OPTIONS['clear'].lower() == 'all':
                    weechat.command(ptr_buffer,"/input set_unread_current_buffer")

    weechat.infolist_free(ptr_infolist)
    return weechat.WEECHAT_RC_OK
Пример #18
0
def save_history():
    global history_list
    # get buffers
    ptr_infolist_buffer = weechat.infolist_get('buffer','','')

    while weechat.infolist_next(ptr_infolist_buffer):
        ptr_buffer = weechat.infolist_pointer(ptr_infolist_buffer,'pointer')

        # check for localvar_save_history
        if not weechat.buffer_get_string(ptr_buffer, 'localvar_save_history') and OPTIONS['save_buffer'].lower() == 'off':
            continue

        plugin = weechat.buffer_get_string(ptr_buffer, 'localvar_plugin')
        name = weechat.buffer_get_string(ptr_buffer, 'localvar_name')
        filename = get_filename_with_path('%s.%s' % (plugin,name))

        get_buffer_history(ptr_buffer)
        if len(history_list):
            write_history(filename)

    weechat.infolist_free(ptr_infolist_buffer)

    if OPTIONS['save_global'].lower() != 'off':
        get_buffer_history('')  # buffer pointer (if not set, return global history) 
        if len(history_list):
            write_history(filename_global_history)
Пример #19
0
def get_matching_buffers(input):
    """ Return list with buffers matching user input """
    global buffers_pos
    list = []
    if len(input) == 0:
        buffers_pos = 0
    input = input.lower()
    infolist = weechat.infolist_get("buffer", "", "")
    while weechat.infolist_next(infolist):
        if weechat.config_get_plugin("short_name") == "on":
            name = weechat.infolist_string(infolist, "short_name")
        else:
            name = weechat.infolist_string(infolist, "name")
        if weechat.config_get_plugin("use_core_instead_weechat") == "on" and name == "weechat":
            name = "core"
        number = weechat.infolist_integer(infolist, "number")
        full_name = weechat.infolist_string(infolist, "full_name")
        if not full_name:
            full_name = "%s.%s" % (weechat.infolist_string(infolist, "plugin_name"),
                                   weechat.infolist_string(infolist, "name"))
        pointer = weechat.infolist_pointer(infolist, "pointer")
        matching = name.lower().find(input) >= 0
        if not matching and input[-1] == ' ':
            matching = name.lower().endswith(input.strip())
        if not matching and input.isdigit():
            matching = str(number).startswith(input)
        if len(input) == 0 or matching:
            list.append({"number": number, "name": name, "full_name": full_name, "pointer": pointer})
            if len(input) == 0 and pointer == weechat.current_buffer():
                buffers_pos = len(list) - 1
    weechat.infolist_free(infolist)
    if not weechat.config_string_to_boolean(weechat.config_get_plugin('sort_by_activity')):
        return list
    # sort buffers like in hotlist.
    hotlist = []
    infolist = weechat.infolist_get("hotlist", "", "")
    while weechat.infolist_next(infolist):
        hotlist.append(weechat.infolist_pointer(infolist, "buffer_pointer"))
    weechat.infolist_free(infolist)
    last_index = len(hotlist)
    def priority(b):
        try:
            return hotlist.index(b["pointer"])
        except ValueError:
            # not in hotlist, always last.
            return last_index
    return sorted(list, key=priority)
Пример #20
0
def cb_command_apply(data, buf, list_args):
    """Apply the rules the all existing buffers; useful when testing a new rule."""
    infolist = weechat.infolist_get("buffer", "", "")
    while weechat.infolist_next(infolist):
        buf2 = weechat.infolist_pointer(infolist, "pointer")
        cb_signal_apply_rules(data, None, buf2)
    weechat.infolist_free(infolist)
    return weechat.WEECHAT_RC_OK
Пример #21
0
def get_all_buffers():
	"""Returns list with pointers of all open buffers."""
	buffers = []
	infolist = weechat.infolist_get('buffer', '', '')
	while weechat.infolist_next(infolist):
		buffers.append(weechat.infolist_pointer(infolist, 'pointer'))
	weechat.infolist_free(infolist)
	return buffers
Пример #22
0
def infolist_get_first_entry_from_hotlist():
    infolist = weechat.infolist_get('hotlist', '', '')
    if infolist:
        weechat.infolist_next(infolist)         # go to first entry in hotlist
        buffer_name = weechat.infolist_string(infolist, 'buffer_name')
        buffer_number = weechat.infolist_integer(infolist, 'buffer_number')
        ptr_buffer = weechat.infolist_pointer(infolist, 'buffer_pointer')
        weechat.infolist_free(infolist)
    return buffer_name, ptr_buffer, buffer_number
Пример #23
0
def chanact_cb(*args):
    ''' Callback ran on hotlist changes '''
    global keydict

    hotlist = w.infolist_get('hotlist', '', '')

    activity = []
    while w.infolist_next(hotlist):
        priority = w.infolist_integer(hotlist, 'priority')

        if priority < int(w.config_get_plugin('lowest_priority')):
            continue

        int_number = w.infolist_integer(hotlist, 'buffer_number')
        number = str(int_number)
        thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer')
        name = w.buffer_get_string(thebuffer, 'short_name')

        color = w.config_get_plugin('color_default')
        if priority > 0:
            color = w.config_get_plugin('color_%s' %priority)

        if number in keydict:
            number = keydict[number]
            entry = '%s%s%s' % (w.color(color), number, w.color('reset'))
        elif name in keydict:
            name = keydict[name]
            entry = '%s%s%s' % (w.color(color), name, w.color('reset'))
        elif name:
            entry = '%s%s%s:%s%s%s' % (
                    w.color('default'),
                    number,
                    w.color('reset'),
                    w.color(color),
                    name[:int(w.config_get_plugin('item_length'))],
                    w.color('reset'))
        else:
            entry = '%s%s%s' % (
                    w.color(color),
                    number,
                    w.color(reset))

        activity.append((entry, thebuffer, sort_rank(thebuffer, priority), int_number))

    if w.config_get_plugin('sort_by_number') == "on":
        activity.sort(key=lambda t: int(t[3]))
    else:
        activity.sort(key=lambda t: int(t[2]), reverse=True)

    w.infolist_free(hotlist)
    if activity:
        message = w.config_get_plugin('message')
        delim = w.config_get_plugin('delimiter')
        return message + delim.join(a[0] for a in activity)
    else:
        return ''
Пример #24
0
def hotlist():
    hotlist_items = []
    hotlist = weechat.infolist_get("hotlist", "", "")
    while weechat.infolist_next(hotlist):
        buffer_number = weechat.infolist_integer(hotlist, "buffer_number")
        buffer = weechat.infolist_pointer(hotlist, "buffer_pointer")
        short_name = weechat.buffer_get_string(buffer, "short_name")
        hotlist_items.append("%s:%s" % (buffer_number, short_name))
    weechat.infolist_free(hotlist)
    return ",".join(hotlist_items)
Пример #25
0
def check_hotlist(check_pointer):
    ptr_buffer = 0
    infolist = weechat.infolist_get('hotlist', '', '')
    while weechat.infolist_next(infolist):
        pointer = weechat.infolist_pointer(infolist, 'buffer_pointer')
        if pointer == check_pointer:
            ptr_buffer = pointer
            break
    weechat.infolist_free(infolist)
    return ptr_buffer
Пример #26
0
def infolist_get_buffer_name_and_ptr_by_name(str_buffer_name):
    infolist = weechat.infolist_get('buffer', '', '*%s*' % str_buffer_name)
    full_name = ''
    ptr_buffer = ''
    if infolist:
        while weechat.infolist_next(infolist):
            full_name = weechat.infolist_string(infolist, 'full_name')
            ptr_buffer = weechat.infolist_pointer(infolist, 'pointer')
            break
        weechat.infolist_free(infolist)
    return full_name, ptr_buffer
Пример #27
0
def infolist_get_buffer_name_and_ptr(str_buffer_number):
    infolist = weechat.infolist_get('buffer', '', '')
    full_name = ''
    ptr_buffer = ''
    if infolist:
        while weechat.infolist_next(infolist):
            if int(str_buffer_number) == weechat.infolist_integer(infolist, 'number'):
                full_name = weechat.infolist_string(infolist, 'full_name')
                ptr_buffer = weechat.infolist_pointer(infolist, 'pointer')
                break
    weechat.infolist_free(infolist)
    return full_name, ptr_buffer
Пример #28
0
def set_away(message, overridable_messages=[]):
    """Sets away status, but respectfully
    (so it doesn't change already set statuses"""
    if (weechat.config_get_plugin('away') == '1'):
        return  # No need to go away again
                # (this prevents some repeated messages)
    serverlist = weechat.infolist_get('irc_server', '', '')
    if serverlist:
        buffers = []
        while weechat.infolist_next(serverlist):
            if weechat.infolist_integer(serverlist, 'is_away') == 0:
                ptr = weechat.infolist_pointer(serverlist, 'buffer')
                if ptr:
                    buffers.append(ptr)
            elif (weechat.infolist_string(serverlist, 'away_message')
                    in overridable_messages):
                buffers.append(weechat.infolist_pointer(serverlist, 'buffer'))
        weechat.infolist_free(serverlist)
        for buffer in buffers:
            weechat.command(buffer, "/away %s" % message)
    weechat.config_set_plugin('away', '1')
Пример #29
0
def irc_servers():
    ''' Disconnected IRC servers, workaround for /away -all bug 
    in v. < 0.3.2 '''
    serverlist = w.infolist_get('irc_server','','')
    buffers = []
    if serverlist:
        while w.infolist_next(serverlist):
            if w.infolist_integer(serverlist, 'is_connected') == 0:
                buffers.append((w.infolist_pointer(serverlist,
                               'buffer')))
        w.infolist_free(serverlist)
    return buffers
Пример #30
0
def get_logfile():
    logfilename = ""
    current_buffer = weechat.current_buffer()
    infolist = weechat.infolist_get('logger_buffer','','')
    while weechat.infolist_next(infolist):
        bpointer = weechat.infolist_pointer(infolist, 'buffer')
        if current_buffer == bpointer:
            logfilename = weechat.infolist_string(infolist, 'log_filename')
            log_enabled = weechat.infolist_integer(infolist, 'log_enabled')
            log_level = weechat.infolist_integer(infolist, 'log_level')
    weechat.infolist_free(infolist)                  # free infolist()
    return logfilename
Пример #31
0
def get_servers():
    '''Get the servers that are not away, or were set away by this script'''

    infolist = w.infolist_get('irc_server', '', '')
    buffers = []
    while w.infolist_next(infolist):
        if not w.infolist_integer(infolist, 'is_connected') == 1:
            continue
        if not w.infolist_integer(infolist, 'is_away') or \
               w.infolist_string(infolist, 'away_message') == \
               w.config_get_plugin('message'):
            buffers.append((w.infolist_pointer(infolist, 'buffer'),
                            w.infolist_string(infolist, 'nick')))
    w.infolist_free(infolist)
    return buffers
Пример #32
0
def check_nicks(data, remaining_calls):
    serverlist = OPTIONS['serverlist'].split(',')
    infolist = weechat.infolist_get('irc_server', '', '')

    while weechat.infolist_next(infolist):
        servername = weechat.infolist_string(infolist, 'name')
        ptr_buffer = weechat.infolist_pointer(infolist, 'buffer')
        nick = weechat.infolist_string(infolist, 'nick')
        ssl_connected = weechat.infolist_integer(infolist, 'ssl_connected')
        is_connected = weechat.infolist_integer(infolist, 'is_connected')
        if servername in serverlist:
            if nick and ssl_connected + is_connected:
                ison(ptr_buffer, servername, nick, server_nicks(servername))
    weechat.infolist_free(infolist)
    return weechat.WEECHAT_RC_OK
Пример #33
0
    def get_log_level(self):
        """Return the current logging level for this context's peer."""
        infolist = weechat.infolist_get('logger_buffer', '', '')

        buf = self.buffer()

        result = 0

        while weechat.infolist_next(infolist):
            if weechat.infolist_pointer(infolist, 'buffer') == buf:
                result = weechat.infolist_integer(infolist, 'log_level')
                break

        weechat.infolist_free(infolist)

        return result
Пример #34
0
def test_infolist():
    """Test infolist functions."""
    hook_infolist = weechat.hook_infolist('infolist_test_script',
                                          'description', '', '',
                                          'infolist_cb', '')
    check(weechat.infolist_get('infolist_does_not_exist', '', '') == '')
    ptr_infolist = weechat.infolist_get('infolist_test_script', '', '')
    check(ptr_infolist != '')
    check(weechat.infolist_next(ptr_infolist) == 1)
    check(weechat.infolist_integer(ptr_infolist, 'integer') == 123)
    check(weechat.infolist_string(ptr_infolist, 'string') == 'test string')
    check(weechat.infolist_pointer(ptr_infolist, 'pointer') == '0xabcdef')
    check(weechat.infolist_time(ptr_infolist, 'time') == 1231231230)
    check(weechat.infolist_fields(ptr_infolist) == 'i:integer,s:string,p:pointer,t:time')
    check(weechat.infolist_next(ptr_infolist) == 0)
    weechat.infolist_free(ptr_infolist)
    weechat.unhook(hook_infolist)
Пример #35
0
def get_current_query_buffers():
    stored_query_buffers_per_server = {}

    ptr_infolist_buffer = weechat.infolist_get('buffer', '', '')
    while weechat.infolist_next(ptr_infolist_buffer):
        ptr_buffer = weechat.infolist_pointer(ptr_infolist_buffer,'pointer')

        buf_type = weechat.buffer_get_string(ptr_buffer, 'localvar_type')
        if buf_type == 'private':
            server_name = weechat.buffer_get_string(ptr_buffer, 'localvar_server')
            channel_name = weechat.buffer_get_string(ptr_buffer, 'localvar_channel')

            stored_query_buffers_per_server.setdefault(server_name, set([]))
            stored_query_buffers_per_server[server_name].add(channel_name)
    weechat.infolist_free(ptr_infolist_buffer)

    return stored_query_buffers_per_server
Пример #36
0
def chanact_cb(*args):
    ''' Callback ran on hotlist changes '''
    global keydict

    hotlist = w.infolist_get('hotlist', '', '')

    activity = []
    while w.infolist_next(hotlist):
        priority = w.infolist_integer(hotlist, 'priority')

        if priority < int(w.config_get_plugin('lowest_priority')):
            continue

        number = str(w.infolist_integer(hotlist, 'buffer_number'))
        thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer')
        name = w.buffer_get_string(thebuffer, 'short_name')

        color = w.config_get_plugin('color_default')
        if priority > 0:
            color = w.config_get_plugin('color_%s' % priority)

        if number in keydict:
            number = keydict[number]
            entry = '%s%s%s' % (w.color(color), number, w.color('reset'))
        elif name in keydict:
            name = keydict[name]
            entry = '%s%s%s' % (w.color(color), name, w.color('reset'))
        elif name:
            entry = '%s%s%s:%s%s%s' % (
                w.color('default'), number, w.color('reset'),
                w.color(color), name[:int(w.config_get_plugin('item_length'))],
                w.color('reset'))
        else:
            entry = '%s%s%s' % (w.color(color), number, w.color(reset))

        activity.append((entry, thebuffer))

    activity.sort(key=lambda t: sort_rank(t[1]), reverse=True)

    w.infolist_free(hotlist)
    if activity:
        message = w.config_get_plugin('message')
        delim = w.config_get_plugin('delimiter')
        return message + delim.join(a[0] for a in activity)
    else:
        return ''
Пример #37
0
def get_servers():
    '''Get the servers that are not away, or were set away by this script.'''
    ignores = w.config_get_plugin('ignore').split(',')
    infolist = w.infolist_get('irc_server', '', '')
    buffers = []
    while w.infolist_next(infolist):
        if (not w.infolist_integer(infolist, 'is_connected') == 1
                or w.infolist_string(infolist, 'name') in ignores):
            continue
        if (not w.config_string_to_boolean(w.config_get_plugin('set_away'))
                or not w.infolist_integer(infolist, 'is_away')
                or w.config_get_plugin('message') in w.infolist_string(
                    infolist, 'away_message')):
            buffers.append((w.infolist_pointer(infolist, 'buffer'),
                            w.infolist_string(infolist, 'nick')))
    w.infolist_free(infolist)
    return buffers
Пример #38
0
def update_title(data, signal, signal_data):
    title = w.buffer_get_string(w.current_buffer(), 'name')
    num = w.buffer_get_integer(w.current_buffer(), 'number')
    title = w.string_remove_color(title, '')
    title = "[WeeChat] [" + str(num) + ":" + title + "]"
    hotlist = w.infolist_get('hotlist', '', '')
    while w.infolist_next(hotlist):
        number = w.infolist_integer(hotlist, 'buffer_number')
        thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer')
        name = w.buffer_get_string(thebuffer, 'short_name')
        if not number == num:
            title += ' (%s:%s)' % (number, name)
    w.infolist_free(hotlist)

    w.window_set_title(title)

    return w.WEECHAT_RC_OK
Пример #39
0
def get_file_by_buffer(buffer):
    """Given buffer pointer, finds log's path or returns None."""
    #debug('get_file_by_buffer: searching for %s' %buffer)
    file = None
    log_enabled = False
    infolist = weechat.infolist_get('logger_buffer', '', '')
    while weechat.infolist_next(infolist):
        pointer = weechat.infolist_pointer(infolist, 'buffer')
        if pointer == buffer:
            file = weechat.infolist_string(infolist, 'log_filename')
            log_enabled = weechat.infolist_integer(infolist, 'log_enabled')
            break
    weechat.infolist_free(infolist)
    #debug('get_file_by_buffer: log_enabled: %s got: %s' %(log_enabled, file))
    if not log_enabled:
        return None
    return file
Пример #40
0
def set_back(overridable_messages):
    '''Removes away status for servers where one of the overridable_messages is set'''
    if (w.config_get_plugin('away') == '0'):
        return  # No need to come back again
    serverlist = w.infolist_get('irc_server', '', '')
    if serverlist:
        buffers = []
        while w.infolist_next(serverlist):
            if w.infolist_string(serverlist,
                                 'away_message') in overridable_messages:
                ptr = w.infolist_pointer(serverlist, 'buffer')
                if ptr:
                    buffers.append(ptr)
        w.infolist_free(serverlist)
        for buffer in buffers:
            w.command(buffer, "/away")
    w.config_set_plugin('away', '0')
Пример #41
0
    def is_logged(self):
        """Return True if conversations with this context's peer are currently
        being logged to disk."""
        infolist = weechat.infolist_get('logger_buffer', '', '')

        buf = self.buffer()

        result = False

        while weechat.infolist_next(infolist):
            if weechat.infolist_pointer(infolist, 'buffer') == buf:
                result = bool(weechat.infolist_integer(infolist,
                                                       'log_enabled'))
                break

        weechat.infolist_free(infolist)

        return result
Пример #42
0
    def get_fit_size(self):
        widths = []
        heights = []

        infolist = weechat.infolist_get("window", "", "")
        while weechat.infolist_next(infolist):
            buffer = weechat.infolist_pointer(infolist, "buffer")
            if buffer == self.buffer:
                width = weechat.infolist_integer(infolist, "chat_width")
                height = weechat.infolist_integer(infolist, "chat_height")

                widths.append(width)
                heights.append(height)
        weechat.infolist_free(infolist)

        if widths and heights:
            return (min(heights), min(widths))
        else:
            return None
Пример #43
0
def populate_nicks(*args):
    global colored_nicks
    colored_nicks = {}
    buffers = weechat.infolist_get('buffer', '', '')
    while weechat.infolist_next(buffers):
        buffer_ptr = weechat.infolist_pointer(buffers, 'pointer')
        my_nick = weechat.buffer_get_string(buffer_ptr, 'localvar_nick')
        nicklist = weechat.infolist_get('nicklist', buffer_ptr, '')
        while weechat.infolist_next(nicklist):
            if buffer_ptr not in colored_nicks:
                colored_nicks[buffer_ptr] = {}
            if weechat.infolist_string(nicklist, 'type') != 'nick':
                continue
            nick = weechat.infolist_string(nicklist, 'name')
            nick_color = colorize_nick_color(nick, my_nick)
            colored_nicks[buffer_ptr][nick] = nick_color
        weechat.infolist_free(nicklist)
    weechat.infolist_free(buffers)
    return weechat.WEECHAT_RC_OK
Пример #44
0
def hotlist_changed(data, signal, signal_data):
    hotlist = weechat.infolist_get('hotlist', '', '')

    data = []

    while weechat.infolist_next(hotlist):
        priority = weechat.infolist_integer(hotlist, 'priority')

        plugin_name = weechat.infolist_string(hotlist, 'plugin_name')
        buffer_name = weechat.infolist_string(hotlist, 'buffer_name')

        buffer_number = weechat.infolist_integer(hotlist, 'buffer_number')
        low_messages = weechat.infolist_integer(hotlist, 'count_00')
        channel_messages = weechat.infolist_integer(hotlist, 'count_01')
        private_messages = weechat.infolist_integer(hotlist, 'count_02')
        highlight_messages = weechat.infolist_integer(hotlist, 'count_03')

        buffer_pointer = weechat.infolist_pointer(hotlist, 'buffer_pointer')
        short_name = weechat.buffer_get_string(buffer_pointer, 'short_name')

        data.append({
            'priority': priority,
            'plugin_name': plugin_name,
            'buffer_name': buffer_name,
            'buffer_number': buffer_number,
            'low_messages': low_messages,
            'channel_messages': channel_messages,
            'private_messages': private_messages,
            'highlight_messages': highlight_messages,
            0: low_messages,
            1: channel_messages,
            2: private_messages,
            3: highlight_messages,
            'short_name': short_name
        })

    weechat.infolist_free(hotlist)

    write_file({'hotlist': data})

    return weechat.WEECHAT_RC_OK
Пример #45
0
def idle_check(data, remain):
    try:
        timeout = int(w.config_get_plugin("timeout"))
    except ValueError:
        timeout = 0
    message = w.config_get_plugin("message")

    inactivity = int(w.info_get("inactivity", "0")) / 60
    last_action = (time.monotonic() - LAST_ACTION) / 60
    inactivity = min(inactivity, last_action)

    if timeout > 0 and inactivity >= timeout:
        servers = w.infolist_get("irc_server", "", "")
        while w.infolist_next(servers):
            if (w.infolist_integer(servers, "is_connected") == 1
                    and w.infolist_integer(servers, "is_away") == 0):
                ptr = w.infolist_pointer(servers, "buffer")
                w.command(ptr, f"/away {message}")
        w.infolist_free(servers)

    return w.WEECHAT_RC_OK
Пример #46
0
def update_title(data, signal, signal_data):
    ''' The callback that adds title. '''

    if w.config_get_plugin('short_name') == 'on':
        title = w.buffer_get_string(w.current_buffer(), 'short_name')
    else:
        title = w.buffer_get_string(w.current_buffer(), 'name')

    hotlist = w.infolist_get('hotlist', '', '')
    while w.infolist_next(hotlist):
        priority = w.infolist_integer(hotlist, 'priority')
        if priority >= int(w.config_get_plugin('title_priority')):
            number = w.infolist_integer(hotlist, 'buffer_number')
            thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer')
            name = w.buffer_get_string(thebuffer, 'short_name')

            title += ' %s:%s' % (number, name)
    w.infolist_free(hotlist)

    w.window_set_title(title)

    return w.WEECHAT_RC_OK
Пример #47
0
def update_title(data, signal, signal_data):
    ''' The callback that adds title. '''

    # prefix
    title = w.config_get_plugin('title_prefix')

    # current buffer
    title += w.config_get_plugin('current_buffer_prefix')
    if w.config_get_plugin('short_name') == 'on':
        title += w.buffer_get_string(w.current_buffer(), 'short_name')
    else:
        title += w.buffer_get_string(w.current_buffer(), 'name')
    title += w.config_get_plugin('current_buffer_suffix')

    if w.config_get_plugin('show_hotlist') == 'on':
        # hotlist buffers
        hotlist = w.infolist_get('hotlist', '', '')
        pnumber = w.config_get_plugin('hotlist_number_prefix')
        snumber = w.config_get_plugin('hotlist_number_suffix')
        pname = w.config_get_plugin('hotlist_buffer_prefix')
        sname = w.config_get_plugin('hotlist_buffer_suffix')
        separator = w.config_get_plugin('hotlist_separator')
        while w.infolist_next(hotlist):
            priority = w.infolist_integer(hotlist, 'priority')
            if priority >= int(w.config_get_plugin('title_priority')):
                number = w.infolist_integer(hotlist, 'buffer_number')
                thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer')
                name = w.buffer_get_string(thebuffer, 'short_name')
                title += ' {0}{1}{2}{3}{4}{5}{6}'.format(pnumber, \
                    number, snumber, separator, pname, name, sname)
        w.infolist_free(hotlist)

    # suffix
    title += w.config_get_plugin('title_suffix')

    title = w.string_remove_color(title, '')
    w.window_set_title(title)

    return w.WEECHAT_RC_OK
Пример #48
0
def find_merge_id(buf, merge):
    """Find the id of the buffer to merge to."""
    mid = -1
    if merge.isdigit():
        mid = merge
    elif merge == "server":
        server = weechat.buffer_get_string(buf, 'localvar_server')
        infolist = weechat.infolist_get("buffer", "", "")
        while weechat.infolist_next(infolist) and mid < 0:
            if weechat.infolist_string(infolist, "plugin_name") == "irc":
                buf2 = weechat.infolist_pointer(infolist, "pointer")
                server2 = weechat.buffer_get_string(buf2, 'localvar_server')
                if server == server2:
                    mid = weechat.infolist_integer(infolist, 'number')
        weechat.infolist_free(infolist)
    else:
        infolist = weechat.infolist_get("buffer", "", "")
        prog = re.compile(merge)
        while weechat.infolist_next(infolist) and mid < 0:
            if prog.match(weechat.infolist_string(infolist, "full_name")):
                mid = weechat.infolist_integer(infolist, 'number')
        weechat.infolist_free(infolist)
    return mid
Пример #49
0
def timer_cb(data, remaining_calls):
    global indent
    current_time = int(time.time())
    interval = int(weechat.config_get_plugin('modulo_interval')) * 60
    if (current_time % interval) == 0:
        infolist = weechat.infolist_get("buffer", "", "")
        if infolist:
            # set static width, assumes balanced window widths
            if indent < 0:
                if weechat.config_get_plugin('center') == '0':
                    indent = 0
                else:
                    # centering = (window width - prefix width - (vertical separator + date)) / 2 - rounding adjustment
                    indent = (weechat.window_get_integer(
                        weechat.current_window(), "win_width") - int(
                            weechat.string_eval_expression(
                                "${weechat.look.prefix_align_min}", {}, {},
                                {})) - 14) / 2 - 1
            while weechat.infolist_next(infolist):
                buffer = weechat.infolist_pointer(infolist, 'pointer')
                prnt_timestamp(buffer, current_time, indent)
            weechat.infolist_free(infolist)
    return weechat.WEECHAT_RC_OK
Пример #50
0
def hotlist():
    hotlist = weechat.infolist_get("hotlist", "", "")
    while weechat.infolist_next(hotlist):
        yield weechat.infolist_pointer(hotlist, 'buffer_pointer')
    weechat.infolist_free(hotlist)
Пример #51
0
def command_main(data, buffer, args):
    infolist = w.infolist_get("buffer", "", "")
    buffer_groups = {}
    results = []
    buffer_count = 0
    merge_count = 0
    numbers = set()
    while w.infolist_next(infolist):
        bplugin = w.infolist_string(infolist, "plugin_name")
        bname = w.infolist_string(infolist, "name")
        bpointer = w.infolist_pointer(infolist, "pointer")
        bnumber = w.infolist_integer(infolist, "number")
        btype = w.buffer_get_string(bpointer, 'localvar_type')
        if not bnumber in numbers:
            numbers.add(bnumber)
        else:
            merge_count += 1

        if btype == 'server':
            bdesc = 'servers'
        elif btype == 'channel':
            bdesc = 'channels'
        elif btype == 'private':
            bdesc = 'queries'
        else:
            bdesc = bplugin

        buffer_groups.setdefault(bdesc, []).append({
            'name': bname,
            'pointer': bpointer
        })

    w.infolist_free(infolist)

    infolist = w.infolist_get("window", "", "")
    windows_v = set()
    windows_h = set()
    windows = set()
    while w.infolist_next(infolist):
        window = w.infolist_pointer(infolist, "pointer")
        window_w = w.infolist_integer(infolist, "width_pct")
        window_h = w.infolist_integer(infolist, "height_pct")
        windows.add(window)
        if window_h == 100 and window_w != 100:
            windows_v.add(window)
        elif window_w == 100 and window_h != 100:
            windows_h.add(window)
        #else: #both 100%, thus no splits
    w.infolist_free(infolist)

    window_count = len(windows)

    for desc, buffers in buffer_groups.items():
        buffer_count += len(buffers)
        results.append('%i %s' % (len(buffers), desc))

    buffer_stats = ', '.join(
        sorted(results,
               key=lambda item: (int(item.partition(' ')[0])
                                 if item[0].isdigit() else float('inf'), item),
               reverse=True))  # descending numerical sort of strings
    stats_string = '%i buffers (%i merged): %s; %i windows' % (
        buffer_count, merge_count, buffer_stats, window_count)
    if '-split' in args:
        stats_string += ": %i vertically / %i horizontally split" % (
            len(windows_v), len(windows_h))
    w.command("", "/input insert %s" % stats_string)
    return w.WEECHAT_RC_OK
Пример #52
0
def infolist_display(buffer, args):
    global infolist_var_type

    items = args.split(" ", 1)
    infolist_args = ""
    infolist_pointer = ""
    if len(items) >= 2:
        infolist_args = items[1]
        if infolist_args[:2] == "0x":
            infolist_pointer, sep, infolist_args = infolist_args.partition(" ")
        elif infolist_args[:3] == "\"\" ":
            infolist_args = infolist_args[3:]

    infolist = weechat.infolist_get(items[0], infolist_pointer, infolist_args)
    if infolist == "":
        weechat.prnt_date_tags(
            buffer, 0, "no_filter",
            "%sInfolist '%s' not found." % (weechat.prefix("error"), items[0]))
        return weechat.WEECHAT_RC_OK

    item_count = 0
    weechat.buffer_clear(buffer)
    weechat.prnt_date_tags(
        buffer, 0, "no_filter",
        "Infolist '%s', with pointer '%s' and arguments '%s':" %
        (items[0], infolist_pointer, infolist_args))
    weechat.prnt(buffer, "")
    count = 0
    while weechat.infolist_next(infolist):
        item_count += 1
        if item_count > 1:
            weechat.prnt(buffer, "")

        fields = weechat.infolist_fields(infolist).split(",")
        prefix = "%s[%s%d%s]\t" % (weechat.color("chat_delimiters"),
                                   weechat.color("chat_buffer"), item_count,
                                   weechat.color("chat_delimiters"))
        for field in fields:
            (type, name) = field.split(":", 1)
            value = ""
            quote = ""
            if type == "i":
                value = weechat.infolist_integer(infolist, name)
            elif type == "s":
                value = weechat.infolist_string(infolist, name)
                quote = "'"
            elif type == "p":
                value = weechat.infolist_pointer(infolist, name)
            elif type == "t":
                value = weechat.infolist_time(infolist, name)
                # since WeeChat 2.2, infolist_time returns a long integer
                # instead of a string
                if not isinstance(value, str):
                    str_date = time.strftime('%F %T',
                                             time.localtime(int(value)))
                    value = '%d (%s)' % (value, str_date)
            name_end = "." * (30 - len(name))
            weechat.prnt_date_tags(
                buffer, 0, "no_filter", "%s%s%s: %s%s%s %s%s%s%s%s%s" %
                (prefix, name, name_end, weechat.color("brown"),
                 infolist_var_type[type], weechat.color("chat"),
                 weechat.color("chat"), quote, weechat.color("cyan"), value,
                 weechat.color("chat"), quote))
            prefix = ""
            count += 1
    if count == 0:
        weechat.prnt_date_tags(buffer, 0, "no_filter", "Empty infolist.")
    weechat.infolist_free(infolist)
    return weechat.WEECHAT_RC_OK
Пример #53
0
 def get_pointer(self, name):
     "Get a pointer from an InfoList"
     self.assert_open()
     return infolist_pointer(self._infolist, name)
Пример #54
0
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                        SCRIPT_LICENSE, SCRIPT_DESC, '', ''):
        # initialize
        owl_config_set()
        optimize_configs()

        # register hooks
        weechat.hook_hsignal('irc_redirection_owl_userhost', 'owl_userhost_cb',
                             '')
        weechat.hook_signal('buffer_switch', 'owl_buff_switch', '')
        weechat.hook_signal('nicklist_nick_added', 'owl_nick_added', '')
        weechat.hook_signal('nicklist_nick_changed', 'owl_nick_changed', '')
        weechat.hook_signal('nicklist_nick_removed', 'owl_nick_removed', '')
        weechat.hook_config('plugins.var.python.owl.*', 'owl_config_update',
                            '')

        # check every buffer at start up
        ilb = weechat.infolist_get('buffer', '', '')
        while weechat.infolist_next(ilb):
            buff_ptr = weechat.infolist_pointer(ilb, 'pointer')
            owl_init(buff_ptr)
        weechat.infolist_free(ilb)

        # add command
        weechat.hook_command(
            SCRIPT_COMMAND, SCRIPT_DESC,
            '[list] | [enable|disable [server.channel|channel]]',
            SCRIPT_ARGS_DESC, 'list'
            ' || enable %(filters_names)'
            ' || disable %(filters_names)', 'owl_cmd', '')
Пример #55
0
def buffers():
    buffers = weechat.infolist_get("buffer", "", "")
    while weechat.infolist_next(buffers):
        yield weechat.infolist_pointer(buffers, 'pointer')
    weechat.infolist_free(buffers)
Пример #56
0
def go_matching_buffers(strinput):
    """Return a list with buffers matching user input."""
    global buffers_pos
    listbuf = []
    if len(strinput) == 0:
        buffers_pos = 0
    strinput = strinput.lower()
    infolist = weechat.infolist_get('buffer', '', '')
    while weechat.infolist_next(infolist):
        short_name = weechat.infolist_string(infolist, 'short_name')
        if go_option_enabled('short_name'):
            name = weechat.infolist_string(infolist, 'short_name')
        else:
            name = weechat.infolist_string(infolist, 'name')
        if name == 'weechat' \
                and go_option_enabled('use_core_instead_weechat') \
                and weechat.infolist_string(infolist, 'plugin_name') == 'core':
            name = 'core'
        number = weechat.infolist_integer(infolist, 'number')
        full_name = weechat.infolist_string(infolist, 'full_name')
        if not full_name:
            full_name = '%s.%s' % (weechat.infolist_string(
                infolist,
                'plugin_name'), weechat.infolist_string(infolist, 'name'))
        pointer = weechat.infolist_pointer(infolist, 'pointer')
        matching = name.lower().find(strinput) >= 0
        if not matching and strinput[-1] == ' ':
            matching = name.lower().endswith(strinput.strip())
        if not matching and go_option_enabled('fuzzy_search'):
            matching = go_match_fuzzy(name.lower(), strinput)
        if not matching and strinput.isdigit():
            matching = str(number).startswith(strinput)
        if len(strinput) == 0 or matching:
            listbuf.append({
                'number': number,
                'short_name': short_name,
                'name': name,
                'full_name': full_name,
                'pointer': pointer,
            })
    weechat.infolist_free(infolist)

    # sort buffers
    hotlist = []
    infolist = weechat.infolist_get('hotlist', '', '')
    while weechat.infolist_next(infolist):
        hotlist.append(weechat.infolist_pointer(infolist, 'buffer_pointer'))
    weechat.infolist_free(infolist)
    last_index_hotlist = len(hotlist)

    def _sort_name(buf):
        """Sort buffers by name (or short name)."""
        return buf['name']

    def _sort_hotlist(buf):
        """Sort buffers by hotlist order."""
        try:
            return hotlist.index(buf['pointer'])
        except ValueError:
            # not in hotlist, always last.
            return last_index_hotlist

    def _sort_match_number(buf):
        """Sort buffers by match on number."""
        return 0 if str(buf['number']) == strinput else 1

    def _sort_match_beginning(buf):
        """Sort buffers by match at beginning."""
        return 0 if go_match_beginning(buf, strinput) else 1

    funcs = {
        'name': _sort_name,
        'hotlist': _sort_hotlist,
        'number': _sort_match_number,
        'beginning': _sort_match_beginning,
    }

    for key in weechat.config_get_plugin('sort').split(','):
        if key in funcs:
            listbuf = sorted(listbuf, key=funcs[key])

    if not strinput:
        index = [
            i for i, buf in enumerate(listbuf)
            if buf['pointer'] == weechat.current_buffer()
        ]
        if index:
            buffers_pos = index[0]

    return listbuf
Пример #57
0
                " || del %(buffer_autoset_options)", "bas_cmd", "")
            weechat.hook_completion("buffer_autoset_current_buffer",
                                    "current buffer name for buffer_autoset",
                                    "bas_completion_current_buffer_cb", "")
            weechat.hook_completion("buffer_autoset_options",
                                    "list of options for buffer_autoset",
                                    "bas_completion_options_cb", "")
            weechat.hook_signal("9000|buffer_opened",
                                "bas_signal_buffer_opened_cb", "")
            weechat.hook_config("%s.buffer.*" % CONFIG_FILE_NAME,
                                "bas_config_option_cb", "")

            # apply settings to all already opened buffers
            buffers = weechat.infolist_get("buffer", "", "")
            if buffers:
                while weechat.infolist_next(buffers):
                    buffer = weechat.infolist_pointer(buffers, "pointer")
                    bas_signal_buffer_opened_cb("", "", buffer)
                weechat.infolist_free(buffers)

# ==================================[ end ]===================================


def bas_unload_script():
    """ Function called when script is unloaded. """
    global bas_config_file

    if bas_config_file:
        bas_config_write()
    return weechat.WEECHAT_RC_OK