示例#1
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", "")
示例#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.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', '')
示例#3
0
def config(*args, **kwargs):
    if not wc.config_is_set_plugin('channels'):
        wc.config_set_plugin('channels', '.*')
    if not wc.config_is_set_plugin('api_key'):
        wc.config_set_plugin('api_key', 'not_set')
    if not wc.config_is_set_plugin('other_bots'):
        wc.config_set_plugin('other_bots', 'not_set')
    return wc.WEECHAT_RC_OK
示例#4
0
def init_options():
    """Initialize global options dict from client."""
    global OPTIONS
    for opt, attr in DEFAULT_OPTIONS.items():
        xchat_opt = '_'.join((__module_name__, opt))
        if isinstance(attr[1], str):
            value = attr[1]
        else:
            value = ' '.join(attr[1])

        desc = '{} (default: "{}")'.format(attr[0], value)
        if WEECHAT:
            weechat.config_set_desc_plugin(opt, desc)
            plugin_pref = weechat.config_is_set_plugin(opt)
        else:
            cmd_name = ''.join(('WVM', opt.upper()))
            xchat.hook_command(cmd_name,
                               xchat_update_option_cb,
                               userdata=opt,
                               help='/{} -- {}'.format(cmd_name, desc))
            plugin_pref = xchat.get_pluginpref(xchat_opt)

        if plugin_pref:
            value = weechat.config_get_plugin(opt) if WEECHAT else \
                    xchat.get_pluginpref(xchat_opt)
            if not isinstance(DEFAULT_OPTIONS[opt][1], str):
                value = list(map(str.strip, value.split()))
            set_option(opt, value)
        else:
            if WEECHAT:
                weechat.config_set_plugin(opt, value)
            else:
                xchat.set_pluginpref(xchat_opt, value)
            set_option(opt, attr[1])
示例#5
0
文件: mnotify.py 项目: mmaker/mnotify
def main():
    '''Sets up WeeChat notifications.'''
    # Initialize options.
    for option, value in SETTINGS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value)
    # Initialize.
    notifications = [
        'Public',
        'Private',
        'Action',
        'Notice',
        'Invite',
        'Highlight',
        'Server',
        'Channel',
        'DCC',
        'WeeChat'
    ]
    # Register hooks.
    weechat.hook_signal(
        'irc_server_connected',
        'cb_irc_server_connected',
        '')
    weechat.hook_signal(
        'irc_server_disconnected',
        'cb_irc_server_disconnected',
        '')
    weechat.hook_signal('upgrade_ended', 'cb_upgrade_ended', '')
    weechat.hook_print('', '', '', 1, 'cb_process_message', '')
示例#6
0
def urlscan(data, buf, args):
    infolist = weechat.infolist_get("buffer_lines", buf, "")
    lines = []
    while weechat.infolist_next(infolist) == 1:
        lines.append(
            weechat.string_remove_color(
                weechat.infolist_string(infolist, "message"),
                ""
            )
        )

    weechat.infolist_free(infolist)

    if not lines:
        weechat.prnt(buf, "No URLs found")
        return weechat.WEECHAT_RC_OK

    if not weechat.config_is_set_plugin("command"):
        weechat.config_set_plugin("command", "urlscan")
    command = weechat.config_get_plugin("command")

    text = "\n".join(reversed(lines))
    response = os.system("echo %s | %s" % (pipes.quote(text), command))
    if response != 0:
        weechat.prnt(buf, "No URLs found")

    weechat.command(buf, "/window refresh")

    return weechat.WEECHAT_RC_OK
示例#7
0
def urlview(data, buf, args):
    infolist = weechat.infolist_get("buffer_lines", buf, "")
    lines = []
    while weechat.infolist_next(infolist) == 1:
        lines.append(
            weechat.string_remove_color(
                weechat.infolist_string(infolist, "message"),
                ""
            )
        )

    weechat.infolist_free(infolist)

    if not lines:
        weechat.prnt(buf, "No URLs found")
        return weechat.WEECHAT_RC_OK

    if not weechat.config_is_set_plugin("command"):
        weechat.config_set_plugin("command", "urlview")
    command = weechat.config_get_plugin("command")

    text = "\n".join(reversed(lines))
    response = os.system("echo %s | %s" % (pipes.quote(text), command))
    if response != 0:
        weechat.prnt(buf, "No URLs found")

    weechat.command(buf, "/window refresh")

    return weechat.WEECHAT_RC_OK
