Exemple #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
Exemple #2
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
def buffer_opened_closed_cb(data, signal, signal_data):
    global OPTIONS

    # localvar not set in this moment? :-(
#    server = weechat.buffer_get_string(signal_data, 'localvar_server')          # get internal servername
    infolist = weechat.infolist_get('buffer', signal_data, '')
    weechat.infolist_next(infolist)
    plugin_name = weechat.infolist_string(infolist, 'plugin_name')
    name = weechat.infolist_string(infolist, 'name')
    weechat.infolist_free(infolist)

    # TODO how about matrix script or other non-irc channel buffer? no idea! help is welcome
    if plugin_name != "irc":                                                    # for example /fset, /color etc.pp buffer
        return weechat.WEECHAT_RC_OK

    if OPTIONS['activity'].lower() == 'no' or OPTIONS['activity'].lower() == 'off' or OPTIONS['activity'].lower() == '0':
        weechat.command('','/allchan -exclude=%s /buffer hide' % OPTIONS['channel_exclude'])
        if not signal_data:                                                     # signal_data available?
            weechat.command(signal_data,'/allchan -current /buffer unhide')
        else:                                                                   # signal_data empty!
            weechat.command('','/allchan /buffer hide')
        exclude_server('')
        single_channel_exclude()
    else:
        weechat.command('','/allchan /buffer hide')
    exclude_hotlist()
    return weechat.WEECHAT_RC_OK
Exemple #4
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
Exemple #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")
    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
Exemple #6
0
def xfer_end_do(data, signal, signal_data):
    wc.infolist_next(signal_data)
    status = wc.infolist_string(signal_data, 'status_string')
    filename = wc.infolist_string(signal_data, 'filename')
    local = wc.infolist_string(signal_data, 'local_filename')
    if status == "done":
        os.popen('eiyfs "%s"' % local, 'r', 0)
    return wc.WEECHAT_RC_OK
Exemple #7
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
Exemple #8
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
Exemple #9
0
def xfer_ended_signal_cb(data, signal, signal_data):
    weechat.infolist_next(signal_data)
    status_string, filename, local_filename = weechat.infolist_string(signal_data, 'status_string'), weechat.infolist_string(signal_data, 'filename'), weechat.infolist_string(signal_data, 'local_filename')

    if status_string == "done":
        for pattern in patterns.keys():
            if re.match(pattern, filename):
                scp_file(local_filename, patterns[pattern])
                return weechat.WEECHAT_RC_OK
        # check for a defualt dir and send there since for loop completed without returning
    return weechat.WEECHAT_RC_OK
def walk_nicklist(nicklist,word):
    weechat.infolist_reset_item_cursor(nicklist)
    ni = weechat.infolist_next(nicklist)
    while ni :
        type = weechat.infolist_string(nicklist,'type')
        if type == 'nick':
            nick = weechat.infolist_string(nicklist,'name')
            if nick.lower().startswith(word):
                return nick
        ni = weechat.infolist_next(nicklist)
    return ''
Exemple #11
0
def other_nicks(channel_name, server_name):
    nicks = []
    infolist = weechat.infolist_get("irc_nick", "",
                                    server_name + "," + channel_name)
    rc = weechat.infolist_next(infolist)
    while rc:
        nick = weechat.infolist_string(infolist, "name")
        if nick != my_nick(server_name):
            nicks.append(nick)
        rc = weechat.infolist_next(infolist)

    return nicks
