def remove_group_options(data, buffer, argList):
    intRequiredArgs = 1
    split_args = argList.split(" ")
    num_of_args = len(split_args)
    
    if not argList:
        #print_help()
        w.prnt("", w.prefix("error") + "No arguments supplied.")
        return w.WEECHAT_RC_ERROR
        
    if num_of_args != intRequiredArgs:
        #print_help()
        w.prnt("", w.prefix("error") + "Wrong number of arguments. Supplied: " + str(num_of_args) + ", required: " + intRequiredArgs + ".")
        return w.WEECHAT_RC_ERROR
    
    GroupName = split_args[0]
    
    infolist = w.infolist_get("option", "", SETTINGS_PREFIX + GroupName + ".*")

    counter = 0
    
    if infolist:
        while w.infolist_next(infolist):
            name = w.infolist_string(infolist, "option_name")
            name = name.replace("python." + SCRIPT_NAME + ".", "")
            w.prnt("", "Removing option: " + name)
            w.config_unset_plugin(name)
            counter += 1

    w.infolist_free(infolist)
            
    if counter == 0:
        w.prnt("", w.prefix("error") + "No group name found called '" + GroupName + "'.")
    
    return w.WEECHAT_RC_OK
Example #2
0
def main():
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
        version = int(weechat.info_get("version_number", "")) or 0

        # unset unused setting from older versions of script
        if weechat.config_is_set_plugin("display_unit"):
            weechat.prnt("", "Option plugins.var.python.bandwidth.display_unit no longer used, removing.")
            weechat.config_unset_plugin("display_unit")

        # set default settings
        for option in SCRIPT_SETTINGS.iterkeys():
            if not weechat.config_is_set_plugin(option):
                weechat.config_set_plugin(option, SCRIPT_SETTINGS[option][0])
            if version >= 0x00030500:
                weechat.config_set_desc_plugin(option, SCRIPT_SETTINGS[option][1])

        # ensure sane refresh_rate setting
        if int(weechat.config_get_plugin("refresh_rate")) < 1:
            weechat.prnt(
                "",
                "{}Invalid value for option plugins.var.python.bandwidth.refresh_rate, setting to default of {}".format(
                    weechat.prefix("error"), SCRIPT_SETTINGS["refresh_rate"][0]
                ),
            )
            weechat.config_set_plugin("refresh_rate", SCRIPT_SETTINGS["refresh_rate"][0])

        # create the bandwidth monitor bar item
        weechat.bar_item_new("bandwidth", "bandwidth_item_cb", "")
        # update it every plugins.var.python.bandwidth.refresh_rate seconds
        weechat.hook_timer(int(weechat.config_get_plugin("refresh_rate")) * 1000, 0, 0, "bandwidth_timer_cb", "")
Example #3
0
def load_settings(data, option, value):
    """load all settings"""
    infobar['enabled'] = _load_setting('infobar_enabled', 'off', 'bool')
    infobar['format'] = _load_setting('infobar_format',
                                      'Now Playing: %mocTitle%')
    infobar['update'] = _load_setting('infobar_update', '10', 'int')
    output['format'] = _load_setting(
        'output_format',
        '/me is listening to %C04%title%%C %artist%%album%::: %C07%file%%C ::: %cTime%/%tTime% @ %bitrate%'
    )
    output['artist'] = _load_setting('output_format_artist',
                                     '- %C03%artist%%C ')
    output['album'] = _load_setting('output_format_album', '(%C12%album%%C) ')
    output['nothing'] = _load_setting('output_nothing',
                                      '/me is listening to nothing')

    #update config for 1.6 (i|o|ot -> +/me)
    if weechat.config_is_set_plugin('output_type'):
        if weechat.config_get_plugin('output_type') == 'ot':
            weechat.config_set_plugin('output_format',
                                      "/me " + output['format'])
            weechat.config_set_plugin('output_nothing',
                                      "/me " + output['nothing'])
            output['format'] = "/me " + output['format']
            output['nothing'] = "/me " + output['nothing']
        weechat.config_unset_plugin('output_type')

    return weechat.WEECHAT_RC_OK
