예제 #1
0
def find_channels():
    """Return list of servers and channels"""
    #@TODO: make it return a dict with more options like "nicks_count etc."
    items = {}
    infolist = w.infolist_get('irc_server', '', '')
    # populate servers
    while w.infolist_next(infolist):
        items[w.infolist_string(infolist, 'name')] = ''

    w.infolist_free(infolist)

    # populate channels per server
    for server in items.keys():
        items[server] = '' #init if connected but no channels
        infolist = w.infolist_get('irc_channel', '',  server)
        while w.infolist_next(infolist):
            if w.infolist_integer(infolist, 'nicks_count') == 0:
                #parted but still open in a buffer: bit hackish
                continue
            if w.infolist_integer(infolist, 'type') == 0:
                channel = w.infolist_string(infolist, "buffer_short_name")
                items[server] += '%s,' %channel
        w.infolist_free(infolist)

    return items
예제 #2
0
def find_channels():
    """Return list of servers and channels"""
    #@TODO: make it return a dict with more options like "nicks_count etc."
    items = {}
    infolist = w.infolist_get('irc_server', '', '')
    # populate servers
    while w.infolist_next(infolist):
        items[w.infolist_string(infolist, 'name')] = ''

    w.infolist_free(infolist)

    # populate channels per server
    for server in items.keys():
        keys = []
        keyed_channels = []
        unkeyed_channels = []
        items[server] = '' #init if connected but no channels
        infolist = w.infolist_get('irc_channel', '',  server)
        while w.infolist_next(infolist):
            if w.infolist_integer(infolist, 'nicks_count') == 0:
                #parted but still open in a buffer: bit hackish
                continue
            if w.infolist_integer(infolist, 'type') == 0:
                key = w.infolist_string(infolist, "key")
                if len(key) > 0:
                    keys.append(key)
                    keyed_channels.append(w.infolist_string(infolist, "name"))
                else :
                    unkeyed_channels.append(w.infolist_string(infolist, "name"))
        items[server] = ','.join(keyed_channels + unkeyed_channels)
        if len(keys) > 0:
            items[server] += ' %s' % ','.join(keys)
        w.infolist_free(infolist)

    return items
예제 #3
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
예제 #4
0
파일: weestats.py 프로젝트: idk/moo-skel
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
예제 #5
0
 def init_weechat(self):
     """
     Initialize theme using current WeeChat options (aliases are
     replaced with their values from palette).
     """
     # get palette options
     self.palette = {}
     infolist = weechat.infolist_get('option', '', 'weechat.palette.*')
     while weechat.infolist_next(infolist):
         option_name = weechat.infolist_string(infolist, 'option_name')
         value = weechat.infolist_string(infolist, 'value')
         self.palette[value] = option_name
     weechat.infolist_free(infolist)
     # get color options (replace aliases by values from palette)
     self.options = {}
     infolist = weechat.infolist_get('option', '', '')
     while weechat.infolist_next(infolist):
         full_name = weechat.infolist_string(infolist, 'full_name')
         if self._option_is_used(full_name):
             value = weechat.infolist_string(infolist, 'value')
             self.options[full_name] = self._get_color_without_alias(value)
     weechat.infolist_free(infolist)
     # replace aliases in chat_nick_colors
     option = 'weechat.color.chat_nick_colors'
     colors = []
     for color in self.options.get(option, '').split(','):
         colors.append(self._get_color_without_alias(color))
     if colors:
         self.options[option] = ','.join(colors)
     # replace aliases in buffer_time_format
     option = 'weechat.look.buffer_time_format'
     if option in self.options:
         value = re.compile(r'\$\{color:[^\}]+\}').sub(
             self._replace_color_alias, self.options[option])
         if value:
             self.options[option] = value
     # build dict with nick prefixes (and replace alisases)
     prefixes = []
     option = 'irc.color.nick_prefixes'
     for prefix in self.options.get(option, '').split(';'):
         values = prefix.split(':', 1)
         if len(values) == 2:
             prefixes.append(values[0] + ':' +
                             self._get_color_without_alias(values[1]))
     if prefixes:
         self.options[option] = ';'.join(prefixes)
     # delete palette
     del self.palette
