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', '')
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
def load_settings(): for (option, default_value) in configs.items(): if w.config_get_plugin(option) == '': if configs[option] == '_required': w.prnt('', 'missing plugins.var.python.weepushover.{}'.format(option)) else: w.config_set_plugin(option, configs[option])
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
def del_from_exemptions(entry): """Remove an entry from the list of defined exemptions. :param entry: The entry to delete, which can be specified by the position in the list or by the name itself. :returns: the new list of entries. The return value is only used for unit testing. """ entries = list_exemptions() try: # by index try: index = int(entry) - 1 if index < 0: raise IndexError entry = entries.pop(index) except IndexError: weechat.prnt("", "[{}] del: Index out of range".format(SCRIPT_COMMAND)) return entries except ValueError: try: # by name entries.remove(entry) weechat.config_set_plugin("exemptions", DELIMITER.join(entries)) except ValueError: weechat.prnt("", "[{}] del: Could not find {}".format(SCRIPT_COMMAND, entry)) return entries weechat.config_set_plugin("exemptions", DELIMITER.join(entries)) weechat.prnt("", "[{}] del: Removed {} from exemptions.".format(SCRIPT_COMMAND, entry)) return entries
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)
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", "")
def command_cb(data, buffer, args): debug('adding "%s"' % args) items = weechat.config_get_plugin('items') new_items = '%s %s' % (items, args) debug('new_items: %s' % new_items) weechat.config_set_plugin('items', new_items) return weechat.WEECHAT_RC_OK
def init_options(): for option,value in OPTIONS.items(): if not weechat.config_get_plugin(option): weechat.config_set_plugin(option, value[0]) else: OPTIONS[option] = weechat.config_get_plugin(option) weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))
def get_validated_key_from_config(setting): key = weechat.config_get_plugin(setting) if key != 'mask' and key != 'nick': weechat.prnt("", "Key %s not found. Valid settings are 'nick' and 'mask'. Reverted the setting to 'mask'" % key) weechat.config_set_plugin("clone_report_key", "mask") key = "mask" return key
def at_control(data,buffer,args): argv = args.split(' ') js = ', ' if argv[0] in ['enable','disable','toggle']: if argv[0] == 'enable' : config['enable'] = True if argv[0] == 'disable': config['enable'] = False if argv[0] == 'toggle' : config['enable'] = not config['enable'] weechat.config_set_plugin('enable','on' if config['enable'] else 'off') if argv[0] == 'status': weechat.prnt('','atcomplete: %s' % 'on' if config['enable'] else 'off') weechat.prnt('',' servers: %s' % js.join(config['servers'])) weechat.prnt('',' buffers: %s' % js.join(config['buffers'])) if argv[0] in ['server','buffer']: sets = argv[0]+'s' if argv[1] == 'list': weechat.prnt('','atcomplete %s: %s' % (sets,js.join(config[sets]))) if (argv[1] == 'add' and len(argv) == 3): if argv[2] not in config[sets]: config[sets].append(argv[2]) at_config('',STRIP_VAR+sets,js.join(config[sets])) if (argv[1] == 'del' and len(argv) == 3): if argv[2] in config[sets]: config[sets].remove(argv[2]) at_config('',STRIP_VAR+sets,js.join(config[sets])) return weechat.WEECHAT_RC_OK
def print_tweet_data(buffer,tweets,data): for message in tweets: nick = message[1] text = message[3] reply_id = "" if script_options['tweet_nicks']: parse_for_nicks(text,buffer) add_to_nicklist(buffer,nick,tweet_nicks_group[buffer]) if script_options['print_id']: t_id = weechat.color('reset') + ' ' + dict_tweet(message[2]) else: t_id = '' if len(message) == 5: #This is a reply to a tweet arrow_col = weechat.color('chat_prefix_suffix') reset_col = weechat.color('reset') reply_id = arrow_col + "<" + reset_col + dict_tweet(message[4]) + arrow_col + "> " + reset_col temp_text = text text = reply_id reply_id = temp_text weechat.prnt_date_tags(buffer, message[0], "notify_message", "%s%s\t%s%s" % (nick, t_id, text,reply_id)) if data == "id": try: if script_options['last_id'] < tweets[-1][2]: script_options['last_id'] = tweets[-1][2] # Save last id weechat.config_set_plugin("last_id",script_options["last_id"]) except: pass
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', '')
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', '')
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]) 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]))
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]))
def save_state(): global buffers global maintop if(len(buffers)): wee.config_set_plugin(conf_opt, py2wee(buffers)) wee.config_set_plugin(conf_opt2, str(maintop)) return
def cmd_help(data, buffer, args): # Get current list of ignored channels in list form ignored_channels = get_ignored_channels() # Used for checking for ignore/unignore commands and getting the arguments ignore_command = re.match("^ignore\s+(.+)", args) unignore_command = re.match("^unignore\s+(.+)", args) if (ignore_command is not None): channels_to_ignore = ignore_command.group(1).split(' ') for channel in channels_to_ignore: if channel not in ignored_channels: ignored_channels.append(channel) w.config_set_plugin("ignored_channels", ','.join(ignored_channels)) w.prnt( "", "Updated. Ignored channels: %s" % w.config_get_plugin("ignored_channels")) elif (unignore_command is not None): channels_to_unignore = unignore_command.group(1).split(' ') for channel in channels_to_unignore: if channel in ignored_channels: ignored_channels.remove(channel) w.config_set_plugin("ignored_channels", ','.join(ignored_channels)) w.prnt( "", "Updated. Ignored channels: %s" % w.config_get_plugin("ignored_channels")) elif (args == "listignores"): w.prnt( "", "Ignored channels: %s" % w.config_get_plugin("ignored_channels")) elif (args == "listdevices"): apikey = w.string_eval_expression(w.config_get_plugin("api_key"), {}, {}, {}) apiurl = "https://%[email protected]/v2/devices" % (apikey) w.hook_process("url:" + apiurl, 20000, "process_devicelist_cb", "") else: w.prnt( "", """ Weebullet requires an API key from your Pushbullet account to work. Set your API key with (evaluated): /set plugins.var.python.weebullet.api_key <KEY> Weebullet will by default only send notifications when you are marked away on IRC. You can change this with: /set plugins.var.python.weebullet.away_only [0|1] Weebullet will by default send to all devices associated with your Pushbullet account. You can change this with: /set plugins.var.python.weebullet.device_iden <ID> Weebullet can ignore repeated notifications if they arrive too often. You can set this with (0 or blank to disable): /set plugins.var.python.weebullet.min_notify_interval <NUMBER> You can get a list of your devices from the Pushbullet website, or by using /weebullet listdevices """) return w.WEECHAT_RC_OK
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
def update_extract_cb(new_version, command, rc, out, err): new_bin = "%s/signal-cli/signal-cli-%s/bin/signal-cli" % (weechat.info_get( "weechat_dir", ""), new_version) prnt("Downloaded and extracted signal-cli %s!" % new_bin) weechat.config_set_plugin("signal_cli_command", new_bin) logger.debug("Options are %s", options) if options.get("number", "") == "": check_update("welcome") return weechat.WEECHAT_RC_OK
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))
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)
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
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
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]))
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)
def init_options(): for option,value in list(OPTIONS.items()): if int(version) >= 0x00030500: 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)
def remove_server(server, remove_seed=False): """ Remove server from the plugin configuration. """ if remove_seed and weechat.string_eval_expression("${sec.data.%s_seed}" % server, {}, {}, {}): weechat.command("", "/secure del %s_seed" % server) servers = get_config_as_list("otp_server_names") if server in servers: servers = [v for v in servers if v != server] weechat.config_set_plugin("otp_server_names", ','.join(servers))
def weechat_script(): settings = {"host": "localhost", "port": "4321", "icon": "utilities-terminal", "pm-icon": "emblem-favorite"} if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""): for (kw, v) in settings.items(): if not w.config_get_plugin(kw): w.config_set_plugin(kw, v) w.hook_print("", "notify_message", "", 1, "on_msg", "") w.hook_print("", "notify_private", "", 1, "on_msg", "private") w.hook_print("", "notify_highlight", "", 1, "on_msg", "") # Not sure if this is needed
def load_settings(): for (option, default_value) in list(configs.items()): if w.config_get_plugin(option) == '': if configs[option] == '_required': w.prnt( '', 'missing plugins.var.python.weebullet.{}'.format(option)) else: w.config_set_plugin(option, configs[option])
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)
def weather_cb(server, buffer, argList): """ Callback for the Google weather bar item. """ global last_run, last_city, current_city global gweather_output, gweather_hook_process if argList.partition(" ")[0] == "default": weechat.config_set_plugin("city", argList.partition(" ")[2]) current_city = weechat.config_get_plugin("city") weechat.prnt(weechat.current_buffer(), "Saving new location as: %s" % current_city) if argList == "" and weechat.config_get_plugin("city") == "": weechat.prnt(weechat.current_buffer(), "Error: no default city, provide one with command") return weechat.WEECHAT_RC_ERROR if len(argList) > 0: if weechat.config_get_plugin("city") == "": weechat.config_set_plugin("city", argList) current_city = argList else: current_city = weechat.config_get_plugin("city") location_id, hl = map(quote, (current_city, weechat.config_get_plugin("language"))) url = GOOGLE_WEATHER_URL % (location_id, hl) # Use cached copy if it is updated recently enough if current_city == last_city and (time() - last_run) < (int(weechat.config_get_plugin("interval")) * 60): weechat.command(weechat.current_buffer(), gweather_output) return weechat.WEECHAT_RC_OK last_city = current_city command = "urllib2.urlopen('%s')" % (url) if gweather_hook_process != "": weechat.unhook(gweather_hook_process) gweather_hook_process = "" # Fire up the weather informationg fetching python2_bin = weechat.info_get("python2_bin", "") or "python" gweather_hook_process = weechat.hook_process( python2_bin + ' -c "import urllib2;\ handler = ' + command + ";\ print handler.info().dict['content-type'];\ print handler.read();\ handler.close();\"", int(weechat.config_get_plugin("timeout")) * 1000, "weather_data_cb", "", ) # The old cached string is returned here. gweather_data_cb() will # request a new update after the data is fetched and parsed. return weechat.WEECHAT_RC_OK
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')
def main(): if not weechat.register("imgur", "Keith Smiley", "1.0.0", "MIT", "Upload an image to imgur", "", ""): return weechat.WEECHAT_RC_ERROR if not weechat.config_get_plugin(CLIENT_ID): weechat.config_set_plugin(CLIENT_ID, "Set imgur client ID") weechat.hook_command("imgur", "Pass the current buffer to urlview", "", "", "filename", "imgur", "")
def get_validated_key_from_config(setting): key = weechat.config_get_plugin(setting) if key != 'mask' and key != 'nick': weechat.prnt( "", "Key %s not found. Valid settings are 'nick' and 'mask'. Reverted the setting to 'mask'" % key) weechat.config_set_plugin("clone_report_key", "mask") key = "mask" return key
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
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]))
def toggle_cb(data, buf, args): if w.config_get_plugin('enable') == 'on': w.config_set_plugin('enable', 'off') else: w.config_set_plugin('enable', 'on') if w.config_get_plugin('status_prnt') == 'core': buf = '' w.prnt(buf, '%shighlightxmpp status%s set to %s' % \ (w.color('bold'),w.color('-bold'),w.config_get_plugin('enable'))) return w.WEECHAT_RC_OK
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)
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)
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', '')
def _config(): """Configuration.""" if not config_get_plugin('enabled'): config_set_plugin('enabled', 'on') status = config_get_plugin('enabled') if not config_get_plugin('delay'): config_set_plugin('delay', '5000') return status == 'on'
def remove_server(server, remove_seed=False): """ Remove server from the plugin configuration. """ if remove_seed and weechat.string_eval_expression( "${sec.data.%s_seed}" % server, {}, {}, {}): weechat.command("", "/secure del %s_seed" % server) servers = get_config_as_list("otp_server_names") if server in servers: servers = [v for v in servers if v != server] weechat.config_set_plugin("otp_server_names", ','.join(servers))
def stickynote_cmd(data, buffer, args): isSticky = weechat.config_get_plugin('sticky') if (args == 'toggle'): isSticky = ('on' if isSticky == 'off' else 'off') elif (args == 'on' or args == 'off'): isSticky = args else: weechat.prnt("", "Invalid stickynote option: " + args) weechat.config_set_plugin('sticky', isSticky) weechat.prnt("", "Growl notification stickyness is " + isSticky) return weechat.WEECHAT_RC_OK
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 get_option_int(option): """ Checks to see if a configuration option is an integer and sets it back to the default if it isn't. Returns the value when done. """ try: value = int(weechat.config_get_plugin(option)) except ValueError: weechat.config_set_plugin(option, settings[option]) value = int(weechat.config_get_plugin(option)) return value
def toggle_refresh(pointer, name, value): global OPTIONS config_option = name[len('plugins.var.python.' + SCRIPT_NAME + '.'):] # get optionname OPTIONS[config_option] = value # save new value if config_option in ('hooks.excluded_servers', 'hooks.explicit_servers'): remove_hooks() add_hooks() weechat.config_set_plugin(config_option, value) return weechat.WEECHAT_RC_OK
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])
def weather_cb(server, buffer, argList): ''' Callback for the Google weather bar item. ''' global last_run, last_city, current_city global gweather_output, gweather_hook_process if (argList.partition(" ")[0] == "default"): weechat.config_set_plugin('city', argList.partition(" ")[2]) current_city = weechat.config_get_plugin('city') weechat.prnt(weechat.current_buffer(), "Saving new location as: %s" % current_city) if (argList == '' and weechat.config_get_plugin('city') == ''): weechat.prnt(weechat.current_buffer(), "Error: no default city, provide one with command") return weechat.WEECHAT_RC_ERROR if (len(argList) > 0): if (weechat.config_get_plugin('city') == ''): weechat.config_set_plugin('city', argList) current_city = argList else: current_city = weechat.config_get_plugin('city') location_id, hl = map(quote, (current_city, \ weechat.config_get_plugin('language'))) url = GOOGLE_WEATHER_URL % (location_id, hl) # Use cached copy if it is updated recently enough if current_city == last_city and \ (time() - last_run) < (int(weechat.config_get_plugin('interval')) * 60): weechat.command(weechat.current_buffer(), gweather_output) return weechat.WEECHAT_RC_OK last_city = current_city command = 'urllib2.urlopen(\'%s\')' % (url) if gweather_hook_process != "": weechat.unhook(gweather_hook_process) gweather_hook_process = '' # Fire up the weather informationg fetching python2_bin = weechat.info_get("python2_bin", "") or "python" gweather_hook_process = weechat.hook_process(\ python2_bin + " -c \"import urllib2;\ handler = " + command + ";\ print handler.info().dict['content-type'];\ print handler.read();\ handler.close();\"" , int(weechat.config_get_plugin('timeout')) * 1000, "weather_data_cb", "") # The old cached string is returned here. gweather_data_cb() will # request a new update after the data is fetched and parsed. return weechat.WEECHAT_RC_OK
def enable_logging(): """ Connect to MongoDB and add our IRC hooks """ global mongo_collection, logging_hooks # Attempt to connect to our configured MongoDB instance # TODO -- assert that mongo connection worked mongo_host = weechat.config_get_plugin('mongo_host') mongo_port = weechat.config_get_plugin('mongo_port') mongo_database_name = weechat.config_get_plugin('mongo_database') mongo_collection_name = weechat.config_get_plugin('mongo_collection') mongo_user = weechat.config_get_plugin('mongo_user') mongo_password = weechat.config_get_plugin('mongo_password') mongoclient_arguments = { 'connectTimeoutMS': 1 } if len(mongo_host) > 0: mongoclient_arguments['host'] = mongo_host if len(mongo_port) > 0: mongoclient_arguments['port'] = int(mongo_port) mongo_client = pymongo.MongoClient(**mongoclient_arguments) mongo_database = mongo_client[mongo_database_name] mongo_collection = mongo_database[mongo_collection_name] # Authenticate if we have a configured user if len(mongo_user) > 0: try: mongo_database.authenticate(mongo_user, password=mongo_password) except pymongo.errors.OperationFailure as e: weechat.prnt('', 'Couldn\'t authenticate to MongoDB DB {}: {}'.format(mongo_database_name, e.details['errmsg'])) weechat.config_set_plugin('enabled', DISABLED) return # Set up our logging hooks hooks = [ 'irc_raw_in2_privmsg', 'irc_raw_in2_join', 'irc_raw_in2_part', 'irc_raw_in2_mode', 'irc_raw_in2_quit', 'irc_out1_privmsg', 'irc_out1_join', 'irc_out1_part', 'irc_out1_mode', 'irc_out1_quit' ] for hook in hooks: logging_hooks.append(weechat.hook_signal('*,{}'.format(hook), 'log_to_mongo', ''))
def my_config_cb(data, option, value): global options for boolean_option in boolean_options : if option.endswith(boolean_option): if value in booleans.keys(): options[boolean_option] = booleans[w.config_get_plugin(boolean_option)] else: w.prnt('', 'Error: "%s" is not a boolean, please use "on" or "off"' % w.config_get_plugin(boolean_option)) w.config_set_plugin(boolean_option, invertdict(booleans)[options[boolean_option]]) write_file() return w.WEECHAT_RC_OK
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", "")
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': OPTIONS[option] = weechat.config_string_to_boolean( weechat.config_get_plugin(option)) else: OPTIONS[option] = weechat.config_get_plugin(option)
def init_script(): global default_settings for option, default_value in default_settings.items(): if not weechat.config_is_set_plugin(option): weechat.config_set_plugin(option, default_value) weechat.hook_command("weemustfeed", "open/switch to weemustfeed buffer", "", "", "", "weemustfeed_command_cb", "") weechat.hook_config("plugins.var.python.weemustfeed.interval", "weemustfeed_reset_timer_cb", "")
def local_notify(data): """ Method to send notification locally on the host """ if notify_imported: notify(data) else: if dbus_imported: w.prnt("", "notify2 could not be imported, disabling {}" .format(SCRIPT_NAME)) else: w.prnt("", "notify2 could not be imported due to missing dbus-python," "disabling {}".format(SCRIPT_NAME)) w.config_set_plugin('enable', 'off')