Example #4
0
def main():
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
        version = int(weechat.info_get('version_number', '')) or 0

        # unset unused setting from older versions of script
        if weechat.config_is_set_plugin('display_unit'):
            weechat.prnt("", "Option plugins.var.python.bandwidth.display_unit no longer used, removing.")
            weechat.config_unset_plugin('display_unit')

        # set default settings
        for option in SCRIPT_SETTINGS.keys():
            if not weechat.config_is_set_plugin(option):
                value = SCRIPT_SETTINGS[option][0]
                if isinstance(value, str):
                    pass
                elif isinstance(value, bytes):
                    pass
                elif isinstance(value, unicode):
                    value = value.encode('utf8')
                weechat.config_set_plugin(option, value)
            if version >= 0x00030500:
                weechat.config_set_desc_plugin(option, SCRIPT_SETTINGS[option][1])

        # ensure sane refresh_rate setting
        if int(weechat.config_get_plugin('refresh_rate')) < 1:
            weechat.prnt("", "{}Invalid value for option plugins.var.python.bandwidth.refresh_rate, setting to default of {}".format(weechat.prefix("error"), SCRIPT_SETTINGS['refresh_rate'][0]))
            weechat.config_set_plugin('refresh_rate', SCRIPT_SETTINGS['refresh_rate'][0])

        # create the bandwidth monitor bar item
        weechat.bar_item_new('bandwidth', 'bandwidth_item_cb', '')
        # update it every plugins.var.python.bandwidth.refresh_rate seconds
        weechat.hook_timer(int(weechat.config_get_plugin('refresh_rate'))*1000, 0, 0, 'bandwidth_timer_cb', '')
Example #5
0
 def __update(self):
     self._updated = True
     self.readDB()
     # import and remove old warn configs
     infolist = Infolist('option', 'plugins.var.%s.*' % self._config)
     n = len(self._config) + 1
     for opt in infolist:
         pattern = opt['option_name'][n:]
         comment = opt['value']
         self.add(pattern, comment=comment)
         weechat.config_unset_plugin('mask.%s' % pattern)
Example #6
0
 def __update(self):
     self._updated = True
     self.readDB()
     # import and remove old warn configs
     infolist = Infolist('option', 'plugins.var.%s.*' % self._config)
     n = len(self._config) + 1
     for opt in infolist:
         pattern = opt['option_name'][n:]
         comment = opt['value']
         self.add(pattern, comment=comment)
         weechat.config_unset_plugin('mask.%s' % pattern)
Example #7
0
def free_options_cb(all_conf=True):
    #weechat.unhook_all()
    for instance in TRIV['instances']['launched'].keys():
        for option in TRIV['default_instance_options'].keys():
            TRIV['rc']['instance.' + instance + '.' + option] = weechat.config_unset_plugin('instance.' + instance + '.' + option)
    if all_conf:
        TRIV['rc']['instances'] = weechat.config_unset_plugin('ids')
    for option,value in TRIV['rc'].items():
        if value == weechat.WEECHAT_CONFIG_OPTION_UNSET_ERROR:
            return weechat.WEECHAT_RC_ERROR
    return weechat.WEECHAT_RC_OK
Example #8
0
def free_options_cb(all_conf=True):
    #weechat.unhook_all()
    for instance in TRIV['instances']['launched'].keys():
        for option in TRIV['default_instance_options'].keys():
            TRIV['rc']['instance.' + instance + '.' +
                       option] = weechat.config_unset_plugin('instance.' +
                                                             instance + '.' +
                                                             option)
    if all_conf:
        TRIV['rc']['instances'] = weechat.config_unset_plugin('ids')
    for option, value in TRIV['rc'].items():
        if value == weechat.WEECHAT_CONFIG_OPTION_UNSET_ERROR:
            return weechat.WEECHAT_RC_ERROR
    return weechat.WEECHAT_RC_OK