예제 #6
0
def get_list_commands(plugin, input_cmd, input_args):
    """Get list of commands (beginning with current input)."""
    global cmdhelp_settings
    infolist = weechat.infolist_get('hook', '', 'command,%s*' % input_cmd)
    commands = []
    plugin_names = []
    while weechat.infolist_next(infolist):
        commands.append(weechat.infolist_string(infolist, 'command'))
        plugin_names.append(
            weechat.infolist_string(infolist, 'plugin_name') or 'core')
    weechat.infolist_free(infolist)
    if commands:
        if len(commands) > 1 or commands[0].lower() != input_cmd.lower():
            commands2 = []
            for index, command in enumerate(commands):
                if commands.count(command) > 1:
                    commands2.append('%s(%s)' % (command, plugin_names[index]))
                else:
                    commands2.append(command)
            return '%s%d commands: %s%s' % (
                weechat.color(cmdhelp_settings['color_list_count']),
                len(commands2),
                weechat.color(cmdhelp_settings['color_list']),
                ', '.join(commands2))
    return None
예제 #7
0
def match_against_nicklist(server, channel, hostmask):
    """Compare the hostmask against all users in the channel"""

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

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

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

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

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

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

    w.infolist_free(infolist)
    return matches
예제 #8
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)
예제 #9
0
def update_user_count(server=None, channel=None):
    if isinstance(channel, str):
        channel = set((channel, ))
    elif channel:
        channel = set(channel)

    def update_channel(server, channel=None):
        channel_infolist = weechat.infolist_get('irc_channel', '', server)
        while weechat.infolist_next(channel_infolist):
            _channel = weechat.infolist_string(channel_infolist, 'name')
            if channel:
                _channel = caseInsensibleKey(_channel)
                if _channel not in channel:
                    continue
            channel_stats[server, _channel] = weechat.infolist_integer(channel_infolist, 'nicks_count')
        weechat.infolist_free(channel_infolist)

    if not server:
        server_infolist = weechat.infolist_get('irc_server', '', '')
        while weechat.infolist_next(server_infolist):
            server = weechat.infolist_string(server_infolist, 'name')
            update_channel(server)
        weechat.infolist_free(server_infolist)
    else:
        update_channel(server, channel)
예제 #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 bufsave_cmd(data, buffer, args):
    ''' Callback for /bufsave command '''

    filename = args

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

    if exists(filename):
        w.prnt('', "Error: target file already exists!")
        return w.WEECHAT_RC_OK
        
    infolist = w.infolist_get('buffer_lines', buffer, '')
    channel =  w.buffer_get_string(buffer, 'name')
    try:
        fp = file(filename, 'w')
    except:
        w.prnt('', "Error writing to target file!")
        return w.WEECHAT_RC_OK

    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)

    return w.WEECHAT_RC_OK
예제 #12
0
def gen_infolist_get(infolist_name, arguments, pointer=""):
    """
    Same as infolist_get(), but yields it's elements.
    Be sure to iterate through the whole list, to ensure
    weechat.infolist_free() is called.
    """
    infolist = weechat.infolist_get(infolist_name, pointer, arguments)
    if infolist:
        while weechat.infolist_next(infolist):
            fields = weechat.infolist_fields(infolist).split(',')
            field_names = []
            list_element = {}
            for field in fields:
                field_type, field_name = field.split(':')
                field_names.append(field_name)

                # decide which function to use
                info_func = {
                    'i': weechat.infolist_integer,
                    's': weechat.infolist_string,
                    'p': weechat.infolist_pointer,
                    # 'b': weechat.infolist_buffer,
                    't': weechat.infolist_time,
                }[field_type]
                value = info_func(infolist, field_name)
                list_element[field_name] = value
            # create a temporary namedtuple type using field_names
            item_tpl = namedtuple('InfolistItem', field_names)
            yield item_tpl(**list_element)
        weechat.infolist_free(infolist)
