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 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 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 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 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(): 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 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 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 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]))
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 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 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 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]))
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 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)
def config_init(): """Add configuration options to weechat.""" config = { "hide_inactive": ("off", "Hide inactive buffers"), "hide_private": ("off", "Hide private buffers"), "unhide_low": ("off", "Unhide a buffer when a low message (like JOIN, PART, etc.) has been received"), } 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]))
def main(): """Main""" if not weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC,'', ''): return for option, (default_value, description) in settings.items(): if weechat.config_get_plugin(option) == "": weechat.config_set_plugin(option, default_value) if description: weechat.config_set_desc_plugin(option, description) weechat.hook_command(SCRIPT_COMMAND, SCRIPT_DESC, '', '', '%(buffers_names)', 'np_cb', '')
def init_options(): global OPTIONS notransform = lambda x: x 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.prnt('', 'x') weechat.config_set_plugin(option, value[0]) if len(value) > 2: transform = value[2] else: transform = notransform OPTIONS[option] = transform(weechat.config_get_plugin(option))
def init_config(): """Perform initial configuration of the application settings""" for option, (default_value, config_type, description) in config.items(): # set config type config_types[option] = config_type # set descriptions for options weechat.config_set_desc_plugin( option, '{0} (default: "{1}")'.format(description, config_as_str(default_value)) ) # setdefault the script's options from weechat if not weechat.config_is_set_plugin(option): weechat.config_set_plugin(option, config_as_str(default_value)) config[option] = default_value debug('Option "{0}" was not set, is now {1}'.format(option, repr(default_value))) else: config[option] = config_type(weechat.config_get_plugin(option)) debug('Option "{0}" set to {1}'.format(option, repr(config[option])))
def at_config(data = '', option = '', value = ''): return_code = weechat.WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE option = option.replace(STRIP_VAR,'') if data == 'load' : for k in config.keys(): if not weechat.config_is_set_plugin(k): v = config[k] if type(v) is list: v = str.join(',',v) weechat.config_set_plugin(k, v) weechat.config_set_desc_plugin(k,config_desc[k]) stored = weechat.config_string(weechat.config_get(STRIP_VAR+k)) if k == 'enable': if stored in ['on','off']: if stored == 'on': config[k] = True else: config[k] = False weechat.config_set_plugin(k,'on' if config[k] else 'off') if k == 'servers' or k == 'buffers': stored = stored.replace(' ','') lst = stored.split(',') config[k] = lst weechat.config_set_plugin(k,stored) return weechat.WEECHAT_RC_OK else: if option == 'enable': if value in ['on', 'off']: return weechat.WEECHAT_CONFIG_OPTION_SET_ERROR value = True if value == 'on' else False if config[option] != value: return_code = weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED config[option] = value elif option == 'servers' or option == 'buffers': value = value.replace(' ','') if value != weechat.config_string(weechat.config_get(STRIP_VAR+option)): return_code = weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED lst = value.split(',') config[option] = lst else: return_code = weechat.WEECHAT_CONFIG_OPTION_SET_ERROR return return_code
def desc_options(): """ Load descriptions for all the options. """ weechat.config_set_desc_plugin( 'check_every', 'Interval between each check for expired messages.') weechat.config_set_desc_plugin( 'data_timeout', 'Time before a message is expired.') weechat.config_set_desc_plugin( 'message_limit', 'Number of messages to store per nick.') weechat.config_set_desc_plugin( 'print_format', 'Format string for the printed corrections.') weechat.config_set_desc_plugin( 'print_limit', 'Maximum number of lines to correct.') return weechat.WEECHAT_RC_OK
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"))
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': OPTIONS[option] = weechat.config_string_to_boolean( 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" else: OPTIONS[option] = weechat.config_get_plugin(option)
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "weechat_script_end", ""): version = weechat.info_get('version_number', '') or 0 # Init everything for option, default_desc in settings.items(): if not weechat.config_is_set_plugin(option): weechat.config_set_plugin(option, default_desc[0]) if int(version) >= 0x00030500: weechat.config_set_desc_plugin(option, default_desc[1]) # Perform some sanity checks to make sure we have everything we need to run sanity = True weechat_windowid = os.environ.get('WINDOWID') if weechat_windowid == None: weechat.prnt("", "%sEnvironment variable WINDOWID not set. This script requires an X environment to run." % weechat.prefix("error")) sanity = False fifo_filename = weechat.info_get("fifo_filename", "") if fifo_filename == "": weechat.prnt("", "%sWeechat variable fifo_filename is not set. Is the fifo plugin enabled?" % weechat.prefix("error")) sanity = False if sanity: Subprocess.start(fifo_filename, weechat_windowid)
def signal_mode(data, signal, signal_data): items_update() return w.WEECHAT_RC_OK SETTINGS = { "args-first": ["no", "whether or not to sort modes with args first"] } if import_ok and w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""): for name, (default, description) in SETTINGS.items(): if not w.config_is_set_plugin(name): w.config_set_plugin(name, default) w.config_set_desc_plugin(name, description) w.bar_item_new("better_nick", "bar_item_nick", "") w.bar_item_new("better_umodes", "bar_item_umodes", "") w.bar_item_new("better_cmodes", "bar_item_cmodes", "") w.bar_item_new("better_prefix", "bar_item_prefix", "") w.bar_item_new("better_prompt", "bar_item_prompt", "") items_update() w.hook_config(f"plugins.var.python.{SCRIPT_NAME}.*", "config_plugin", '') w.hook_config("irc.color.item_channel_modes", "config_channel", '') w.hook_config("irc.color.item_nick_modes", "config_user", '') w.hook_config("irc.color.nick_prefixes", "config_prefix", '') w.hook_config("irc.color.input_nick", "config_nick", '') w.hook_config("weechat.bar.input.color_delim", "config_delim", '')
return weechat.WEECHAT_RC_OK def cb_command_apply(data, buf, list_args): """Apply the rules the all existing buffers; useful when testing a new rule.""" infolist = weechat.infolist_get("buffer", "", "") while weechat.infolist_next(infolist): buf2 = weechat.infolist_pointer(infolist, "pointer") cb_signal_apply_rules(data, None, buf2) weechat.infolist_free(infolist) return weechat.WEECHAT_RC_OK def bad_command(buf): """Print an error message about the command.""" weechat.prnt(buf, ("[" + NAME + "] Bad option for /" + NAME + " " "command, try '/help " + NAME + "' for more info.")) return weechat.WEECHAT_RC_OK if IMPORT_OK: weechat.register(NAME, AUTHOR, VERSION, 'GPL2', DESC, '', '') weechat.hook_signal('irc_channel_opened', 'cb_signal_apply_rules', '') weechat.hook_signal('irc_pv_opened', 'cb_signal_apply_rules', '') weechat.config_set_desc_plugin('rules', 'Rules to follow when automerging.') if not weechat.config_is_set_plugin('rules'): weechat.config_set_plugin('rules', '') weechat.hook_command(NAME, CMD_DESC, '[' + '|'.join(CMD_LIST) + ']', '', CMD_COMPLETE, 'cb_command', '')
if __name__ == '__main__' and IMPORT_OK: if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', ''): # set default settings version = weechat.info_get("version_number", "") or 0 for ttt_option, ttt_value in tictactoe_settings_default.items(): if weechat.config_is_set_plugin(ttt_option): tictactoe_settings[ttt_option] = weechat.config_get_plugin( ttt_option) else: weechat.config_set_plugin(ttt_option, ttt_value[0]) tictactoe_settings[ttt_option] = ttt_value[0] if int(version) >= 0x00030500: weechat.config_set_desc_plugin( ttt_option, '%s (default: "%s")' % (ttt_value[1], ttt_value[0])) # mouse support weechat.key_bind('mouse', tictactoe_mouse_keys) weechat.hook_hsignal('tictactoe_mouse', 'tictactoe_mouse_cb', '') # detect config changes weechat.hook_config('plugins.var.python.%s.*' % SCRIPT_NAME, 'tictactoe_config_cb', '') # add command weechat.hook_command( SCRIPT_COMMAND, 'Tic-tac-toe game.', '', 'Instructions:\n' ' - enter one digit, or click with mouse in an empty cell to ' 'play\n'
""" Command /buffers_dmenu """ if args == "hotlist": buffers = get_hotlist_buffers() else: buffers = get_open_buffers() if not launch(buffers): return w.WEECHAT_RC_ERROR return w.WEECHAT_RC_OK if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""): version = w.info_get('version_number', '') or 0 for option, value in settings.items(): if not w.config_is_set_plugin(option): w.config_set_plugin(option, value[0]) if int(version) >= 0x00030500: w.config_set_desc_plugin( option, '{0} (default: "{1}")'.format(value[1], value[0])) w.hook_command( SCRIPT_COMMAND, "Show a list of all buffers in dmenu", "[hotlist]", " hotlist: shows hotlist buffers only\n" "\n" "To call externally (IE: from i3), enable weechat fifo and run:\n" " $ echo 'core.weechat */buffer_dmenu' >> $(find ~/.weechat -type p)\n" "\n" "To focus the terminal containing WeeChat for the following WM:\n" " i3: requires i3ipc from pip3\n", "", "dmenu_cmd_cb", "")
" size: set max size (width and height) for layout to be automatically applied\n" " nicklist: show or hide nicklist bar when layout is automatically applied\n" "default_nicklist: default show or hide nicklist bar if not configured per layout\n" " remove: remove settings for responsive layout\n" " list: list current configuration\n" " terminal: list current terminal width and height\n" " debug: print script debug output\n\n" "To get current layout and terminal dimensions in your bar, use 'rlayout' bar item.", "size %(layouts_names)" " || nicklist %(layouts_names) %(rlayout_bool_value)" " || default_nicklist %(rlayout_bool_value)" " || remove %(rlayouts_names)" " || list" " || terminal" " || debug %(rlayout_bool_value)", "rlayout_cmd_cb", "") # Default settings for option, default_value in SETTINGS.items(): if weechat.config_get_plugin(option) == "": weechat.config_set_plugin(option, default_value[0]) weechat.config_set_desc_plugin(option, '%s (default: %s)' % (default_value[1], default_value[0])) weechat.hook_completion("rlayout_bool_value", "list of bool values", "rlayout_completion_bool_cb", "") weechat.hook_completion("rlayouts_names", "list of rlayouts", "rlayout_completion_layout_list_cb", "") weechat.hook_config("plugins.var.python.responsive_layout.layout.*", "config_cb", "") weechat.bar_item_new("rlayout", "rlayout_bar_cb", "") update_layout_list() hook = weechat.hook_signal("signal_sigwinch", "responsive_cb", "")
"ignore_buffers": "Comma separated list of buffers to ignore.", "ignore_servers": "Comma separated list of servers to ignore.", "ignore_nicks": "Comma separated list of nicks to ignore.", } required_settings = ["api_token", "encryption_password"] for option, help_text in list(settings.items()): if not weechat.config_is_set_plugin(option): weechat.config_set_plugin(option, "") if option in required_settings and weechat.config_get_plugin(option) == "": weechat.prnt("", weechat.prefix("error") + "irssinotifier: Please set option: %s" % option) weechat.prnt("", "irssinotifier: /set plugins.var.python.irssinotifier.%s STRING" % option) weechat.config_set_desc_plugin(option, help_text) # Hook privmsg/hilights weechat.hook_print("", "notify_message", "", 1, "notify_show", "") weechat.hook_print("", "notify_private", "", 1, "notify_show", "") # Functions def notify_show(data, bufferp, uber_empty, tagsn, isdisplayed, ishilight, prefix, message): # irc PMs are caught by notify_private, but we need notify_message to # capture hilights in channels. if 'notify_message' in tagsn and not ishilight: return weechat.WEECHAT_RC_OK # are we away?
match = re.match(match_prefix + r'([\w-]+?): (.*)$', input_s) if match: nick, message = match.groups() if not channel_has_nick(server, channel, nick): w.prnt(buffer, "| Enqueued message for %s: %s" % (nick, message)) save = datetime.now(), nick + ": " + message postpone_data.setdefault(server, {}).setdefault( channel, {}).setdefault(nick.lower(), []).append(save) w.buffer_set(buffer, 'input', "") # XXX why doesn't this work? i want to have the typed text # in the history #history_list = w.infolist_get("history", buffer, "") #history_item = w.infolist_new_item(history_list) #w.infolist_new_var_string(history_item, "text", input_s) return w.WEECHAT_RC_OK if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""): version = w.info_get('version_number', '') or 0 for option, default_desc in settings.iteritems(): if not w.config_is_set_plugin(option): w.config_set_plugin(option, default_desc[0]) if int(version) >= 0x00030500: w.config_set_desc_plugin(option, default_desc[1]) w.hook_command_run("/input return", "command_run_input", "") w.hook_signal('*,irc_in2_join', 'join_cb', '')
def urlbuf2_close_cb(): global urlbuf_buffer urlbuf_buffer = None return weechat.WEECHAT_RC_OK if __name__ == "__main__" and import_ok: if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "urlbuf2_close_cb", ""): version = weechat.info_get('version_number', '') or 0 # Set default settings for option, default_value in urlbuf_settings.items(): if not weechat.config_is_set_plugin(option): weechat.config_set_plugin(option, default_value[0]) if int(version) >= 0x00030500: weechat.config_set_desc_plugin(option, default_value[1]) urlbuf_buffer = weechat.buffer_search("python", "urlbuf") if not urlbuf_buffer: # Create urlbuf. Sets notify to 0 as this buffer does not need to # be in hotlist. urlbuf_buffer = weechat.buffer_new("urlbuf", "urlbuf_input_cb", \ "", "urlbuf_close_cb", "") weechat.buffer_set(urlbuf_buffer, "title", "URL buffer") weechat.buffer_set(urlbuf_buffer, "notify", "0") weechat.buffer_set(urlbuf_buffer, "nicklist", "0") # Hook all public and private messages (some may think this is too limiting) weechat.hook_print("", "notify_message", "", 1, "urlbuf_print_cb", "") weechat.hook_print("", "notify_private", "", 1, "urlbuf_print_cb", "")
if __name__ == "__main__" and IMPORT_OK: if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""): weechat.hook_signal("input_search", "input_search_cb", "") weechat.hook_signal("input_text_changed", "input_text_changed_cb", "") weechat.hook_command( SCRIPT_COMMAND, SCRIPT_DESC, """enable || disable || toggle""", """ enable: enable {0} in current buffer disable: disable {0} in current buffer toggle: toggle {0} in current buffer By default a bind in "search" context is added to toggle with "ctrl-G". To see {0} status during search, add "{1}" item to some bar. On default configuration you can do it with: /set weechat.bar.input.items "[input_prompt]+(away),[{1}],[input_search],[input_paste],input_text" Due to technical reasons with /filter it is not possible to exactly {0} in "pre|msg" search mode, thus the bar item is shown in warning color.""" .format(SCRIPT_NAME, SCRIPT_BAR_ITEM), """enable || disable || toggle""", "command_cb", "") weechat.bar_item_new("(extra)%s" % SCRIPT_BAR_ITEM, "bar_item_cb", "") for option, value in SETTINGS.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])) weechat.key_bind("search", KEYS)
tznames = OPTIONS['timezone'].split() for tzname in tznames: tz = pytz.timezone(tzname) ret += tz.zone + ': ' + datetime.datetime.now(tz).strftime( OPTIONS['timeformat']) + ' ' return ret[:-1] def alternatetz_timer_cb(*kwargs): w.bar_item_update('alternatetz') return w.WEECHAT_RC_OK if __name__ == '__main__': w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', '') for option, value in list(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]) OPTIONS[option] = value[0] else: OPTIONS[option] = w.config_get_plugin(option) w.bar_item_new('alternatetz', 'alternatetz_item_cb', '') w.bar_item_update('alternatetz') w.hook_timer(1000 * 60, 60, 0, 'alternatetz_timer_cb', '') # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
# "emergency" : 2, # "high" : 1, # "normal" : 0, # "moderate" : -1, # "low": -2 #} """ Init """ for option, (default_value, description) in settings.items(): if w.config_get_plugin(option) == "": w.config_set_plugin(option, default_value) if description: w.config_set_desc_plugin(option, description) if w.config_get_plugin("apikey") == "": w.prnt("", "[nma] - You haven't set your API key. Use /set " "plugins.var.python.nma.apikey \"you_nma_api_token\" " "to fix that.") """ Hooks """ # Hook command w.hook_command("nma", "Activate NotifyMyAndroid notifications", "on | off | test", """ on : Activate notifications
def init_config(): for option, (default, help) in CONFIG.viewitems(): if not wc.config_is_set_plugin(option): wc.config_set_plugin(option, default) wc.config_set_desc_plugin(option, "%s (default: \"%s\")" % (help, default))
"limit": ["4", "How many matches should be displayed at maximum? Number"], "match_set": ["true", "Match when a mode gets set. Boolean"], "match_unset": ["true", "Match when a mode gets unset. Boolean"], "matching_modes": ["bIqe", "List of mode characters to match on, every character represents a mode."], "prefix": ["_script_name_", "The name the script will have. Special options: _script_name_, _prefix_network_, _setter_, _target_"], "prefix_color": ["green", "The colour the prefix will have. If prefix is wrapped in brackets, the brackets will have this color. Any weechat-supported color"], "print_as_list": ["false", "Print as one large list, less information - but can fit more names at cost of readability. Boolean"], "sorting": ["alpha_ignore_case", "Sort names alphabetically or not. none, alpha, or alpha_ignore_case"], "verbose": ["false", "Print also if no matches are found. Boolean"], "whitelist": ["", "List of servers, channels, or server.channel combinations this should be done for. Comma separated string"] } for option, default_value in settings.items(): if not w.config_is_set_plugin(option): w.config_set_plugin(option, default_value[0]) w.config_set_desc_plugin(option, default_value[1]) w.hook_command( SCRIPT_COMMAND, ("Compare a hostmask against the active channel to see how much people it would affect." "\n\nA fully qualified hostname should be used in most cases, as it might give unexpected results " "when this is not done." "\n\nMaskmatch compares against the users in the active channel." "\n\nYou can also use account extbans like so: $a:account, $~a." " Full extban support is not implemented."), "<hostmask>", ("The argument <hostmask> is the hostmask to compare against in the active channel, " "and should be a fully qualified hostname (*!*@* format), or an account extban."), "", "cmd_maskmatch", "" )
return "CAP REQ :twitch.tv/commands twitch.tv/tags " "twitch.tv/membership\r\n" + string return string if __name__ == "__main__" and import_ok: if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""): # Set/get settings version = weechat.info_get("version_number", "") or 0 for option, value in twitch_settings_default.items(): if weechat.config_is_set_plugin(option): twitch_settings[option] = weechat.config_get_plugin(option) else: weechat.config_set_plugin(option, value[0]) twitch_settings[option] = value[0] if int(version) >= 0x00030500: weechat.config_set_desc_plugin(option, value[1] + " ( default: " + value[0] + ")") user_self["name"] = weechat.config_string( weechat.config_get("irc.server." + twitch_settings["group_server"] + ".nicks") ).split(",", 1)[0] user_self["display_name"] = user_self["name"] user_self["color"] = weechat.config_string(weechat.config_get("weechat.color.chat_nick_self")) user_self["channels"]["#" + user_self["name"]] = {"user_type": "broadcaster"} users[user_self["name"]] = user_self # Detect config changes weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "handle_config_change", "") weechat.hook_modifier("irc_in_whisper", "handle_whisper", "") weechat.hook_modifier("irc_in_globaluserstate", "handle_globaluserstate", "") weechat.hook_modifier("irc_in_userstate", "handle_userstate", "") weechat.hook_modifier("irc_in_roomstate", "handle_roomstate", "")
if len(rules2) == len(rules): weechat.prnt('', "[" + NAME + "] rule not found") else: weechat.prnt('', "[" + NAME + "] rule deleted") return weechat.WEECHAT_RC_OK def cb_command_apply(data, buf, list_args): """Apply the rules the all existing buffers; useful when testing a new rule.""" infolist = weechat.infolist_get("buffer", "", "") while weechat.infolist_next(infolist): buf2 = weechat.infolist_pointer(infolist, "pointer") cb_signal_apply_rules(data, None, buf2) weechat.infolist_free(infolist) return weechat.WEECHAT_RC_OK def bad_command(buf): """Print an error message about the command.""" weechat.prnt(buf, ("[" + NAME + "] Bad option for /" + NAME + " " "command, try '/help " + NAME + "' for more info.")) return weechat.WEECHAT_RC_OK if IMPORT_OK: weechat.register(NAME, AUTHOR, VERSION, 'GPL2', DESC, '', '') weechat.hook_signal('irc_channel_opened', 'cb_signal_apply_rules', '') weechat.hook_signal('irc_pv_opened', 'cb_signal_apply_rules', '') weechat.config_set_desc_plugin('rules', 'Rules to follow when automerging.') if not weechat.config_is_set_plugin('rules'): weechat.config_set_plugin('rules', '') weechat.hook_command(NAME, CMD_DESC, '[' + '|'.join(CMD_LIST) + ']', '', CMD_COMPLETE, 'cb_command', '')
n.set_hint("transient", GLib.Variant.new_boolean(True)) if notification.urgency: n.set_urgency(getattr(Notify.Urgency, notification.urgency.upper())) n.show() # n.uninit() if __name__ == "__main__": # Registration. weechat.register( SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, SCRIPT_SHUTDOWN_FUNC, SCRIPT_CHARSET, ) # Initialization. for option, (default_value, description) in OPTIONS.items(): description = add_default_value_to(description, default_value) weechat.config_set_desc_plugin(option, description) if not weechat.config_is_set_plugin(option): weechat.config_set_plugin(option, default_value) # Catch all messages on all buffers and strip colors from them before # passing them into the callback. weechat.hook_print("", "", "", 1, "message_printed_callback", "")
if __name__ == '__main__' and import_ok: if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', ''): # set default settings version = weechat.info_get('version_number', '') or 0 for option, value in minesweeper_settings_default.items(): if weechat.config_is_set_plugin(option): minesweeper_settings[option] = weechat.config_get_plugin( option) else: weechat.config_set_plugin(option, value[0]) minesweeper_settings[option] = value[0] if int(version) >= 0x00030500: weechat.config_set_desc_plugin( option, '%s (default: "%s")' % (value[2], value[0])) minesweeper_set_colors() # mouse support if int(version) >= 0x00030600: weechat.key_bind('mouse', minesweeper_mouse_keys) weechat.hook_hsignal('minesweeper_mouse', 'minesweeper_mouse_cb', '') # detect config changes weechat.hook_config('plugins.var.python.%s.*' % SCRIPT_NAME, 'minesweeper_config_cb', '') # add command weechat.hook_command( SCRIPT_COMMAND, 'Minesweeper game.', '[16col|256col]',
weechat.hook_hsignal("500|buffer_open_full_name", "buffer_open_full_name_irc_cb", "") weechat.hook_signal("irc_server_connected", "irc_server_connected_cb", "") weechat.hook_command( SCRIPT_COMMAND, SCRIPT_DESC, """closed [-noswitch|-list] || [-noswitch] <full name>""", """ closed: open most recently closed buffer closed -list: list most recently closed buffers -noswitch: try not to switch to new buffer Without subcommand, this command opens a buffer with given full name. Option "{prefix}.max_closed" specifies the number of most recently closed buffers that are remembered. If option "{prefix}.layout_apply" is on and "/layout apply" is executed, closed buffers in the layout are opened.""" .format(prefix="plugins.var.python.{}".format(SCRIPT_NAME)), """closed -noswitch|-list %- || -noswitch""".replace("\n", ""), "command_cb", "") weechat.hook_signal("buffer_closing", "buffer_closing_cb", "") weechat.hook_command_run("/layout apply*", "layout_apply_cb", "") for option, value in SETTINGS.items(): if not weechat.config_is_set_plugin(option): weechat.config_set_plugin(option, value[0]) weechat.config_set_desc_plugin( option, "{} (default: \"{}\")".format(value[1], value[0]))
weechat.infolist_free(infolist) if fields: cmdhelp_settings_default['format_option'][1] += ( ': %s' % ', '.join(fields)) # set default settings version = weechat.info_get("version_number", "") or 0 for option, value in cmdhelp_settings_default.items(): if weechat.config_is_set_plugin(option): cmdhelp_settings[option] = weechat.config_get_plugin(option) else: weechat.config_set_plugin(option, value[0]) cmdhelp_settings[option] = value[0] if int(version) >= 0x00030500: weechat.config_set_desc_plugin( option, '%s (default: "%s")' % (value[1], value[0])) # detect config changes weechat.hook_config('plugins.var.python.%s.*' % SCRIPT_NAME, 'config_cb', '') # add hook to catch "enter" key if cmdhelp_settings['stop_on_enter'] == 'on': cmdhelp_hooks['command_run'] = weechat.hook_command_run( '/input return', 'command_run_cb', '') # add command weechat.hook_command( SCRIPT_COMMAND, 'Contextual command line help.',
if players: players.sort() err = 'running players: %s' % ', '.join(players) else: err = 'no MPRIS v2 players are running' v1_players = [p for p in list_players(BUS_NAME_PREFIX_V1) if '.' not in p] if v1_players: err += ' (I found "%s", but it only supports MPRIS v1)' \ % ('" and "'.join(v1_players)) if err: weechat.prnt(buffer, 'np: %s' % err) else: weechat.prnt(buffer, 'np: %s' % msg) weechat.command(buffer, 'np: %s' % msg) return weechat.WEECHAT_RC_OK if __name__ == '__main__': weechat.hook_command('np', 'Print information on the currently played song', '', '', '', 'print_info', '') if not weechat.config_is_set_plugin('default_player'): weechat.config_set_plugin('default_player', '') weechat.config_set_desc_plugin('default_player', 'Player name to use for "/np" (default: "", shows a list)')
weechat.hook_signal("input_search", "input_search_cb", "") weechat.hook_signal("input_text_changed", "input_text_changed_cb", "") weechat.hook_command(SCRIPT_COMMAND, SCRIPT_DESC, """enable || disable || toggle""", """ enable: enable {0} in current buffer disable: disable {0} in current buffer toggle: toggle {0} in current buffer By default a bind in "search" context is added to toggle with "ctrl-G". To see {0} status during search, add "{1}" item to some bar. On default configuration you can do it with: /set weechat.bar.input.items "[input_prompt]+(away),[{1}],[input_search],[input_paste],input_text" Due to technical reasons with /filter it is not possible to exactly {0} in "pre|msg" search mode, thus the bar item is shown in warning color.""".format(SCRIPT_NAME, SCRIPT_BAR_ITEM), """enable || disable || toggle""", "command_cb", "") weechat.bar_item_new("(extra)%s" % SCRIPT_BAR_ITEM, "bar_item_cb", "") for option, value in SETTINGS.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])) weechat.key_bind("search", KEYS)
return weechat.WEECHAT_RC_OK command_description = r'''/autobump add high: Add the current buffer to the high priority list /autobump add low: Add the current buffer to the low priority list /autobump del high: Remove the current buffer from the high priority list /autobump del low: Remove the current buffer from the low priority list You can manually modify the high/low priority lists (for instance, with custom patterns) with /set var.plugins.python.autobump.highprio_buffers and /set var.plugins.python.autobump.lowprio_buffers. See /help filter for documentation on writing buffer lists. ''' command_completion = 'add high || add low || del high || del low' if __name__ == '__main__': if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', ''): for option, value in DEFAULTS.items(): if not weechat.config_is_set_plugin(option): weechat.config_set_plugin(option, value[0]) weechat.config_set_desc_plugin(option, value[1]) update_hook() weechat.hook_config('plugins.var.python.' + SCRIPT_NAME + '.tags', 'update_hook', '') weechat.hook_signal('buffer_opened', 'on_buffer_open', '') weechat.hook_command('autobump', command_description, '', '', command_completion, 'on_autobump_command', '')
SCRIPT_NAME = "pyshnotify" SCRIPT_AUTHOR = "Tony Blyler <*****@*****.**>" SCRIPT_VERSION = "1.0" SCRIPT_LICENSE = "MPL2" SCRIPT_DESC = "Execute command from highlights and private messages" def on_msg(data, buffer, timestamp, tags, displayed, highlight, sender, message): if data == "private" or int(highlight) or w.buffer_get_string(buffer, "localvar_type") == "private": buffer_name = w.buffer_get_string(buffer, "name") cmd = w.config_get_plugin("command") if not cmd: return w.WEECHAT_RC_OK cmd = cmd.replace("{{buffer_name}}", buffer_name).replace("{{msg}}", message) proc = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = proc.communicate() if proc.returncode != 0: w.prnt("", w.prefix("error") + " Unable to run command: '" + cmd + "' stdout: '" + stdout + "' stderr: '" + stderr + "'") return w.WEECHAT_RC_ERROR return w.WEECHAT_RC_OK if __name__ == "__main__" and w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""): w.config_set_desc_plugin("command", "Shell command to execute {{buffer_name}} and {{msg}} will be replaced per message") if not w.config_get_plugin("command"): w.config_set_plugin("command", "") w.hook_print("", "irc_privmsg", "", 1, "on_msg", "")
if interval >= settings['autoclean_interval'][0]: proxies = clean_proxies(proxies) time.sleep(settings['timer'][0]) if __name__ == '__main__': if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "ProxyRotator_end", ''): version = weechat.info_get('version_number', '') or 0 for option, value in settings.items(): if weechat.config_is_set_plugin(option): settings[option] = weechat.config_get_plugin(option) else: weechat.config_set_plugin(option, value[0]) if int(version) >= 0x00030500: weechat.config_set_desc_plugin( option, '{} (default: {})'.format(value[1], value[0])) # Detect Config Changes weechat.hook_config('plugins.var.python.{}'.format(SCRIPT_NAME), 'ProxyRotator_config_cb', '') # Add command weechat.hook_command( SCRIPT_COMMAND, SCRIPT_DESC, "start|stop|restart|update|buffer", "start: starts ProxyRotator", "stop: stops ProxyRotator & restores default proxy setting", "restart: restarts ProxyRotator", "update: updates setting", "buffer: creates buffer for logging output too") if settings['autostart'][0] is True: ProxyRotator() # Buffer weechat.hook_print('', '', '://', 1, 'ProxyRotator_config_cb', '')