Example #9
0
def customize_cmd_cb(data, buffer, args):
    args = args.lower()
    argv = args.split(None)
    if (args == '') or (len(argv) != 2):
        return weechat.WEECHAT_RC_OK
    if argv[1] not in 'title status input':
        return weechat.WEECHAT_RC_OK

    full_name = weechat.buffer_get_string(buffer,'full_name')                           # get full_name of current buffer

    if argv[0] == 'add':
        if weechat.config_get_plugin('%s.%s' % (argv[1],full_name)):
            return weechat.WEECHAT_RC_OK
        else:
            default_plugin = weechat.config_get_plugin('default.%s' % (argv[1]))
            bar = weechat.config_set_plugin('%s.%s' % (argv[1],full_name),default_plugin)  # set default bar
    elif argv[0] == 'del':
        weechat.config_unset_plugin('%s.%s' % (argv[1],full_name))
    return weechat.WEECHAT_RC_OK
Example #10
0
def load_settings(data, option, value):
    """load all settings"""
    infobar['enabled'] = _load_setting('infobar_enabled', 'off', 'bool')
    infobar['format']  = _load_setting('infobar_format', 'Now Playing: %mocTitle%')
    infobar['update']  = _load_setting('infobar_update', '10', 'int')
    output['format']   = _load_setting('output_format', '/me is listening to %C04%title%%C %artist%%album%::: %C07%file%%C ::: %cTime%/%tTime% @ %bitrate%')
    output['artist']   = _load_setting('output_format_artist', '- %C03%artist%%C ')
    output['album']    = _load_setting('output_format_album', '(%C12%album%%C) ')
    output['nothing']  = _load_setting('output_nothing', '/me is listening to nothing')

    #update config for 1.6 (i|o|ot -> +/me)
    if weechat.config_is_set_plugin('output_type'):
        if weechat.config_get_plugin('output_type') == 'ot':
            weechat.config_set_plugin('output_format', "/me " + output['format'])
            weechat.config_set_plugin('output_nothing', "/me " + output['nothing'])
            output['format'] = "/me " + output['format']
            output['nothing'] = "/me " + output['nothing']
        weechat.config_unset_plugin('output_type')

    return weechat.WEECHAT_RC_OK
Example #11
0
def customize_cmd_cb(data, buffer, args):
    args = args.lower()
    argv = args.split(None)
    if (args == '') or (len(argv) != 2):
        return weechat.WEECHAT_RC_OK
    if argv[1] not in 'title status input':
        return weechat.WEECHAT_RC_OK

    full_name = weechat.buffer_get_string(
        buffer, 'full_name')  # get full_name of current buffer

    if argv[0] == 'add':
        if weechat.config_get_plugin('%s.%s' % (argv[1], full_name)):
            return weechat.WEECHAT_RC_OK
        else:
            default_plugin = weechat.config_get_plugin('default.%s' %
                                                       (argv[1]))
            bar = weechat.config_set_plugin('%s.%s' % (argv[1], full_name),
                                            default_plugin)  # set default bar
    elif argv[0] == 'del':
        weechat.config_unset_plugin('%s.%s' % (argv[1], full_name))
    return weechat.WEECHAT_RC_OK