예제 #13
0
def get_option_list_and_desc(option, displayname):
    """Get list of options and description for option(s)."""
    global cmdhelp_settings, cmdhelp_option_infolist
    global cmdhelp_option_infolist_fields
    options = []
    description = ''
    cmdhelp_option_infolist = weechat.infolist_get('option', '', option)
    if cmdhelp_option_infolist:
        cmdhelp_option_infolist_fields = {}
        while weechat.infolist_next(cmdhelp_option_infolist):
            options.append(weechat.infolist_string(cmdhelp_option_infolist,
                                                   'full_name'))
            if not description:
                fields = weechat.infolist_fields(cmdhelp_option_infolist)
                for field in fields.split(','):
                    items = field.split(':', 1)
                    if len(items) == 2:
                        cmdhelp_option_infolist_fields[items[1]] = items[0]
                description = re.compile(r'\$\{[^\}]+\}').sub(
                    format_option, cmdhelp_settings['format_option'])
                if displayname:
                    description = '%s%s%s: %s' % (
                        weechat.color(cmdhelp_settings['color_option_name']),
                        weechat.infolist_string(cmdhelp_option_infolist,
                                                'full_name'),
                        weechat.color(cmdhelp_settings['color_option_help']),
                        description)
        weechat.infolist_free(cmdhelp_option_infolist)
        cmdhelp_option_infolist = ''
        cmdhelp_option_infolist_fields = {}
    return options, description
예제 #14
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
예제 #15
0
파일: hank.py 프로젝트: wetfish/hank
def get_hank_home():
    infolist = weechat.infolist_get("python_script", "", "hankbot")
    fname = "~/hank/hank.py"
    while weechat.infolist_next(infolist):
        fname = weechat.infolist_string(infolist, "filename")
    weechat.infolist_free(infolist)
    return os.path.dirname(os.path.realpath(fname))
예제 #16
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
예제 #17
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
예제 #18
0
def _find_first_buffer_number():
    infolist = weechat.infolist_get('buffer', '', '')
    while weechat.infolist_next(infolist):
        short_name = weechat.infolist_string(infolist, 'short_name')
        if _newserv_match(short_name):
            number = weechat.infolist_integer(infolist, 'number')
            return number
예제 #19
0
파일: automode.py 프로젝트: qguv/config
def get_patterns_in_config(filter):
    d = {}
    infolist = weechat.infolist_get('option', '', 'plugins.var.python.%s.%s' %(SCRIPT_NAME, filter))
    while weechat.infolist_next(infolist):
        name = weechat.infolist_string(infolist, 'option_name')
        name = name[len('python.%s.' %SCRIPT_NAME):]
        # channels might have dots in their names, so we'll strip type from right and server
        # from left. Lets hope that users doesn't use dots in server names.
        name, _, type = name.rpartition('.')
        if type not in ('op', 'halfop', 'voice'):
            # invalid option
            continue
        server, _, channel = name.partition('.')
        value = weechat.infolist_string(infolist, 'value')
        if not value:
            continue
        else:
            value = value.split(',')
        key = (server, channel)
        if key not in d:
            d[key] = {type:value}
        else:
            d[key][type] = value
    weechat.infolist_free(infolist)
    return d
예제 #20
0
파일: title.py 프로젝트: aimeeble/dotfiles
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
예제 #21
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
예제 #22
0
def hotlist_cache_update_cb(data, remaining_calls):
    #this keeps the hotlist dupe up to date for the buffer switch, but is prob technically a race condition. (meh)
    global hotlist
    prev_hotlist = hotlist
    hotlist = w.infolist_get("hotlist", "", "")
    w.infolist_free(prev_hotlist)
    return w.WEECHAT_RC_OK
예제 #23
0
def buffer_count():
    buffer_count = 0
    buffer = weechat.infolist_get("buffer", "", "")
    while weechat.infolist_next(buffer):
        buffer_count += 1
    weechat.infolist_free(buffer)
    return buffer_count