示例#8
0
    def __init__(self):
        """Weenotifier - initialization."""
        self.options = {
            'url': 'https://irssinotifier.appspot.com/API/Message',
            'token': '',
            'password': '******'
        }

        for option, value in self.options.items():
            if not weechat.config_is_set_plugin(option):
                weechat.config_set_plugin(option, value)

        self.url = weechat.config_get_plugin('url')
        if self.url is None or len(self.url) <= 0:
            raise NameError('weenotifier: url not configured')

        self.token = weechat.config_get_plugin('token')
        if self.token is None or len(self.token) <= 0:
            raise NameError('weenotifier: token not configured')

        self.password = weechat.config_get_plugin('password')
        if self.password is None or len(self.password) <= 0:
            raise NameError('weenotifier: password not configured')

        self.version = weechat.info_get('version_number', '') or '0'
        weechat.hook_print('', '', '', 1, 'message_cb', '')
示例#9
0
def main():
    '''Sets up WeeChat notifications.'''
    # Initialize options.
    for option, value in SETTINGS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value)
    # Initialize.
    name = "WeeChat"
    icon = "/usr/share/pixmaps/weechat.xpm"
    notifications = [
        'Public',
        'Private',
        'Action',
        'Notice',
        'Invite',
        'Highlight',
        'Server',
        'Channel',
        'DCC',
        'WeeChat'
    ]
    STATE['icon'] = icon
    # Register hooks.
    weechat.hook_signal(
        'irc_server_connected',
        'cb_irc_server_connected',
        '')
    weechat.hook_signal(
        'irc_server_disconnected',
        'cb_irc_server_disconnected',
        '')
    weechat.hook_signal('upgrade_ended', 'cb_upgrade_ended', '')
    weechat.hook_print('', '', '', 1, 'cb_process_message', '')
    weechat.hook_timer(1000, 1, 65535, "cb_buffer_tick", "")
    pynotify.init(name)
示例#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
示例#11
0
def main():
    '''Sets up WeeChat notifications.'''
    # Initialize options.
    for option, value in SETTINGS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value)
    # Initialize.
    notifications = [
        'Public',
        'Private',
        'Action',
        'Notice',
        'Invite',
        'Highlight',
        'Server',
        'Channel',
        'DCC',
        'WeeChat'
    ]
    # Register hooks.
    weechat.hook_signal(
        'irc_server_connected',
        'cb_irc_server_connected',
        '')
    weechat.hook_signal(
        'irc_server_disconnected',
        'cb_irc_server_disconnected',
        '')
    weechat.hook_signal('upgrade_ended', 'cb_upgrade_ended', '')
    weechat.hook_print('', '', '', 1, 'cb_process_message', '')
示例#12
0
def config_init():
    """Add configuration options to weechat."""
    global KEEP_ALIVE_TIMEOUT

    config = {
        "hide_inactive": ("off", "Hide inactive buffers"),
        "hide_private": ("off", "Hide private buffers"),
        "unhide_low":
        ("off",
         "Unhide a buffer when a low priority message (like JOIN, PART, etc.) has been received"
         ),
        "exemptions":
        ("", "An enumeration of buffers that should not get hidden"),
        "keep_open": ("off", "Keep a buffer open for a short amount of time"),
        "keep_open_timeout":
        ("60 * 1000",
         "Timeout in milliseconds for how long a selected buffer should be kept around"
         ),
    }
    for option, default_value in config.items():
        if weechat.config_get_plugin(option) == "":
            weechat.config_set_plugin(option, default_value[0])
        weechat.config_set_desc_plugin(
            option, '{} (default: "{}")'.format(default_value[1],
                                                default_value[0]))

    weechat.hook_config("plugins.var.python.buffer_autohide.keep_open_timeout",
                        "timeout_config_changed_cb", "")
    if weechat.config_is_set_plugin("keep_open_timeout"):
        KEEP_ALIVE_TIMEOUT = eval_expr(
            weechat.config_get_plugin("keep_open_timeout"))