def rlayout_cmd_cb(data, buffer, args):
    """
    Callback for /rlayout command.
    """
    if args == "":
        weechat.command("", "/help %s" % SCRIPT_COMMAND)
        return weechat.WEECHAT_RC_OK

    argv = args.strip().split(" ", 1)
    if len(argv) == 0:
        return weechat.WEECHAT_RC_OK

    short_cmds = ["list", "terminal"]
    if argv[0] not in short_cmds and len(argv) < 2:
        _print("Too few arguments for option '%s'." % argv[0])
        return weechat.WEECHAT_RC_OK

    if argv[0] == "size":
        try:
            layout, width, height = argv[1].split(" ")

            if layout_exist(layout):
                weechat.config_set_plugin("layout.%s.width" % layout, width)
                weechat.config_set_plugin("layout.%s.height" % layout, height)
                update_layout_list()
            else:
                _print(
                    "Layout '%s' doesn't exist, see /help layout to create one."
                    % layout)
        except ValueError:
            _print("Too few arguments for option '%s'" % argv[0])
    elif argv[0] == "nicklist":
        try:
            layout, nicklist = argv[1].split(" ")

            if layout_exist(layout):
                if nicklist == "on" or nicklist == "off":
                    weechat.config_set_plugin("layout.%s.nicklist" % layout,
                                              nicklist)
                else:
                    _print("Invalid argument '%s' for option '%s'." %
                           (nicklist, argv[0]))
            else:
                _print(
                    "Layout '%s' doesn't exist, see /help layout to create one."
                    % layout)
        except ValueError:
            _print("Too few arguments for option '%s'" % argv[0])
    elif argv[0] == "default_nicklist" or argv[0] == "debug":
        if argv[1] == "on" or argv[1] == "off":
            weechat.config_set_plugin(argv[0], argv[1])
        else:
            _print("Invalid argument '%s' for option '%s'" %
                   (argv[1], argv[0]))
    elif argv[0] == "remove":
        if argv[1] in rlayouts_list():
            for option in ["width", "height", "nicklist"]:
                weechat.config_unset_plugin("layout.%s.%s" % (argv[1], option))
            _print("Removed rlayout '%s'" % argv[1])
        else:
            _print("Could not remove '%s', rlayout not found." % argv[1])
    elif argv[0] == "list":
        if len(rlayouts_list()) == 0:
            _print("No configuration set.")
        else:
            for rlayout in rlayouts_list():
                width = weechat.config_get_plugin("layout.%s.width" % rlayout)
                height = weechat.config_get_plugin("layout.%s.height" %
                                                   rlayout)
                nicklist = weechat.config_get_plugin("layout.%s.nicklist" %
                                                     rlayout)
                msg = "[%s] width: %s, height: %s" % (rlayout, width, height)
                if nicklist is not "":
                    msg += ", nicklist: %s" % nicklist
                _print(msg)
    elif argv[0] == "terminal":
        term_height = int(weechat.info_get("term_height", ""))
        term_width = int(weechat.info_get("term_width", ""))
        _print("Current terminal width x height is: %s x %s" %
               (term_width, term_height))

    return weechat.WEECHAT_RC_OK
Example #13
0
def command(data, buffer, args):
    global join_hook
    if not args:
        args = 'list'

    channel = weechat.buffer_get_string(buffer, 'localvar_channel')
    server = weechat.buffer_get_string(buffer, 'localvar_server')

    args = args.split()
    cmd = args[0]
    try:
        if cmd in ('add', 'del'):
            if not weechat.info_get('irc_is_channel', channel):
                error("Not an IRC channel buffer.")
                return WEECHAT_RC_OK

            type, match = args[1], args[2:]
            if type not in ('op', 'voice', 'halfop'):
                raise ValueError(
                    "valid values are 'op', 'halfop' and 'voice'.")
            if not match:
                raise ValueError("missing pattern or nick.")
            match = match[0].lower()
            config = '.'.join((server, channel.lower(), type))
            L = get_config_list(config)

            if cmd == 'add':
                # check if pattern is a nick
                if weechat.info_get('irc_is_nick', match):
                    userhost = get_userhost(server, channel, match)
                    if userhost:
                        match = userhost.lower()
                nicks = find_matching_users(server, channel, match)
                n = len(nicks)
                if n == 0:
                    say("'%s' added, matches 0 users." % match, buffer)
                elif n == 1:
                    say("'%s' added, matches 1 user: %s" % (match, nicks[0]),
                        buffer)
                elif n > 1:
                    say(
                        "'%s' added, matches %s%s%s users: %s" %
                        (match, weechat.color('lightred'), n, color_reset,
                         ' '.join(nicks)), buffer)
                if match not in L:
                    L.append(match)
            elif cmd == 'del':
                if match not in L:
                    say("'%s' not found in %s.%s" % (match, server, channel),
                        buffer)
                else:
                    say("'%s' removed." % match, buffer)
                    del L[L.index(match)]

            if L:
                weechat.config_set_plugin(config, ','.join(L))
            else:
                weechat.config_unset_plugin(config)

        elif cmd == 'disable':
            if join_hook:
                weechat.unhook(join_hook)
            weechat.config_set_plugin('enabled', 'off')
            say("%s script disabled." % SCRIPT_NAME, buffer)
        elif cmd == 'enable':
            if join_hook:
                weechat.unhook(join_hook)
            join_hook = weechat.hook_signal('*,irc_in_join', 'join_cb', '')
            weechat.config_set_plugin('enabled', 'on')
            say("%s script enabled." % SCRIPT_NAME, buffer)
        elif cmd == 'list':
            if weechat.info_get('irc_is_channel', channel):
                filter = '%s.%s.*' % (server, channel)
            else:
                filter = '*'
                buffer = ''  # print in core buffer
            if not get_config_boolean('enabled'):
                say('Automodes currently disabled.', buffer)
            patterns = get_patterns_in_config(filter)
            if not patterns:
                if buffer:
                    say('No automodes for %s.' % channel, buffer)
                else:
                    say('No automodes.', buffer)
                return WEECHAT_RC_OK
            for key, items in patterns.iteritems():
                say(
                    '%s[%s%s.%s%s]' %
                    (color_chat_delimiters, color_chat_buffer, key[0], key[1],
                     color_chat_delimiters), buffer)
                for type, masks in items.iteritems():
                    for mask in masks:
                        say(
                            '  %s%s%s: %s%s' %
                            (color_chat_nick, type, color_chat_delimiters,
                             color_reset, mask), buffer)
        else:
            raise ValueError("'%s' isn't a valid option. See /help %s" %
                             (cmd, SCRIPT_NAME))
    except ValueError, e:
        error('Bad argument: %s' % e)
        return WEECHAT_RC_OK