예제 #24
0
def get_clones_for_buffer(infolist_buffer_name, hostname_to_match=None):
  matches = {}
  infolist = weechat.infolist_get("irc_nick", "", infolist_buffer_name)
  while(weechat.infolist_next(infolist)):
    ident_hostname = weechat.infolist_string(infolist, "host")
    host_matchdata = re.match('([^@]+)@(\S+)', ident_hostname)
    if not host_matchdata:
      continue

    hostname = host_matchdata.group(2).lower()
    ident = host_matchdata.group(1).lower()
    if weechat.config_get_plugin("compare_idents") == "on":
      hostkey = ident_hostname.lower()
    else:
      hostkey = hostname

    if hostname_to_match and hostname_to_match.lower() != hostkey:
      continue

    nick = weechat.infolist_string(infolist, "name")

    matches.setdefault(hostkey,[]).append({
      'nick': nick,
      'mask': "%s!%s" % (
        format_from_config(nick, "colors.mask.nick"), 
        format_from_config(ident_hostname, "colors.mask.identhost")),
      'ident': ident,
      'ident_hostname': ident_hostname,
      'hostname': hostname,
    })
  weechat.infolist_free(infolist)

  #Select only the results that have more than 1 match for a host
  return dict((k, v) for (k, v) in matches.iteritems() if len(v) > 1)
예제 #25
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
예제 #26
0
파일: go.py 프로젝트: GGLucas/configs
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
예제 #27
0
def servernicks(servername):
    infolist = weechat.infolist_get('irc_server','',servername)
    weechat.infolist_next(infolist)
    nicks = weechat.infolist_string(infolist, 'nicks')
    weechat.infolist_free(infolist)
    servernicks = nicks.split(',')
    return servernicks
예제 #28
0
def get_irc_servers():
    """ Returns a list of configured IRC servers in weechat"""
    serverptrlist = weechat.infolist_get('irc_server', '', '')
    serverlist = []
    while weechat.infolist_next(serverptrlist):
         serverlist.append(weechat.infolist_string(serverptrlist, 'name'))
    return serverlist
예제 #29
0
파일: docgen.py 프로젝트: stfnm/weechat_old
def get_options():
    """
    Get list of config options in a dict with 4 indexes: config,
    section, option, xxx.
    """
    global plugin_list, ignore_options
    options = \
        defaultdict(lambda: defaultdict(lambda: defaultdict(defaultdict)))
    infolist = weechat.infolist_get('option', '', '')
    while weechat.infolist_next(infolist):
        full_name = weechat.infolist_string(infolist, 'full_name')
        if not re.search('|'.join(ignore_options), full_name):
            config = weechat.infolist_string(infolist, 'config_name')
            if config in plugin_list and 'o' in plugin_list[config]:
                section = weechat.infolist_string(infolist, 'section_name')
                option = weechat.infolist_string(infolist, 'option_name')
                for key in ('type', 'string_values', 'default_value',
                            'description'):
                    options[config][section][option][key] = \
                        weechat.infolist_string(infolist, key)
                for key in ('min', 'max', 'null_value_allowed'):
                    options[config][section][option][key] = \
                        weechat.infolist_integer(infolist, key)
    weechat.infolist_free(infolist)
    return options
예제 #30
0
def reorder_buffers():
    """Reorders the buffers once the whitelist has changed
    """

    count = 2
    chan = ""

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

    for chan in whitelist:
        if -1 == chan.find(".#"): #network name is not set, matching by short_name
            weechat.infolist_reset_item_cursor(ilist)

            while weechat.infolist_next(ilist):
                if weechat.infolist_string(ilist, "short_name") == chan:
                    chan = weechat.infolist_string(ilist, "name")
                    break

        buff = weechat.buffer_search("irc", chan)

        if buff:
            weechat.buffer_set(buff, "number", str(count))
            count += 1

    weechat.infolist_free(ilist)

    return weechat.WEECHAT_RC_OK