示例#13
0
def init_config():
    global default_options, options
    for option, default_value in default_options.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default_value)
        options[option] = weechat.config_get_plugin(option)
    return weechat.WEECHAT_RC_OK
示例#14
0
def config_setup():
    for option,value in OPTIONS.items():
        weechat.config_set_desc_plugin(option, '%s' % value[1])
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value[0])
            OPTIONS[option] = value[0]
        else:
            if option == 'prefix_nicks' or option == 'debug' or option == 'ssl_verify' or option == 'notice_notify_block':
                OPTIONS[option] = weechat.config_string_to_boolean(
                    weechat.config_get_plugin(option))
            else:
                OPTIONS[option] = weechat.config_get_plugin(option)
            if option == 'debug':
                if value == 0:
                    curlopt['verbose'] = "0"
                else:
                    curlopt['verbose'] = "1"
            if option == 'ssl_verify':
                if value == 0:
                    curlopt['ssl_verifypeer'] = "0"
                    curlopt['ssl_verifyhost'] = "0"
                else:
                    curlopt['ssl_verifypeer'] = "1"
                    curlopt['ssl_verifyhost'] = "2"
            if option == 'client_id':
                curlopt['httpheader'] = "Client-ID: " + value[0]
示例#15
0
文件: go.py 项目: gilbertw1/scripts
def go_main():
    """Entry point."""
    if not weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                            SCRIPT_LICENSE, SCRIPT_DESC,
                            'go_unload_script', ''):
        return
    weechat.hook_command(
        SCRIPT_COMMAND,
        'Quick jump to buffers', '[term(s)]',
        'term(s): directly jump to buffer matching the provided term(s) single'
        'or space dilimited list (without argument, list is displayed)\n\n'
        'You can bind command to a key, for example:\n'
        '  /key bind meta-g /go\n\n'
        'You can use completion key (commonly Tab and shift-Tab) to select '
        'next/previous buffer in list.',
        '%(buffers_names)',
        'go_cmd', '')

    # set default settings
    version = weechat.info_get('version_number', '') or 0
    for option, value in SETTINGS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value[0])
        if int(version) >= 0x00030500:
            weechat.config_set_desc_plugin(
                option, '%s (default: "%s")' % (value[1], value[0]))
    weechat.hook_info('go_running',
                      'Return "1" if go is running, otherwise "0"',
                      '',
                      'go_info_running', '')
示例#16
0
def init_config():
    global OPTIONS
    for option, value in OPTIONS.items():
        weechat.config_set_desc_plugin(
            option, '%s (default: "%s")' % (value[1], value[0]))
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value[0])
示例#17
0
def Set_Instance_Options(instance):
    for option, value in TRIV['default_instance_options'].items():
        if not weechat.config_is_set_plugin('instance.' + instance + '.' +
                                            option):
            weechat.prnt('', instance + ' - ' + option + ' - ' + value)
            weechat.config_set_plugin('instance.' + instance + '.' + option,
                                      value)
示例#18
0
def load_config(data=None, option=None, value=None):
    """
    Load configuration options and (re)register hook_timer to clear old
    messages based on the current value of check_every.  If check_every is 0
    then messages are never cleared.
    """

    # On initial load set any unset options to the defaults.
    if not option:
        for option, default in settings.iteritems():
            if not weechat.config_is_set_plugin(option):
                weechat.config_set_plugin(option, default)

    if not option or option.endswith('check_every'):
        # If hook_timer for clearing old messages is set already, clear it.
        old_hook = globals().get('CLEAR_HOOK', None)
        if old_hook is not None:
            weechat.unhook(old_hook)

        # Register hook_timer to clear old messages.
        check_every = get_option_int('check_every') * 1000
        if check_every:
            globals()['CLEAR_HOOK'] = weechat.hook_timer(
                    check_every, 0, 0, 'clear_messages_cb', '')

    return weechat.WEECHAT_RC_OK