Example #14
0
def command(data, buffer, args):
    global join_hook
    if not args:
        args = 'list'

    channel = weechat.buffer_get_string(buffer, 'localvar_channel')
    server = weechat.buffer_get_string(buffer, 'localvar_server')

    args = args.split()
    cmd = args[0]
    try:
        if cmd in ('add', 'del'):
            if not weechat.info_get('irc_is_channel', channel):
                error("Not an IRC channel buffer.")
                return WEECHAT_RC_OK

            type, match = args[1], args[2:]
            if type not in ('op', 'voice', 'halfop'):
                raise ValueError("valid values are 'op', 'halfop' and 'voice'.")
            if not match:
                raise ValueError("missing pattern or nick.")
            match = match[0].lower()
            config = '.'.join((server, channel.lower(), type))
            L = get_config_list(config)

            if cmd == 'add':
                # check if pattern is a nick
                if weechat.info_get('irc_is_nick', match):
                    userhost = get_userhost(server, channel, match)
                    if userhost:
                        match = userhost.lower()
                nicks = find_matching_users(server, channel, match)
                n = len(nicks)
                if n == 0:
                    say("'%s' added, matches 0 users." %match, buffer)
                elif n == 1:
                    say("'%s' added, matches 1 user: %s" %(match, nicks[0]),
                            buffer)
                elif n > 1:
                    say("'%s' added, matches %s%s%s users: %s" %(
                        match, weechat.color('lightred'), n, color_reset,
                        ' '.join(nicks)), buffer)
                if match not in L:
                    L.append(match)
            elif cmd == 'del':
                    if match not in L:
                        say("'%s' not found in %s.%s" %(match, server, channel), buffer)
                    else:
                        say("'%s' removed." %match, buffer)
                        del L[L.index(match)]

            if L:
                weechat.config_set_plugin(config, ','.join(L))
            else:
                weechat.config_unset_plugin(config)

        elif cmd == 'disable':
            if join_hook:
                weechat.unhook(join_hook)
            weechat.config_set_plugin('enabled', 'off')
            say("%s script disabled." %SCRIPT_NAME, buffer)
        elif cmd == 'enable':
            if join_hook:
                weechat.unhook(join_hook)
            join_hook = weechat.hook_signal('*,irc_in_join', 'join_cb', '')
            weechat.config_set_plugin('enabled', 'on')
            say("%s script enabled." %SCRIPT_NAME, buffer)
        elif cmd == 'list':
            if weechat.info_get('irc_is_channel', channel):
                filter = '%s.%s.*' %(server, channel)
            else:
                filter = '*'
                buffer = '' # print in core buffer
            if not get_config_boolean('enabled'):
                say('Automodes currently disabled.', buffer)
            patterns = get_patterns_in_config(filter)
            if not patterns:
                if buffer:
                    say('No automodes for %s.' %channel, buffer)
                else:
                    say('No automodes.', buffer)
                return WEECHAT_RC_OK
            for key, items in patterns.items():
                say('%s[%s%s.%s%s]' %(color_chat_delimiters,
                                      color_chat_buffer,
                                      key[0], key[1],
                                      color_chat_delimiters), buffer)
                for type, masks in items.items():
                    for mask in masks:
                        say('  %s%s%s: %s%s' %(color_chat_nick, type,
                                               color_chat_delimiters,
                                               color_reset,
                                               mask), buffer)
        else:
            raise ValueError("'%s' isn't a valid option. See /help %s" %(cmd, SCRIPT_NAME))
    except ValueError as e:
        error('Bad argument: %s' %e)
        return WEECHAT_RC_OK

    return WEECHAT_RC_OK