Exemple #12
0
def hide_buffer_cb(data, signal, signal_data):
    """Hide the previous IRC buffer when switching buffers.

    If configuration option ``hide_private`` is enabled,
    private buffers will become hidden as well.

    If the previous buffer name matches any of the exemptions defined in ``exemptions``,
    it will not become hidden.

    :param data: Pointer
    :param signal: Signal sent by Weechat
    :param signal_data: Data sent with signal
    :returns: callback return value expected by Weechat.
    """
    global CURRENT_BUFFER

    previous_buffer = CURRENT_BUFFER
    CURRENT_BUFFER = weechat.current_buffer()

    plugin = weechat.buffer_get_string(previous_buffer, "plugin")
    full_name = weechat.buffer_get_string(previous_buffer, "full_name")
    server = weechat.buffer_get_string(previous_buffer, "localvar_server")
    channel = weechat.buffer_get_string(previous_buffer, "localvar_channel")

    if full_name.startswith("irc.server"):
        return WEECHAT_RC_OK

    buffer_type = weechat.buffer_get_string(
        weechat.info_get("irc_buffer", "{},{}".format(server, channel)),
        "localvar_type")

    if (buffer_type == "private"
            and weechat.config_get_plugin("hide_private") == "off"):
        return WEECHAT_RC_OK

    if weechat.config_get_plugin("hide_inactive") == "off":
        nicks_count = 0
        infolist = weechat.infolist_get(
            "irc_channel", "", "{},{}".format(server, channel))
        if infolist:
            weechat.infolist_next(infolist)
            nicks_count = weechat.infolist_integer(infolist, "nicks_count")
        weechat.infolist_free(infolist)
        if nicks_count == 0:
            return WEECHAT_RC_OK

    for entry in list_exemptions():
        if entry in full_name:
            return WEECHAT_RC_OK

    weechat.buffer_set(previous_buffer, "hidden", "1")
    return WEECHAT_RC_OK
Exemple #13
0
def cb_hats(data, item, window):
    buf = weechat.current_buffer()
    plugin = weechat.buffer_get_string(buf, "localvar_plugin")
    if plugin == "irc":
        server = weechat.buffer_get_string(buf, "localvar_server")
        channel = weechat.buffer_get_string(buf, "localvar_channel")
        nick = weechat.buffer_get_string(buf, "localvar_nick")
        nicks = weechat.infolist_get("irc_nick", "", "{},{},{}".format(
            server, channel, nick))
        weechat.infolist_next(nicks)
        hats = weechat.infolist_string(nicks, "prefixes")
        weechat.infolist_free(nicks)
        return hats.replace(" ", "")
    return ""
def relay_attached():
    '''Returns True if relay is attached else False'''
    # get infolist for relay
    infolist = w.infolist_get('relay', '', '')

    # only need to look at the first status (current or most recent)
    w.infolist_next(infolist)

    # status can be connected connecting or disconnected
    connected = w.infolist_string(infolist, 'status_string') == 'connected'

    # have to free infolist since it isn't done automatically
    w.infolist_free(infolist)

    return connected
Exemple #15
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
Exemple #16
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
Exemple #17
0
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))
Exemple #18
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
Exemple #19
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)
Exemple #20
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)
Exemple #21
0
 def next(self):
     """Return the next set of fields"""
     if weechat.infolist_next(self._infolist):
         fields = self.get_fields()
         return fields
     else:
         raise StopIteration
Exemple #22
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
Exemple #23
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
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
Exemple #25
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
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)
Exemple #27
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
Exemple #28
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)
Exemple #29
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)
Exemple #30
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
Exemple #31
0
def cron_completion_buffer_cb(data, completion_item, buffer, completion):
    """ Complete with buffer, for command '/cron'. """
    infolist = weechat.infolist_get("buffer", "", "")
    while weechat.infolist_next(infolist):
        plugin_name = weechat.infolist_string(infolist, "plugin_name")
        name = weechat.infolist_string(infolist, "name")
        weechat.hook_completion_list_add(completion,
                                         "%s.%s" % (plugin_name, name),
                                         0, weechat.WEECHAT_LIST_POS_SORT)
    weechat.infolist_free(infolist)
    weechat.hook_completion_list_add(completion, "current",
                                     0, weechat.WEECHAT_LIST_POS_BEGINNING)
    weechat.hook_completion_list_add(completion, "core.weechat",
                                     0, weechat.WEECHAT_LIST_POS_BEGINNING)
    return weechat.WEECHAT_RC_OK
Exemple #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
Exemple #33
0
def get_irc_colors():
    """
    Get list of IRC colors as list of dictionaries.
    """
    irc_colors = []
    infolist = weechat.infolist_get('irc_color_weechat', '', '')
    while weechat.infolist_next(infolist):
        irc_colors.append({
            'color_irc':
            weechat.infolist_string(infolist, 'color_irc'),
            'color_weechat':
            weechat.infolist_string(infolist, 'color_weechat'),
        })
    weechat.infolist_free(infolist)
    return irc_colors