예제 #31
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
예제 #32
0
def get_default_aliases():
    """
    Get list of default aliases as list of dictionaries.
    """
    default_aliases = []
    infolist = weechat.infolist_get('alias_default', '', '')
    while weechat.infolist_next(infolist):
        default_aliases.append({
            'name':
            '/' + weechat.infolist_string(infolist, 'name'),
            'command':
            '/' + weechat.infolist_string(infolist, 'command'),
            'completion':
            weechat.infolist_string(infolist, 'completion'),
        })
    weechat.infolist_free(infolist)
    return default_aliases
예제 #33
0
def get_buffers():
    ''' Get a list of all the buffers in weechat. '''
    buffers = []

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

    while weechat.infolist_next(buffer_list):
        name = weechat.infolist_string(buffer_list, 'full_name')
        number = weechat.infolist_integer(buffer_list, 'number')

        # Buffer is merged with one we already have in the list, skip it.
        if number <= len(buffers):
            continue
        buffers.append((name, number - 1))

    weechat.infolist_free(buffer_list)
    return buffers
예제 #34
0
def get_commands():
    """
    Get list of commands in a dict with 3 indexes: plugin, command, xxx.
    """
    global plugin_list
    commands = defaultdict(lambda: defaultdict(defaultdict))
    infolist = weechat.infolist_get('hook', '', 'command')
    while weechat.infolist_next(infolist):
        plugin = weechat.infolist_string(infolist, 'plugin_name') or 'weechat'
        if plugin in plugin_list:
            command = weechat.infolist_string(infolist, 'command')
            if command == plugin or 'c' in plugin_list[plugin]:
                for key in ('description', 'args', 'args_description',
                            'completion'):
                    commands[plugin][command][key] = \
                        weechat.infolist_string(infolist, key)
    weechat.infolist_free(infolist)
    return commands
예제 #35
0
파일: hank.py 프로젝트: emilypi/hank
def run_alert(srv, chn, from_nick):
    buffer = weechat.info_get("irc_buffer", srv + "," + chn)
    if not buffer:
        return
    nicks = []
    nicklist = weechat.infolist_get("nicklist", buffer, "")
    is_op = False
    while weechat.infolist_next(nicklist):
        nick = weechat.infolist_string(nicklist, "name")
        nick_type = weechat.infolist_string(nicklist, "type")
        nick_prefix = weechat.infolist_string(nicklist, "prefix")
        if nick_type == "nick":
            nicks.append(nick)
            if nick == from_nick and (nick_prefix == "@" or nick_prefix == "&"):
                is_op = True
    weechat.infolist_free(nicklist)
    if is_op:
        say(srv, chn, "Alert: " + (", ".join(nicks)))
예제 #36
0
def get_url_options():
    """
    Get list of completions hooked by plugins in a dict with 3 indexes:
    plugin, item, xxx.
    """
    url_options = []
    infolist = weechat.infolist_get('url_options', '', '')
    while weechat.infolist_next(infolist):
        url_options.append(
            {
                'name': weechat.infolist_string(infolist, 'name').lower(),
                'option': weechat.infolist_integer(infolist, 'option'),
                'type': weechat.infolist_string(infolist, 'type'),
                'constants': weechat.infolist_string(infolist, 'constants')
                .lower().replace(',', ', ')
            })
    weechat.infolist_free(infolist)
    return url_options
예제 #37
0
def hook_print_callback(data, buffer, date, tags, displayed, highlight, prefix,
                        message):
    if weechat.config_get_plugin('short_own') == 'on':
        # get servername
        infolist = weechat.infolist_get('buffer', buffer, '')
        weechat.infolist_next(infolist)
        servername, undef = weechat.infolist_string(infolist,
                                                    'name').split('.', 1)
        weechat.infolist_free(infolist)

        # get own nick
        my_nick = weechat.info_get('irc_nick', servername)
        if my_nick in tags:
            return weechat.WEECHAT_RC_OK

    return match_url(message, buffer, False)

    return weechat.WEECHAT_RC_OK