示例#19
0
def go_main():
    """Entry point."""
    if not weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                            SCRIPT_LICENSE, SCRIPT_DESC,
                            'go_unload_script', ''):
        return
    weechat.hook_command(
        SCRIPT_COMMAND,
        'Quick jump to buffers', '[name]',
        'name: directly jump to buffer by name (without argument, list is '
        'displayed)\n\n'
        'You can bind command to a key, for example:\n'
        '  /key bind meta-g /go\n\n'
        'You can use completion key (commonly Tab and shift-Tab) to select '
        'next/previous buffer in list.',
        '%(buffers_names)',
        'go_cmd', '')

    # set default settings
    version = weechat.info_get('version_number', '') or 0
    for option, value in SETTINGS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value[0])
        if int(version) >= 0x00030500:
            weechat.config_set_desc_plugin(
                option, '%s (default: "%s")' % (value[1], value[0]))
    weechat.hook_info('go_running',
                      'Return "1" if go is running, otherwise "0"',
                      '',
                      'go_info_running', '')
示例#20
0
def main():
    '''Sets up WeeChat Growl notifications.'''
    # Initialize options.
    for option, value in SETTINGS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value)
    # Initialize Growl.
    name = "WeeChat"
    hostname = weechat.config_get_plugin('hostname')
    password = weechat.config_get_plugin('password')
    icon_path = os.path.join(weechat.info_get("weechat_dir", ""),
            weechat.config_get_plugin('icon'))
    try:
        icon = open(icon_path, "rb").read()
    except IOError:
        weechat.prnt('',
                'Weechat-Growl: {0} could not be opened. '.format(icon_path) +
                'Please make sure it exists.')
        icon = None

    notifications = [
        'Public',
        'Private',
        'Action',
        'Notice',
        'Invite',
        'Highlight',
        'Server',
        'Channel',
        'DCC',
        'WeeChat'
    ]
    if len(hostname) == 0:
        hostname = ''
    if len(password) == 0:
        password = ''
    growl = GrowlNotifier(
        applicationName=name,
        hostname=hostname,
        password=password,
        notifications=notifications,
        applicationIcon=icon)
    try:
        growl.register()
    except Exception as error:
        weechat.prnt('', 'growl: {0}'.format(error))
    STATE['growl'] = growl
    STATE['icon'] = icon
    # Register hooks.
    weechat.hook_signal(
        'irc_server_connected',
        'cb_irc_server_connected',
        '')
    weechat.hook_signal(
        'irc_server_disconnected',
        'cb_irc_server_disconnected',
        '')
    weechat.hook_signal('upgrade_ended', 'cb_upgrade_ended', '')
    weechat.hook_print('', '', '', 1, 'cb_process_message', '')
示例#21
0
文件: bufsize.py 项目: Shrews/scripts
def init_options():
    for option, value in OPTIONS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value[0])
            OPTIONS[option] = value[0]
        else:
            OPTIONS[option] = weechat.config_get_plugin(option)
        weechat.config_set_desc_plugin(option, "%s (default: '%s')" % (value[1], value[0]))
示例#22
0
def owl_config_set():
    for option, value in owl_settings_default.items():
        if weechat.config_is_set_plugin(option):
            owl_settings[option] = weechat.config_get_plugin(option)
        else:
            weechat.config_set_plugin(option, value[0])
            weechat.config_set_desc_plugin(option, value[1])
            owl_settings[option] = value[0]
示例#23
0
def init_options():
    for option,value in OPTIONS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value[0])
            OPTIONS[option] = value[0]
        else:
            OPTIONS[option] = weechat.config_get_plugin(option)
        weechat.config_set_desc_plugin(option, "%s (default: '%s')" % (value[1], value[0]))
示例#24
0
def init_options():
  for option,value in OPTIONS.items():
    if not weechat.config_is_set_plugin(option):
      weechat.config_set_plugin(option, value[0])
      toggle_refresh(None, 'plugins.var.python.' + SCRIPT_NAME + '.' + option, value[0])
    else:
      toggle_refresh(None, 'plugins.var.python.' + SCRIPT_NAME + '.' + option, weechat.config_get_plugin(option))
    weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))
示例#25
0
def init_options():
    for option,value in list(OPTIONS.items()):
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value[0])
            weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))
            OPTIONS[option] = value[0]
        else:
            OPTIONS[option] = weechat.config_get_plugin(option)