def check_away_status():
    away = (False, False)
    irc_servers = weechat.infolist_get("irc_server", "", "")

    while weechat.infolist_next(irc_servers):
        auto_away_msg = weechat.config_get_plugin('away_msg')
        current_away_msg = weechat.infolist_string(irc_servers, "away_message")

        is_away_by_me = current_away_msg == auto_away_msg
        is_away = bool(weechat.infolist_integer(irc_servers, "is_away"))
        away = (is_away, is_away_by_me)

    weechat.infolist_free(irc_servers)

    return away
Exemple #35
0
def masshl_cmd_cb(data, buffer, args):
	global nicks
	server   = weechat.buffer_get_string(buffer, 'localvar_server')
	channel  = weechat.buffer_get_string(buffer, 'localvar_channel')
	nicklist = weechat.infolist_get('irc_nick', '', server+','+channel)
	while weechat.infolist_next(nicklist):
		nicks.append(weechat.infolist_string(nicklist, 'name'))
	weechat.infolist_free(nicklist)
	del server, channel, nicklist
	nicks.pop(0)
	if args[:2] == '-1':
		weechat.command(buffer, ', '.join(nicks))
	else:
		weechat.hook_timer(100, 0, len(nicks), 'timer_cb', '[split]'.join((buffer,args)))
	return weechat.WEECHAT_RC_OK
Exemple #36
0
def get_infos_hashtable():
    """
    Get list of WeeChat/plugins infos (hashtable) as dictionary with 3 indexes:
    plugin, name, xxx.
    """
    infos_hashtable = defaultdict(lambda: defaultdict(defaultdict))
    infolist = weechat.infolist_get('hook', '', 'info_hashtable')
    while weechat.infolist_next(infolist):
        info_name = weechat.infolist_string(infolist, 'info_name')
        plugin = weechat.infolist_string(infolist, 'plugin_name') or 'weechat'
        for key in ('description', 'args_description', 'output_description'):
            infos_hashtable[plugin][info_name][key] = \
                weechat.infolist_string(infolist, key)
    weechat.infolist_free(infolist)
    return infos_hashtable
Exemple #37
0
def wg_get_loaded_scripts():
    """
    Get python dictionary with loaded scripts.
    Keys are filenames and values are path to script, for example:
      'weeget.py': '/home/xxx/.weechat/python/weeget.py'
    """
    global wg_loaded_scripts
    wg_loaded_scripts = {}
    for language in SCRIPT_EXTENSION.keys():
        infolist = weechat.infolist_get(language + "_script", "", "")
        while weechat.infolist_next(infolist):
            filename = weechat.infolist_string(infolist, "filename")
            if filename != "":
                wg_loaded_scripts[os.path.basename(filename)] = filename
        weechat.infolist_free(infolist)
Exemple #38
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
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
Exemple #40
0
def bar_item_umodes(data, item, window):
    buffer = w.window_get_pointer(window, "buffer")
    server = w.buffer_get_string(buffer, "localvar_server")

    if server:
        uinfo = w.infolist_get("irc_server", '', server)
        w.infolist_next(uinfo)
        modes = w.infolist_string(uinfo, "nick_modes")
        w.infolist_free(uinfo)

        modes = list(sorted(modes))
        modesf = mode_setting("umodes", server) or default_umodes(server)

        for i, mode in enumerate(modes):
            if mode in modesf:
                color = w.color(modesf[mode])
            else:
                color = w.color(
                    w.config_string(w.config_get("irc.color.item_nick_modes")))
            modes[i] = f"{color}{mode}"

        return "".join(modes)
    else:
        return ""
Exemple #41
0
def get_nicks(buffer, prefix=''):
    channel = weechat.buffer_get_string(buffer, 'localvar_channel')
    server = weechat.buffer_get_string(buffer, 'localvar_server')

    matches = []

    infolist = weechat.infolist_get('irc_nick', '',
                                    '%s,%s' % (server, channel))
    while weechat.infolist_next(infolist):
        nick = weechat.infolist_string(infolist, 'name')
        if nick != 'localhost' and nick.lower().startswith(prefix.lower()):
            matches.append(nick)
    weechat.infolist_free(infolist)

    return matches
Exemple #42
0
def get_plugins_priority():
    """
    Get priority of default WeeChat plugins as a dictionary.
    """
    plugins_priority = {}
    infolist = weechat.infolist_get('plugin', '', '')
    while weechat.infolist_next(infolist):
        name = weechat.infolist_string(infolist, 'name')
        priority = weechat.infolist_integer(infolist, 'priority')
        if priority in plugins_priority:
            plugins_priority[priority].append(name)
        else:
            plugins_priority[priority] = [name]
    weechat.infolist_free(infolist)
    return plugins_priority