예제 #38
0
def rlayout_bar_cb(data, item, window):
    infolist = weechat.infolist_get("layout", "", "")
    layout = None

    while weechat.infolist_next(infolist):
        if weechat.infolist_integer(infolist, "current_layout") == 1:
            layout = weechat.infolist_string(infolist, "name")
            break

    weechat.infolist_free(infolist)

    if layout is None:
        return ""
    else:
        term_height = int(weechat.info_get("term_height", ""))
        term_width = int(weechat.info_get("term_width", ""))

    return "%s (%sx%s)" % (layout, term_width, term_height)
예제 #39
0
 def _read_api_completions():
     """
     Get list of WeeChat/plugins completions as dictionary with 3 indexes:
     plugin, item, xxx.
     """
     completions = defaultdict(lambda: defaultdict(defaultdict))
     infolist = weechat.infolist_get('hook', '', 'completion')
     while weechat.infolist_next(infolist):
         completion_item = weechat.infolist_string(infolist,
                                                   'completion_item')
         if not re.search('|'.join(IGNORE_COMPLETIONS_ITEMS),
                          completion_item):
             plugin = (weechat.infolist_string(infolist, 'plugin_name')
                       or 'weechat')
             completions[plugin][completion_item]['description'] = \
                 weechat.infolist_string(infolist, 'description')
     weechat.infolist_free(infolist)
     return completions
예제 #40
0
파일: docgen.py 프로젝트: raspbeguy/weechat
def get_commands():
    """
    Get list of WeeChat/plugins commands as dictionary with 3 indexes: plugin,
    command, xxx.
    """
    commands = defaultdict(lambda: defaultdict(defaultdict))
    infolist = weechat.infolist_get('hook', '', 'command')
    while weechat.infolist_next(infolist):
        plugin = weechat.infolist_string(infolist, 'plugin_name') or 'weechat'
        if plugin in PLUGIN_LIST:
            command = weechat.infolist_string(infolist, 'command')
            if command == plugin or 'c' in PLUGIN_LIST[plugin]:
                for key in ('description', 'args', 'args_description',
                            'completion'):
                    commands[plugin][command][key] = \
                        weechat.infolist_string(infolist, key)
    weechat.infolist_free(infolist)
    return commands
예제 #41
0
def set_back(overridable_messages):
    """Removes away status for servers
    where one of the overridable_messages is set"""
    if (weechat.config_get_plugin('away') == '0'):
        return  # No need to come back again
    serverlist = weechat.infolist_get('irc_server', '', '')
    if serverlist:
        buffers = []
        while weechat.infolist_next(serverlist):
            if (weechat.infolist_string(serverlist, 'away_message')
                    in overridable_messages):
                ptr = weechat.infolist_pointer(serverlist, 'buffer')
                if ptr:
                    buffers.append(ptr)
        weechat.infolist_free(serverlist)
        for buffer in buffers:
            weechat.command(buffer, "/away")
    weechat.config_set_plugin('away', '0')
예제 #42
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')

        server_matched = re.search(r"\b({})\b".format("|".join(serverlist)),
                                   servername)
        if servername in serverlist or server_matched and is_connected:
            if nick and ssl_connected + is_connected:
                ison(ptr_buffer, servername, nick, server_nicks(servername))
    weechat.infolist_free(infolist)
    return weechat.WEECHAT_RC_OK
예제 #43
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
예제 #44
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.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
예제 #45
0
def retrieve_channels(server):
    """Get a list of the channels the user is in"""

    isupport_chantypes = w.info_get("irc_server_isupport_value",
                                    "{},CHANTYPES".format(server))
    ischan_regex = re.compile("^{}\.[{}]".format(
        re.escape(server), re.escape(isupport_chantypes)))

    chans = []
    infolist = w.infolist_get("buffer", "", "")

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

        if ischan_regex.match(bname):
            chans.append(bname)

    w.infolist_free(infolist)
    return chans
예제 #46
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
예제 #47
0
파일: term.py 프로젝트: sim642/weechat-term
    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