示例#26
0
def init_options():
    for option,value in OPTIONS.items():
        if not w.config_is_set_plugin(option):
            w.config_set_plugin(option, value[0])
            OPTIONS[option] = value[0]
        else:
            OPTIONS[option] = w.config_get_plugin(option)
        w.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))
示例#27
0
def weemustfeed_update_feeds_cb(data, remaining_calls):
    global updating

    for feed in weechat.config_get_plugin("feeds").strip().split(";"):
        if weechat.config_is_set_plugin("feed." + feed.lower() + ".url"):
            if not (weechat.config_is_set_plugin("feed." + feed.lower() + ".enabled") and
                    weechat.config_get_plugin("feed." + feed.lower() + ".enabled").lower() != "yes"):
                updating.add(feed)
                if not feed in fetch_hooks:
                    fetch_hooks[feed] = weechat.hook_process(
                        "url:" + weechat.config_get_plugin("feed." + feed.lower() + ".url"),
                        0,
                        "weemustfeed_update_single_feed_cb", feed
                        )
        elif feed != "":
            weechat.prnt(weemustfeed_buffer, weechat.prefix("error") + "Feed '" + feed + "' has no URL set.")
    return weechat.WEECHAT_RC_OK
示例#28
0
def main():
    """ Entry point, initializes everything  """

    weechat.register(
        SCRIPT_NAME,
        SCRIPT_AUTHOR,
        SCRIPT_VERSION,
        SCRIPT_LICENSE,
        SCRIPT_DESCRIPTION,
        "", # Shutdown callback function
        "", # Charset (blank for utf-8)
    )

    # Default values for settings
    default_settings = {
        'dbfile': os.path.join(
            weechat.info_get("weechat_dir", ""), "emojis-db.dat")
    }

    # Apply default configuration values if anything is unset
    for option, default in default_settings.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default)

    # Hook callbacks
    weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*",
        "configuration_cb", "")
    weechat.hook_command_run("/input return", "transform_cb", "")
    weechat.hook_command_run("/input complete*", "complete_cb", "")
    #weechat.hook_modifier("input_text_display", "collapse_cb", "")

    # Command callbacks
    weechat.hook_command(  # command name
                           SCRIPT_NAME,
                           # description
                           " display :common_name: with its emoji equivalent",
                           # arguments
                           "reload"
                           " || add <name> <emoji>"
                           " || show <emoji>",
                           # description of arguments
                           " name: emoji name, sans colons\n"
                           "emoji: text that replaces :name:\n",
                           # completions
                           "reload || add || show %(emoji_name)", "emojis_cb", "")
    weechat.hook_completion("emoji_name", "Emoji name", "emoji_name_completion_cb", "")

    dbfile = weechat.config_get_plugin("dbfile")

    weechat.prnt("", "%s: Loading emojis from %s" % (SCRIPT_NAME, dbfile))

    try:
        load_emojis(dbfile)
    except IOError as e:
        weechat.prnt("",
            "%s%s: Database file %s is missing or inaccessible." \
                    % (weechat.prefix("error"), SCRIPT_NAME, dbfile))
        raise e # TODO: handle this better instead of brutally aborting
示例#29
0
def _init_options():
  global wb_options

  for opt, def_val in wb_options.items():
    if not weechat.config_is_set_plugin(opt):
      weechat.config_set_plugin(opt, str(def_val))
      
  for key in wb_options:
    cfg_check('', '.%s' % key, weechat.config_get_plugin(key))
示例#30
0
def init_options():
    global HOOK,OPTIONS
    for option,value in list(OPTIONS.items()):
        weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value[0])
            OPTIONS[option] = value[0]
        else:
            OPTIONS[option] = weechat.config_get_plugin(option)
示例#31
0
def init_config():
    global default_options, options, bus, signal
    for option, default_value in default_options.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default_value)
        options[option] = weechat.config_get_plugin(option)
    if options.get('number', '') == '':
        check_update("welcome")
    return weechat.WEECHAT_RC_OK