Exemple #43
0
def get_infolists():
    """
    Get list of infolists hooked by plugins in a dict with 3 indexes:
    plugin, name, xxx.
    """
    infolists = defaultdict(lambda: defaultdict(defaultdict))
    infolist = weechat.infolist_get('hook', '', 'infolist')
    while weechat.infolist_next(infolist):
        infolist_name = weechat.infolist_string(infolist, 'infolist_name')
        plugin = weechat.infolist_string(infolist, 'plugin_name') or 'weechat'
        for key in ('description', 'pointer_description', 'args_description'):
            infolists[plugin][infolist_name][key] = \
                weechat.infolist_string(infolist, key)
    weechat.infolist_free(infolist)
    return infolists
Exemple #44
0
def get_completions():
    """Get list of completions hooked by plugins in a dict with 3 indexes: plugin, item, xxx."""
    global ignore_completions_items
    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
Exemple #45
0
def get_userhost_from_nick(buffer, nick):
    """Return host of a given nick in buffer."""
    channel = weechat.buffer_get_string(buffer, 'localvar_channel')
    server = weechat.buffer_get_string(buffer, 'localvar_server')
    if channel and server:
        infolist = weechat.infolist_get('irc_nick', '', '%s,%s' %(server, channel))
        if infolist:
            try:
                while weechat.infolist_next(infolist):
                    name = weechat.infolist_string(infolist, 'name')
                    if nick == name:
                        return weechat.infolist_string(infolist, 'host')
            finally:
                weechat.infolist_free(infolist)
    return ''
Exemple #46
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
Exemple #47
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
Exemple #48
0
def relay_check():
    check_relays = w.config_string_to_boolean(
        w.config_get_plugin('ignore_on_relay'))

    if not check_relays:
        return False

    infolist = w.infolist_get('relay', '', '')
    if infolist:
        while w.infolist_next(infolist):
            status = w.infolist_string(infolist, 'status_string')
            if status == 'connected':
                return True
        w.infolist_free(infolist)

    return False
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
Exemple #50
0
def get_buffer_by_name(buffer_name):
    """Given a buffer name returns its buffer pointer or None."""
    #debug('get_buffer_by_name: searching for %s' %buffer_name)
    pointer = weechat.buffer_search('', buffer_name)
    if not pointer:
        infolist = weechat.infolist_get('buffer', '', '')
        while weechat.infolist_next(infolist) and not pointer:
            name = weechat.infolist_string(infolist, 'name')
            if buffer_name in name:
                #debug('get_buffer_by_name: found %s' %name)
                pointer = weechat.buffer_search('', name)
        weechat.infolist_free(infolist)
    #debug('get_buffer_by_name: got %s' %pointer)
    if pointer:
        return pointer
    return None
Exemple #51
0
def lb_check_outside_window():
    global lb_buffer, lb_curline
    if (lb_buffer):
        infolist = weechat.infolist_get("window", "", "current")
        if (weechat.infolist_next(infolist)):
            start_line_y = weechat.infolist_integer(infolist, "start_line_y")
            chat_height = weechat.infolist_integer(infolist, "chat_height")
            if (start_line_y > lb_curline):
                weechat.command(
                    lb_buffer,
                    "/window scroll -%i" % (start_line_y - lb_curline))
            elif (start_line_y <= lb_curline - chat_height):
                weechat.command(
                    lb_buffer, "/window scroll +%i" %
                    (lb_curline - start_line_y - chat_height + 1))
        weechat.infolist_free(infolist)
Exemple #52
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
Exemple #53
0
def ugCheckLineOutsideWindow():
    global urlGrab, urlGrabSettings, urlgrab_buffer, current_line, max_buffer_length
    if (urlgrab_buffer):
        infolist = weechat.infolist_get("window", "", "current")
        if (weechat.infolist_next(infolist)):
            start_line_y = weechat.infolist_integer(infolist, "start_line_y")
            chat_height = weechat.infolist_integer(infolist, "chat_height")
            if (start_line_y > current_line):
                weechat.command(
                    urlgrab_buffer,
                    "/window scroll -%i" % (start_line_y - current_line))
            elif (start_line_y <= current_line - chat_height):
                weechat.command(
                    urlgrab_buffer, "/window scroll +%i" %
                    (current_line - start_line_y - chat_height + 1))
        weechat.infolist_free(infolist)