예제 #48
0
def bas_signal_buffer_opened_cb(data, signal, signal_data):
    buffer = signal_data
    name = "%s.%s" % (weechat.buffer_get_string(buffer, "plugin"),
                      weechat.buffer_get_string(buffer, "name"))
    options = weechat.infolist_get("option", "", "%s.buffer.*" % CONFIG_FILE_NAME)
    if options:
        while weechat.infolist_next(options):
            option = weechat.infolist_string(options, "option_name")
            value = weechat.infolist_string(options, "value")
            if option:
                pos = option.rfind(".")
                if pos > 0:
                    buffer_mask = option[0:pos]
                    property = option[pos+1:]
                    if buffer_mask and property:
                        if weechat.string_match(name, buffer_mask, 1):
                            weechat.buffer_set(buffer, property, value)
        weechat.infolist_free(options)
    return weechat.WEECHAT_RC_OK
예제 #49
0
파일: util.py 프로젝트: h1r00/flute
def irc_channel_is_empty(channel, server):
    """Return True if we are the only nick in the channel."""

    infolist = weechat.infolist_get('irc_nick', '',
                                    "%s,%s" % (server, channel))
    n_members = 0

    # Count users
    if infolist:
        while weechat.infolist_next(infolist):
            n_members += 1

        weechat.infolist_free(infolist)

    # At least another person is in the channel.
    if n_members > 1:
        return False

    return True
예제 #50
0
파일: autoconf.py 프로젝트: kevr/scripts
def save_conf(args):
    """match options and save to config file"""

    try:
        f = open(get_config(args), 'w+')

    except Exception as e:
        w.prnt('', '%sError: %s' % (w.prefix('error'), e))

        return w.WEECHAT_RC_ERROR

    header = [
        '#',
        '# WeeChat %s (compiled on %s)' % (w.info_get('version', ''), w.info_get('date', '')),
        '#',
        '# Use /autoconf load or cat this file to the FIFO pipe.',
        '#',
        '# For more info, see https://weechat.org/scripts/source/autoconf.py.html',
        '#',
        ''
    ]

    for ln in header:
        f.write('%s\n' % ln)

    w.command('', '/buffer clear')
    w.command('', '/set diff')

    infolist = w.infolist_get('buffer_lines', '', '')

    while w.infolist_next(infolist):
        message = cstrip(w.infolist_string(infolist, 'message'))
        ignore = w.config_get_plugin('ignore').split(',')
        option = re.match(RE['option'], message)

        if option:
            if not any(fnmatch(option.group(1), p.strip()) for p in ignore):
                f.write('*/set %s %s\n' % (option.group(1), option.group(2)))

    f.close()

    w.infolist_free(infolist)
예제 #51
0
def bas_apply_options_for_buffer(buffer):
    full_name = weechat.buffer_get_string(buffer, "full_name")
    options = weechat.infolist_get("option", "",
                                   "%s.buffer.*" % CONFIG_FILE_NAME)
    if not options:
        return

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

    weechat.infolist_free(options)
예제 #52
0
파일: docgen.py 프로젝트: raspbeguy/weechat
def get_url_options():
    """
    Get list of URL options as list of dictionaries.
    """
    url_options = []
    infolist = weechat.infolist_get('url_options', '', '')
    while weechat.infolist_next(infolist):
        url_options.append({
            'name':
            weechat.infolist_string(infolist, 'name').lower(),
            'option':
            weechat.infolist_integer(infolist, 'option'),
            'type':
            weechat.infolist_string(infolist, 'type'),
            'constants':
            weechat.infolist_string(infolist,
                                    'constants').lower().replace(',', ', ')
        })
    weechat.infolist_free(infolist)
    return url_options
예제 #53
0
def bar_item_update(signal, callback, callback_data):
    ptr_infolist_option = weechat.infolist_get(
        'option', '', 'plugins.var.python.' + SCRIPT_NAME + '.*')

    if not ptr_infolist_option:
        return

    while weechat.infolist_next(ptr_infolist_option):
        option_full_name = weechat.infolist_string(ptr_infolist_option,
                                                   'full_name')
        option_name = option_full_name[len('plugins.var.python.' +
                                           SCRIPT_NAME +
                                           '.'):]  # get optionname

        # check if item exists in a bar and if we have a hook for it
        if weechat.bar_item_search(option_name) and option_name in hooks:
            weechat.bar_item_update(option_name)

    weechat.infolist_free(ptr_infolist_option)
    return weechat.WEECHAT_RC_OK