示例#32
0
def lb_set_default_settings():
  global lb_settings
  # Set default settings
  for option, default_value, description in lb_settings:
     if not weechat.config_is_set_plugin(option):
         weechat.config_set_plugin(option, default_value)
         version = weechat.info_get("version_number", "") or 0
         if int(version) >= 0x00030500:
             weechat.config_set_desc_plugin(option, description)
示例#33
0
def lb_set_default_settings():
    global lb_settings
    # Set default settings
    for option, default_value, description in lb_settings:
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default_value)
            version = weechat.info_get("version_number", "") or 0
            if int(version) >= 0x00030500:
                weechat.config_set_desc_plugin(option, description)
示例#34
0
def parse_config():
    for option, (default, desc) in DEFAULTS.items():
        if not w.config_is_set_plugin(option):
            w.config_set_plugin(option, default)
        w.config_set_desc_plugin(option, '{} (default: {!r})'.format(desc, default))
    CONFIG['rate_limit'] = int(w.config_get_plugin('rate_limit'))
    for i in ('access_token', 'blacklist', 'show_highlight'):
        CONFIG[i] = w.config_get_plugin(i)
    return w.WEECHAT_RC_OK
示例#35
0
def client():
    """ Method to register the plugin and hook into weechat """
    settings = {
        'enable': {
            'description': 'Enable/Disable notifications.',
            'values': ['off', 'on'],
            'default': 'off'
        },
        'mode': {
            'description': 'Set whether notifications need to be'
            'sent locally or to an external server.',
            'values': ['local', 'remote'],
            'default': 'local'
        },
        'host': {
            'description': 'Set the server host to send notifications to.',
            'values': None,
            'default': 'localhost'
        },
        'port': {
            'description': 'Set the server port to use to send notifcation.',
            'values': None,
            'default': '5431'
        },
        'notify_for': {
            'description':
            'A comma-separated list of buffers for which you want to receive notifications.',
            'values': None,
            'default': ''
        },
        'ignore_nicks': {
            'description':
            'A comma-separated list of nicks from which no notifications should be shown.',
            'values': None,
            'default': '-,--,-->,<--,===,*,* , *,,'
        }
    }

    if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
                  SCRIPT_DESCRIPTION, '', ''):
        for option, value in settings.items():
            if not w.config_is_set_plugin(option):
                w.config_set_plugin(option, value['default'])
            if value.get('values', None):
                w.config_set_desc_plugin(
                    option, '{} (values: [{}], default: {})'.format(
                        value['description'], '/'.join(value['values']),
                        value['default']))
            else:
                w.config_set_desc_plugin(
                    option, '{} (default: {})'.format(value['description'],
                                                      value['default']))
        w.hook_print('', '', '', 1, 'on_notify', 'IRC')
        w.hook_print('', 'notify_message', '', 1, 'on_notify', 'MSG')
        w.hook_print('', 'notify_private', '', 1, 'on_notify', 'PRIVMSG')
        w.hook_print('', 'irc_notice', '', 1, 'on_notify', 'NOTICE')
示例#36
0
def init():
    global gribble_buffer
    gribble_buffer = weechat.buffer_new(NAME, "", "", "", "")
    weechat.prnt(gribble_buffer, "Options:")
    for opt, val in options.iteritems():
        if not weechat.config_is_set_plugin(opt):
            weechat.config_set_plugin(opt, val)
        else:
            options[opt] = weechat.config_get_plugin(opt)
        weechat.prnt(gribble_buffer, "    %s: %s" % (opt, options[opt]))
示例#37
0
def init_config():
    for option, (default_value, description) in SW_CONFIG_DEFAULTS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default_value)
            sw_config[option] = default_value
        else:
            sw_config[option] = weechat.config_get_plugin(option)
        weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (description, default_value))

    weechat.hook_config('plugins.var.python.' + SCRIPT_NAME + '.*', 'update_config', '')
示例#38
0
def config(*args, **kwargs):
    options = {
        'foobar_host': 'localhost',
        'foobar_port': '3333',
        'format': 'NP: $title by $artist from $album ($date)'
    }
    for option, default in options.items():
        if not wc.config_is_set_plugin(option):
            wc.config_set_plugin(option, default)
    return wc.WEECHAT_RC_OK