Exemple #54
0
def get_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
Exemple #55
0
 def _read_api_infos():
     """
     Get list of WeeChat/plugins infos as dictionary with 3 indexes:
     plugin, name, xxx.
     """
     infos = defaultdict(lambda: defaultdict(defaultdict))
     infolist = weechat.infolist_get('hook', '', 'info')
     while weechat.infolist_next(infolist):
         info_name = weechat.infolist_string(infolist, 'info_name')
         plugin = (weechat.infolist_string(infolist, 'plugin_name')
                   or 'weechat')
         for key in ('description', 'args_description'):
             infos[plugin][info_name][key] = \
                 weechat.infolist_string(infolist, key)
     weechat.infolist_free(infolist)
     return infos
Exemple #56
0
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
Exemple #57
0
def infolist_relay():
    infolist_relay = weechat.infolist_get('relay', '', '')
    if infolist_relay:
        while weechat.infolist_next(infolist_relay):
            status = weechat.infolist_integer(infolist_relay, 'status')
            status_string = weechat.infolist_string(infolist_relay,
                                                    'status_string')
#            weechat.prnt('', '%d %s' % (status, status_string))
        weechat.infolist_free(
            infolist_relay)  # don't forget to free() infolist!
    return weechat.WEECHAT_RC_OK

    #
    # =============================[ localvars() ]============================
    weechat.buffer_set(buffer, 'localvar_set_<name_of_localvar>', '%s' % value)
    weechat.buffer_get_string(buffer, 'localvar_<name_of_localvar>')
Exemple #58
0
def get_buffer_history(ptr_buffer):
    global history_list

    history_list = []
    ptr_buffer_history = weechat.infolist_get('history', ptr_buffer, '')

    if not ptr_buffer_history:
        return

    while weechat.infolist_next(ptr_buffer_history):
        line = weechat.infolist_string(ptr_buffer_history, 'text')

        if add_buffer_line(line, ptr_buffer):
            history_list.insert(0, line)

    weechat.infolist_free(ptr_buffer_history)
Exemple #59
0
def screen_away_timer_cb(buffer, args):
    '''Check if screen is attached, update awayness'''

    global AWAY, SOCK, CONNECTED_RELAY

    set_away = w.config_string_to_boolean(w.config_get_plugin('set_away'))
    check_relays = not w.config_string_to_boolean(w.config_get_plugin('ignore_relays'))
    suffix = w.config_get_plugin('away_suffix')
    attached = os.access(SOCK, os.X_OK) # X bit indicates attached

    # Check wether a client is connected on relay or not
    CONNECTED_RELAY = False
    if check_relays:
        infolist = w.infolist_get('relay', '', '')
        if infolist:
            while w.infolist_next(infolist):
                status = w.infolist_string(infolist, 'status_string')
                if status == 'connected':
                    CONNECTED_RELAY = True
                    break
            w.infolist_free(infolist)

    if (attached and AWAY) or (check_relays and CONNECTED_RELAY and not attached and AWAY):
        w.prnt('', '%s: Screen attached. Clearing away status' % SCRIPT_NAME)
        for server, nick in get_servers():
            if set_away:
                w.command(server,  "/away")
            if suffix and nick.endswith(suffix):
                nick = nick[:-len(suffix)]
                w.command(server,  "/nick %s" % nick)
        AWAY = False
        for cmd in w.config_get_plugin("command_on_attach").split(";"):
            w.command("", cmd)

    elif not attached and not AWAY:
        if not CONNECTED_RELAY:
            w.prnt('', '%s: Screen detached. Setting away status' % SCRIPT_NAME)
            for server, nick in get_servers():
                if suffix and not nick.endswith(suffix):
                    w.command(server, "/nick %s%s" % (nick, suffix));
                if set_away:
                    w.command(server, "/away %s" % w.config_get_plugin('message'));
            AWAY = True
            for cmd in w.config_get_plugin("command_on_detach").split(";"):
                w.command("", cmd)

    return w.WEECHAT_RC_OK
Exemple #60
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