예제 #54
0
def rlayouts_list():
    """
    Return a list of configured rlayouts.
    """
    layouts = []
    pattern = re.compile(r"^plugins\.var\.python\.%s\.layout\.(.+)\." %
                         SCRIPT_NAME)
    infolist = weechat.infolist_get(
        "option", "", "plugins.var.python.%s.layout.*" % SCRIPT_NAME)

    while weechat.infolist_next(infolist):
        layout = re.search(pattern,
                           weechat.infolist_string(infolist,
                                                   "full_name")).groups()
        if layout[0] not in layouts:
            layouts.append(layout[0])

    weechat.infolist_free(infolist)

    return layouts
예제 #55
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
예제 #56
0
def grep_buffer(buffer, head, tail, *args):
    """Return a list of lines that match 'regexp' in 'buffer', if no regexp returns all lines."""
    lines = []
    # Using /grep in grep's buffer can lead to some funny effects
    # We should take measures if that's the case
    grep_buffer = weechat.buffer_search('python', SCRIPT_NAME)
    grep_buffer = buffer == grep_buffer
    infolist = weechat.infolist_get('buffer_lines', buffer, '')
    if tail:
        # like with grep_file() if we need the last few matching lines, we move the cursor to
        # the end and search backwards
        infolist_next = weechat.infolist_prev
    else:
        infolist_next = weechat.infolist_next
    limit = head or tail

    append = lines.append
    check = check_string
    infolist_time = weechat.infolist_time
    while infolist_next(infolist):
        prefix = weechat.infolist_string(infolist, 'prefix')
        message = weechat.infolist_string(infolist, 'message')
        prefix = weechat.string_remove_color(prefix, '')
        message = weechat.string_remove_color(message, '')
        if grep_buffer:
            if script_nick == prefix:  # ignore our lines
                continue
            date = prefix
            line = '%s\t%s' % (date, message.replace(' ', '\t', 1))
        else:
            date = infolist_time(infolist, 'date')
            line = '%s\t%s\t%s' % (date, prefix, message)
        line = check(line, *args)
        if line:
            append(line)
            if limit and len(lines) >= limit:
                break
    weechat.infolist_free(infolist)
    if tail:
        lines.reverse()
    return lines
예제 #57
0
def create_bar_items():
    ptr_infolist_option = weechat.infolist_get(
        'option', '', 'plugins.var.python.' + SCRIPT_NAME + '.*')

    if not ptr_infolist_option:
        return

    while weechat.infolist_next(ptr_infolist_option):
        option_full_name = weechat.infolist_string(ptr_infolist_option,
                                                   'full_name')
        option_name = option_full_name[len('plugins.var.python.' +
                                           SCRIPT_NAME +
                                           '.'):]  # get optionname

        if weechat.bar_item_search(option_name):
            weechat.bar_item_update(option_name)
        else:
            weechat.bar_item_new(option_name, 'update_item', option_name)
        weechat.bar_item_update(option_name)

    weechat.infolist_free(ptr_infolist_option)
예제 #58
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')
예제 #59
0
    def get_buffers(self):
        buffers = []

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

        while weechat.infolist_next(buffer_pnt):
            buffer_plugin_name = weechat.infolist_string(buffer_pnt, "plugin_name")
            buffer_name = weechat.infolist_string(buffer_pnt, "name")
            buffer_number = weechat.infolist_integer(buffer_pnt, "number")

            buffer_number = int(buffer_number)

            if buffer_plugin_name == 'irc':
                (server, name) = tuple(buffer_name.split('.', 1))

                buf = SortServers_Buffer(buffer_number, server, name)
                buffers.append(buf)

        weechat.infolist_free(buffer_pnt)

        return buffers
예제 #60
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