示例#39
0
def init_settings():
    # Setup default options for pushover
    for option, (default, desc) in default_settings.iteritems():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default)
            weechat.config_set_desc_plugin(option, desc)
    for option in required_settings:
        if weechat.config_get_plugin(option) == "":
            weechat.prnt("", "pushover: Please set option: %s" % option)
            weechat.prnt("", "pushover: /set plugins.var.python.pushover.%s STRING" % option)
示例#40
0
def init():
    global gribble_buffer
    gribble_buffer = weechat.buffer_new(NAME, "", "", "", "")
    weechat.prnt(gribble_buffer, "Options:")
    for opt, val in options.iteritems():
        if not weechat.config_is_set_plugin(opt):
            weechat.config_set_plugin(opt, val)
        else:
            options[opt] = weechat.config_get_plugin(opt)
        weechat.prnt(gribble_buffer, "    %s: %s" % (opt, options[opt]))
示例#41
0
def init_config():
    global tc_default_options, tc_options

    for option,value in list(tc_default_options.items()):
        w.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))
        if not w.config_is_set_plugin(option):
            w.config_set_plugin(option, value[0])
            tc_options[option] = value[0]
        else:
            tc_options[option] = w.config_get_plugin(option)
示例#42
0
def init_options():
    for option, value in OPTIONS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value[0])
            sync_with_options(None, "plugins.var.python." + SCRIPT_NAME + "." + option, value[0])
        else:
            sync_with_options(
                None, "plugins.var.python." + SCRIPT_NAME + "." + option, weechat.config_get_plugin(option)
            )
        weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))
示例#43
0
文件: mpv_np.py 项目: snowfag/mpv_np
def config(*args, **kwargs):
  if not wc.config_is_set_plugin('mpv_host'):
    wc.config_set_plugin('mpv_host', 'localhost')
  if not wc.config_is_set_plugin('mpv_port'):
    wc.config_set_plugin('mpv_port', '8091')
  if not wc.config_is_set_plugin('color1'):
    wc.config_set_plugin('color1', '06')
  if not wc.config_is_set_plugin('color2'):
    wc.config_set_plugin('color2', '13')
  c1 = wc.config_get_plugin('color1')
  c2 = wc.config_get_plugin('color2')
  colorre = re.compile(r'^[0][1-9]|[1][0-5]$')
  if not colorre.match(c1):
    wc.prnt('', 'invalid color (valid colors are 01-15)')
    wc.config_set_plugin('color1', '06')
  if not colorre.match(c2):
    wc.prnt('', 'invalid color (valid colors are 01-15)')
    wc.config_set_plugin('color2', '13')
  return wc.WEECHAT_RC_OK
示例#44
0
def init_config():
    for option, (default_value, description) in SW_CONFIG_DEFAULTS.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default_value)
            sw_config[option] = default_value
        else:
            sw_config[option] = weechat.config_get_plugin(option)
        weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (description, default_value))

    weechat.hook_config('plugins.var.python.' + SCRIPT_NAME + '.*', 'update_config', '')
示例#45
0
def init_config():
    global tc_default_options, tc_options

    for option,value in list(tc_default_options.items()):
        w.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))
        if not w.config_is_set_plugin(option):
            w.config_set_plugin(option, value[0])
            tc_options[option] = value[0]
        else:
            tc_options[option] = w.config_get_plugin(option)
示例#46
0
def url_olde_load_config():
    global url_olde_settings_default, url_olde_settings
    version = w.info_get('version_number', '') or 0
    for option, value in url_olde_settings_default.items():
        if w.config_is_set_plugin(option):
            url_olde_settings[option] = w.config_get_plugin(option)
        else:
            w.config_set_plugin(option, value[0])
            url_olde_settings[option] = value[0]
        if int(version) >= 0x00030500:
            w.config_set_desc_plugin(option, value[1])
示例#47
0
文件: vk.py 项目: Fogapod/weechat-vk
def get_setting(key):
    if not weechat.config_is_set_plugin(key):
        return DEFAULT_SETTINGS[key]

    setting = weechat.config_get_plugin(key)
    setting_type = type(DEFAULT_SETTINGS[key])

    if setting_type is bool:
        return setting == 'True'
    else:
        return setting_type(setting)