Example #15
0
def rlayout_cmd_cb(data, buffer, args):
    """
    Callback for /rlayout command.
    """
    if args == "":
        weechat.command("", "/help %s" % SCRIPT_COMMAND)
        return weechat.WEECHAT_RC_OK

    argv = args.strip().split(" ", 1)
    if len(argv) == 0:
        return weechat.WEECHAT_RC_OK

    short_cmds = ["list", "terminal"]
    if argv[0] not in short_cmds and len(argv) < 2:
        _print("Too few arguments for option '%s'." % argv[0])
        return weechat.WEECHAT_RC_OK

    if argv[0] == "size":
        try:
            layout, width, height = argv[1].split(" ")

            if layout_exist(layout):
                weechat.config_set_plugin("layout.%s.width" % layout, width)
                weechat.config_set_plugin("layout.%s.height" % layout, height)
                update_layout_list()
            else:
                _print("Layout '%s' doesn't exist, see /help layout to create one." % layout)
        except ValueError:
            _print("Too few arguments for option '%s'" % argv[0])
    elif argv[0] == "nicklist":
        try:
            layout, nicklist = argv[1].split(" ")

            if layout_exist(layout):
                if nicklist == "on" or nicklist == "off":
                    weechat.config_set_plugin("layout.%s.nicklist" % layout, nicklist)
                else:
                    _print("Invalid argument '%s' for option '%s'." % (nicklist, argv[0]))
            else:
                _print("Layout '%s' doesn't exist, see /help layout to create one." % layout)
        except ValueError:
            _print("Too few arguments for option '%s'" % argv[0])
    elif argv[0] == "default_nicklist" or argv[0] == "debug":
        if argv[1] == "on" or argv[1] == "off":
            weechat.config_set_plugin(argv[0], argv[1])
        else:
            _print("Invalid argument '%s' for option '%s'" % (argv[1], argv[0]))
    elif argv[0] == "remove":
        if argv[1] in rlayouts_list():
            for option in ["width", "height", "nicklist"]:
                weechat.config_unset_plugin("layout.%s.%s" % (argv[1], option))
            _print("Removed rlayout '%s'" % argv[1])
        else:
            _print("Could not remove '%s', rlayout not found." % argv[1])
    elif argv[0] == "list":
        if len(rlayouts_list()) == 0:
            _print("No configuration set.")
        else:
            for rlayout in rlayouts_list():
                width = weechat.config_get_plugin("layout.%s.width" % rlayout)
                height = weechat.config_get_plugin("layout.%s.height" % rlayout)
                nicklist = weechat.config_get_plugin("layout.%s.nicklist" % rlayout)
                msg = "[%s] width: %s, height: %s" % (rlayout, width, height)
                if nicklist is not "":
                    msg += ", nicklist: %s" % nicklist
                _print(msg)
    elif argv[0] == "terminal":
        term_height = int(weechat.info_get("term_height", ""))
        term_width = int(weechat.info_get("term_width", ""))
        _print("Current terminal width x height is: %s x %s" % (term_width, term_height))

    return weechat.WEECHAT_RC_OK