示例#48
0
def cs_set_default_settings():
  global OPTIONS

  # Set default settings
  for option,value in OPTIONS.items():
    if not weechat.config_is_set_plugin(option):
        weechat.config_set_plugin(option, value[0])
        OPTIONS[option] = value[0]
    else:
        OPTIONS[option] = weechat.config_get_plugin(option)
    weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))
示例#49
0
def url_olde_load_config():
    global url_olde_settings_default, url_olde_settings
    version = w.info_get('version_number', '') or 0
    for option, value in url_olde_settings_default.items():
        if w.config_is_set_plugin(option):
            url_olde_settings[option] = w.config_get_plugin(option)
        else:
            w.config_set_plugin(option, value[0])
            url_olde_settings[option] = value[0]
        if int(version) >= 0x00030500:
            w.config_set_desc_plugin(option, value[1])
示例#50
0
def load_state():
    global buffers
    global maintop
    if wee.config_is_set_plugin(conf_opt):
        buffers = wee2py(wee.config_get_plugin(conf_opt))
        maintop = bool(wee.config_get_plugin(conf_opt2))
    else:
        buffers = {}
        maintop = True

    return
示例#51
0
    def GetConfigOption(option_name, type_=str):
        real_option_name = "python.{0}.{1}".format(Script.NAME, option_name)
        real_option_name_full = "plugins.var.{0}".format(real_option_name)

        if not weechat.config_is_set_plugin(option_name):
            return None

        try:
            return type_(weechat.config_get_plugin(option_name))
        except:
            return type_()
示例#52
0
def nameday_load_config():
    global nameday_settings_default, nameday_settings
    version = weechat.info_get('version_number', '') or 0
    for option, value in nameday_settings_default.items():
        if weechat.config_is_set_plugin(option):
            nameday_settings[option] = weechat.config_get_plugin(option)
        else:
            weechat.config_set_plugin(option, value[0])
            nameday_settings[option] = value[0]
        if int(version) >= 0x00030500:
            weechat.config_set_desc_plugin(option, value[1])
def script_main():
    if not weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                            SCRIPT_LICENSE, SCRIPT_DESCRIPTION, "", ""):
        return
    version = weechat.info_get('version_number', '') or 0
    for option, value in settings.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value[0])
        if int(version) >= 0x00030500:
            weechat.config_set_desc_plugin(
                option, '%s (default: "%s")' % (value[1], value[0]))
    weechat.hook_print("", "irc_privmsg", "", 1, "message_cb", "")
示例#54
0
def init():
    ok = import_ok and weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, 
                                        SCRIPT_LICENSE, SCRIPT_DESC, "", "")
    if not ok: 
        return

    # Set default settings
    for option, default_value in settings.iteritems():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default_value)

    return True
示例#55
0
文件: twitch.py 项目: alyptik/scripts
def config_setup():
    for option,value in OPTIONS.items():
        weechat.config_set_desc_plugin(option, '%s' % value[1])
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, value[0])
            OPTIONS[option] = value[0]
        else:
            if option == 'prefix_nicks' or option == 'debug':
                OPTIONS[option] = weechat.config_string_to_boolean(
                    weechat.config_get_plugin(option))
            else:
                OPTIONS[option] = weechat.config_get_plugin(option)
示例#56
0
def run_notify(urgency, nick, chan, message):
    try:
        if w.config_is_set_plugin("socket"):
            s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            s.connect(w.config_get_plugin("socket"))
        else:
            host = w.config_get_plugin("host")
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect((host, int(w.config_get_plugin("port"))))
        s.send('%s %s "%s to %s" "%s"' % (urgency, socket.gethostname(), nick, chan, message))
        s.close()
    except Exception as e:
        w.prnt("", "Could not send notification: %s" % str(e))
示例#57
0
def init_config():
    """Set plugin options to defaults if not already done"""
    config = {
        'user': '',
        'command': '/me is listening to {track}',
        'command_arg': '{user} is listening to {track}',
        'api_key': 'ae51c9df97d4e90c35ffd302e987efd2',
        'api_url': 'https://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&user={user}&limit=1&api_key={api_key}&format=json',
        'timeout': '10000'
    }

    for option, default in config.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default)