Example #16
0
def command(data, buffer, args):
    global join_hook
    if not args:
        args = "list"

    channel = weechat.buffer_get_string(buffer, "localvar_channel")
    server = weechat.buffer_get_string(buffer, "localvar_server")

    args = args.split()
    cmd = args[0]
    try:
        if cmd in ("add", "del"):
            if not weechat.info_get("irc_is_channel", channel):
                error("Not an IRC channel buffer.")
                return WEECHAT_RC_OK

            type, match = args[1], args[2:]
            if type not in ("op", "voice", "halfop"):
                raise ValueError("valid values are 'op', 'halfop' and 'voice'.")
            if not match:
                raise ValueError("missing pattern or nick.")
            match = match[0].lower()
            config = ".".join((server, channel.lower(), type))
            L = get_config_list(config)

            if cmd == "add":
                # check if pattern is a nick
                if weechat.info_get("irc_is_nick", match):
                    userhost = get_userhost(server, channel, match)
                    if userhost:
                        match = userhost.lower()
                nicks = find_matching_users(server, channel, match)
                n = len(nicks)
                if n == 0:
                    say("'%s' added, matches 0 users." % match, buffer)
                elif n == 1:
                    say("'%s' added, matches 1 user: %s" % (match, nicks[0]), buffer)
                elif n > 1:
                    say(
                        "'%s' added, matches %s%s%s users: %s"
                        % (match, weechat.color("lightred"), n, color_reset, " ".join(nicks)),
                        buffer,
                    )
                if match not in L:
                    L.append(match)
            elif cmd == "del":
                if match not in L:
                    say("'%s' not found in %s.%s" % (match, server, channel), buffer)
                else:
                    say("'%s' removed." % match, buffer)
                    del L[L.index(match)]

            if L:
                weechat.config_set_plugin(config, ",".join(L))
            else:
                weechat.config_unset_plugin(config)

        elif cmd == "disable":
            if join_hook:
                weechat.unhook(join_hook)
            weechat.config_set_plugin("enabled", "off")
            say("%s script disabled." % SCRIPT_NAME, buffer)
        elif cmd == "enable":
            if join_hook:
                weechat.unhook(join_hook)
            join_hook = weechat.hook_signal("*,irc_in_join", "join_cb", "")
            weechat.config_set_plugin("enabled", "on")
            say("%s script enabled." % SCRIPT_NAME, buffer)
        elif cmd == "list":
            if weechat.info_get("irc_is_channel", channel):
                filter = "%s.%s.*" % (server, channel)
            else:
                filter = "*"
                buffer = ""  # print in core buffer
            if not get_config_boolean("enabled"):
                say("Automodes currently disabled.", buffer)
            patterns = get_patterns_in_config(filter)
            if not patterns:
                if buffer:
                    say("No automodes for %s." % channel, buffer)
                else:
                    say("No automodes.", buffer)
                return WEECHAT_RC_OK
            for key, items in patterns.iteritems():
                say(
                    "%s[%s%s.%s%s]" % (color_chat_delimiters, color_chat_buffer, key[0], key[1], color_chat_delimiters),
                    buffer,
                )
                for type, masks in items.iteritems():
                    for mask in masks:
                        say(
                            "  %s%s%s: %s%s" % (color_chat_nick, type, color_chat_delimiters, color_reset, mask), buffer
                        )
        else:
            raise ValueError("'%s' isn't a valid option. See /help %s" % (cmd, SCRIPT_NAME))
    except ValueError, e:
        error("Bad argument: %s" % e)
        return WEECHAT_RC_OK
Example #17
0
 def tearDown(self):
     if weechat.config_is_set_plugin(self.config_name):
         weechat.config_unset_plugin(self.config_name)