def print_as_list(target, matches, data, limit, total): """Prints the output as a comma-separated list of nicks.""" col = w.color(w.info_get("irc_nick_color_name", data["setter"])) pf = fmt_prefix(data).replace("_target_", "") s = "{}\tThe following {} {}" if data["mode"] == "special": w.prnt(target, s.format(pf, "nick matches" if total == 1 else "nicks match", fmt_banmask(data["mask"]))) else: w.prnt(target, (s + ", {} by {}{}{}").format( pf, "nick matches" if total == 1 else "nicks match", fmt_banmask(data["mask"]), fmt_mode_char(data["mode"]), col, data["setter"], w.color("reset") )) nicks = [] remainder = len(matches) - limit i = 0 for name in matches: nicks.append("{}{}{}".format(w.color(w.info_get("irc_nick_color_name", name)), name, w.color("reset"))) i += 1 if i >= limit: break if w.config_string(w.config_get("weechat.look.prefix_same_nick")): pf = (w.color(w.config_get_plugin("prefix_color")) + w.config_string(w.config_get("weechat.look.prefix_same_nick")) + w.color("reset")) printstr = "{}\t{}".format(pf, ", ".join(nicks)) if remainder > 0: printstr += ", and {} more..".format(remainder) w.prnt(target, printstr)
def find_buffer(server, nick, message_type='whois'): # See if there is a target msgbuffer set for this server msgbuffer = weechat.config_string( weechat.config_get('irc.msgbuffer.%s.%s' % (server, message_type))) # No whois msgbuffer for this server; use the global setting if msgbuffer == '': msgbuffer = weechat.config_string( weechat.config_get('irc.msgbuffer.%s' % message_type)) # Use the fallback msgbuffer setting if private buffer doesn't exist if msgbuffer == 'private': buffer = weechat.buffer_search('irc', '%s.%s' % (server, nick)) if buffer != '': return buffer else: msgbuffer = weechat.config_string( weechat.config_get('irc.look.msgbuffer_fallback')) # Find the appropriate buffer if msgbuffer == "current": return weechat.current_buffer() elif msgbuffer == "weechat": return weechat.buffer_search_main() else: return weechat.buffer_search('irc', 'server.%s' % server)
def main(): if not weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, 'exit_cb', ''): return weechat.WEECHAT_RC_ERROR # registration required for accessing config global NOTE_PREFIX global ERROR_PREFIX NOTE_PREFIX = weechat.color( weechat.config_color( weechat.config_get( 'weechat.color.chat_prefix_join'))) + weechat.config_string( weechat.config_get('weechat.look.prefix_join')) + '\t' ERROR_PREFIX = weechat.color( weechat.config_color( weechat.config_get( 'weechat.color.chat_prefix_error'))) + weechat.config_string( weechat.config_get('weechat.look.prefix_error')) + '\t' create_buffer() set_default_settings() log_debug('Test note', note=1) log_debug('Test error', error=1) if not get_setting('token'): show_auth_hint()
def fish_msg_w_marker(msg): marker = weechat.config_string(fish_config_option["mark_encrypted"]) if weechat.config_string(fish_config_option["mark_position"]) == "end": return "%s%s" % (msg, marker) elif weechat.config_string(fish_config_option["mark_position"]) == "begin": return "%s%s" % (marker, msg) else: return msg
def fish_msg_wo_marker(msg): marker = weechat.config_string(fish_config_option["mark_encrypted"]) if weechat.config_string(fish_config_option["mark_position"]) == "end": return msg[0:-len(marker)] elif weechat.config_string(fish_config_option["mark_position"]) == "begin": return msg[len(marker):] else: return msg
def teknik_command(data, buffer, args): args = args.strip() if args == "": weechat.prnt("", "Error: You must specify a command") else: argv = args.split(" ") command = argv[0].lower() # Upload a File if command == 'upload': if len(argv) < 2: weechat.prnt("", "Error: You must specify a file") else: # Get current config values apiUrl = weechat.config_string( weechat.config_get('plugins.var.python.teknik.api_url')) apiUsername = weechat.config_string( weechat.config_get('plugins.var.python.teknik.username')) apiToken = weechat.config_string( weechat.config_get('plugins.var.python.teknik.token')) data = { 'file': argv[1], 'apiUrl': apiUrl, 'apiUsername': apiUsername, 'apiToken': apiToken } hook = weechat.hook_process('func:upload_file', 0, "process_upload", json.dumps(data)) # Set a config option elif command == 'set': if len(argv) < 2: weechat.prnt("", "Error: You must specify the option to set") else: option = argv[1].lower() if option == 'username': if len(argv) < 3: weechat.prnt("", "Error: You must specify a username") else: teknik_set_username(argv[2]) elif option == 'token': if len(argv) < 3: weechat.prnt("", "Error: You must specify an auth token") else: teknik_set_token(argv[2]) elif option == 'url': if len(argv) < 3: weechat.prnt("", "Error: You must specify an api url") else: teknik_set_url(argv[2]) else: weechat.prnt("", "Error: Unrecognized Option") else: weechat.prnt("", "Error: Unrecognized Command") return weechat.WEECHAT_RC_OK
def handle_bouncer_msg(data, signal, signal_data): server_name = signal.split(",")[0] msg = weechat.info_get_hashtable("irc_message_parse", {"message": signal_data}) args = msg["arguments"].split(" ") if args[0] != "NETWORK": return weechat.WEECHAT_RC_OK # Don't connect twice to the same network netid = args[1] if netid in added_networks: return weechat.WEECHAT_RC_OK_EAT # Retrieve the network name from the attributes net_name = None raw_attr_list = args[2].split(";") for raw_attr in raw_attr_list: k, v = raw_attr.split("=") if k == "name": net_name = v break check_char = lambda ch: ch.isalnum() or ch in ".-_" net_name = "".join(ch if check_char(ch) else "_" for ch in net_name) addr = weechat.config_string( weechat.config_get("irc.server." + server_name + ".addresses")) add_server = [ "/server", "add", net_name, addr, "-temp", "-ssl", ] # User name settings need to be adapted for new networks for k in ["username", "sasl_username"]: v = weechat.config_string( weechat.config_get("irc.server." + server_name + "." + k)) if not v: continue username = v.split("/", maxsplit=1)[0] + "/" + net_name add_server.append("-" + k + "=" + username) for k in ["password", "sasl_mechanism", "sasl_password"]: v = weechat.config_string( weechat.config_get("irc.server." + server_name + "." + k)) add_server.append("-" + k + "=" + v) weechat.command(weechat.buffer_search("core", "weechat"), " ".join(add_server)) weechat.command(weechat.buffer_search("core", "weechat"), "/connect " + net_name) return weechat.WEECHAT_RC_OK_EAT
def ircrypt_encrypt_hook(data, msgtype, server, args): '''Hook for outgoing PRVMSG commands. This method will call the appropriate methods for encrypting the outgoing messages either symmetric or asymmetric :param data: :param msgtype: :param server: IRC server the message comes from. :param args: IRC command line- ''' info = weechat.info_get_hashtable("irc_message_parse", {"message": args}) # check if this message is to be send as plain text plain = ircrypt_message_plain.get('%s/%s' % (server, info['channel'])) if plain: del ircrypt_message_plain['%s/%s' % (server, info['channel'])] if (plain[0] - time.time()) < 5 \ and args == 'PRIVMSG %s :%s' % (info['channel'], plain[1]): args = args.replace( 'PRIVMSG %s :%s ' % (info['channel'], weechat.config_string(ircrypt_config_option['unencrypted'])), 'PRIVMSG %s :' % info['channel']) return args # check symmetric key key = ircrypt_keys.get(('%s/%s' % (server, info['channel'])).lower()) if not key: # No key -> don't encrypt return args # Get cipher cipher = ircrypt_cipher.get( ('%s/%s' % (server, info['channel'])).lower(), weechat.config_string(ircrypt_config_option['sym_cipher'])) # Get prefix and message pre, message = args.split(':', 1) # encrypt message try: inp = key.encode('utf-8') + b'\n' + message.encode('utf-8') except: inp = key + b'\n' + message (ret, out, err) = ircrypt_gnupg(inp, '--symmetric', '--cipher-algo', cipher, '--passphrase-fd', '-') # Get and print GPG errors/warnings if ret: buf = weechat.buffer_search('irc', '%s.%s' % (server, info['channel'])) ircrypt_error(err.decode('utf-8'), buf) return args if err: ircrypt_warn(err.decode('utf-8')) # Ensure the generated messages are not too long and send them return ircrypt_split_msg(pre, 'CRY', base64.b64encode(out).decode('utf-8'))
def ircrypt_encrypt_hook(data, msgtype, server, args): '''Hook for outgoing PRVMSG commands. This method will call the appropriate methods for encrypting the outgoing messages either symmetric or asymmetric :param data: :param msgtype: :param server: IRC server the message comes from. :param args: IRC command line- ''' info = weechat.info_get_hashtable("irc_message_parse", { "message": args }) # check if this message is to be send as plain text plain = ircrypt_message_plain.get('%s/%s' % (server, info['channel'])) if plain: del ircrypt_message_plain['%s/%s' % (server, info['channel'])] if (plain[0] - time.time()) < 5 \ and args == 'PRIVMSG %s :%s' % (info['channel'], plain[1]): args = args.replace('PRIVMSG %s :%s ' % ( info['channel'], weechat.config_string(ircrypt_config_option['unencrypted'])), 'PRIVMSG %s :' % info['channel']) return args # check symmetric key key = ircrypt_keys.get(('%s/%s' % (server, info['channel'])).lower()) if not key: # No key -> don't encrypt return args # Get cipher cipher = ircrypt_cipher.get(('%s/%s' % (server, info['channel'])).lower(), weechat.config_string(ircrypt_config_option['sym_cipher'])) # Get prefix and message pre, message = args.split(':', 1) # encrypt message try: inp = key.encode('utf-8') + b'\n' + message.encode('utf-8') except: inp = key + b'\n' + message (ret, out, err) = ircrypt_gnupg(inp, '--symmetric', '--cipher-algo', cipher, '--passphrase-fd', '-') # Get and print GPG errors/warnings if ret: buf = weechat.buffer_search('irc', '%s.%s' % (server, info['channel'])) ircrypt_error(err.decode('utf-8'), buf) return args if err: ircrypt_warn(err.decode('utf-8')) # Ensure the generated messages are not too long and send them return ircrypt_split_msg(pre, 'CRY', base64.b64encode(out).decode('utf-8'))
def init_options(): # check out if a default item bar exists for option,value in OPTIONS.items(): if not weechat.config_get_plugin(option): default_bar = weechat.config_string(weechat.config_get(value))# get original option weechat.config_set_plugin(option, default_bar) default_option = option.split('.') default_bar_value = weechat.config_string(weechat.config_get('weechat.bar.%s.items' % default_option[1])) DEFAULT_OPTION[default_option[1]] = default_bar_value else: default_option = option.split('.') default_bar_value = weechat.config_string(weechat.config_get('weechat.bar.%s.items' % default_option[1])) DEFAULT_OPTION[default_option[1]] = default_bar_value
def hlpv_item_add(buffer, highlight, prefix, message): """ Add message to list of messages (will be displayed by item). """ global hlpv_messages if highlight == "1": color_type = weechat.config_string( weechat.config_get("weechat.color.status_data_highlight")) color_string_highlight = weechat.config_get_plugin( "color_string_highlight") if color_string_highlight == "": color_string_highlight = color_type string_prefix = "%s%s" % ( weechat.color(color_string_highlight), weechat.config_get_plugin("string_highlight")) else: color_type = weechat.config_string( weechat.config_get("weechat.color.status_data_private")) color_string_private = weechat.config_get_plugin( "color_string_private") if color_string_private == "": color_string_private = color_type string_prefix = "%s%s" % (weechat.color(color_string_private), weechat.config_get_plugin("string_private")) color_delimiter = weechat.color( weechat.config_get_plugin("color_delimiter")) if weechat.config_get_plugin("buffer_number") == "on": color_buffer_number = weechat.config_get_plugin("color_buffer_number") if color_buffer_number == "": color_buffer_number = color_type buffer_number = "%s%s%s:" % (weechat.color(color_buffer_number), weechat.buffer_get_integer( buffer, "number"), color_delimiter) else: buffer_number = "" color_buffer_name = weechat.color( weechat.config_get_plugin("color_buffer_name")) if weechat.config_get_plugin("buffer_short_name") == "on": buffer_name = weechat.buffer_get_string(buffer, "short_name") else: buffer_name = weechat.buffer_get_string(buffer, "name") color_prefix = weechat.color(weechat.config_get_plugin("color_prefix")) string_delimiter = weechat.config_get_plugin("string_delimiter") color_message = weechat.color(weechat.config_get_plugin("color_message")) string = "%s%s%s%s: %s%s%s%s%s%s" % ( string_prefix, buffer_number, color_buffer_name, buffer_name, color_prefix, prefix, color_delimiter, string_delimiter, color_message, message) if len(hlpv_messages) == 0: hlpv_timer() hlpv_messages.append(string) weechat.bar_item_update("hlpv")
def reload(self): ''' Load configuration variables. ''' self.case_sensitive = weechat.config_boolean(self.__case_sensitive) self.group_irc = weechat.config_boolean(self.__group_irc) rules_blob = weechat.config_string(self.__rules) replacements_blob = weechat.config_string(self.__replacements) signals_blob = weechat.config_string(self.__signals) self.rules = RuleList.decode(rules_blob, self.case_sensitive) self.replacements = decode_replacements(replacements_blob) self.signals = signals_blob.split() self.sort_on_config = weechat.config_boolean(self.__sort_on_config)
def reload(self): ''' Load configuration variables. ''' self.case_sensitive = weechat.config_boolean(self.__case_sensitive) self.group_irc = weechat.config_boolean(self.__group_irc) rules_blob = weechat.config_string(self.__rules) replacements_blob = weechat.config_string(self.__replacements) signals_blob = weechat.config_string(self.__signals) self.rules = RuleList.decode(rules_blob) self.replacements = decode_replacements(replacements_blob) self.signals = signals_blob.split() self.sort_on_config = weechat.config_boolean(self.__sort_on_config)
def reload(self): ''' Load configuration variables. ''' self.case_sensitive = weechat.config_boolean(self.__case_sensitive) rules_blob = weechat.config_string(self.__rules) helpers_blob = weechat.config_string(self.__helpers) signals_blob = weechat.config_string(self.__signals) self.rules = decode_rules(rules_blob) self.helpers = decode_helpers(helpers_blob) self.signals = signals_blob.split() self.signal_delay = weechat.config_integer(self.__signal_delay) self.sort_on_config = weechat.config_boolean(self.__sort_on_config)
def handle_bouncer_msg(data, signal, signal_data): server = signal.split(",")[0] msg = weechat.info_get_hashtable("irc_message_parse", {"message": signal_data}) args = msg["arguments"].split(" ") if args[0] != "NETWORK": return weechat.WEECHAT_RC_OK # Don't connect twice to the same network netid = args[1] if netid in added_networks: return weechat.WEECHAT_RC_OK_EAT # Retrieve the network name from the attributes net_name = None raw_attr_list = args[2].split(";") for raw_attr in raw_attr_list: k, v = raw_attr.split("=") if k == "name": net_name = v break addr = weechat.config_string( weechat.config_get("irc.server." + server + ".addresses")) username = weechat.config_string( weechat.config_get("irc.server." + server + ".username")) if "/" in username: username = username.split("/")[0] add_server = [ "/server", "add", net_name, addr, "-temp", "-ssl", "-username="******"/" + net_name, ] for k in ["password", "sasl_mechanism", "sasl_username", "sasl_password"]: v = weechat.config_string( weechat.config_get("irc.server." + server + "." + k)) add_server.append("-" + k + "=" + v) weechat.command(weechat.buffer_search("core", "weechat"), " ".join(add_server)) weechat.command(weechat.buffer_search("core", "weechat"), "/connect " + net_name) return weechat.WEECHAT_RC_OK_EAT
def _format_action(server, target, nick, text): white = w.color("white") snick = w.info_get("irc_nick", server) if snick == nick: nickc = white else: nickc = w.color(w.info_get("nick_color_name", nick)) chanc = w.color(w.config_string( w.config_get("weechat.color.chat_channel"))) delim = w.color( w.config_string(w.config_get("weechat.color.chat_delimiters"))) reset = w.color("reset") return f" {white}* {delim}({reset}{target[0]}{delim}){nickc}{nick}{reset} {text}"
def shouldRefresh(message): """Determine whether the recency should be refreshed by checking to see if it was highlighted by the pre-existing highlight configuration.""" words_option = weechat.config_get('weechat.look.highlight') highlight_words = weechat.config_string(words_option) regex_option = weechat.config_get('weechat.look.highlight_regex') highlight_regex = weechat.config_string(regex_option) regexes = [x.strip() for x in highlight_regex.split(',')] regex_match = False for regex in regexes: if weechat.string_has_highlight_regex(message, regex): regex_match = True break return (weechat.string_has_highlight(message, highlight_words) or regex_match)
def obtain_fmuser(who = None, network = None): api_key = weechat.config_string(weechat.config_get(CONF_PREFIX + CONFKEY_APIKEY)) username = weechat.config_string(weechat.config_get(CONF_PREFIX + CONFKEY_USER)) timeout_begin() if not network: network = pylast.LastFMNetwork(api_key = api_key) if who: user = network.get_user(who) else: user = network.get_user(username) timeout_end() return (network, user)
def teknik_command(data, buffer, args): args = args.strip() if args == "": weechat.prnt("", "Error: You must specify a command") else: argv = args.split(" ") command = argv[0].lower() # Upload a File if command == 'upload': if len(argv) < 2: weechat.prnt("", "Error: You must specify a file") else: # Get current config values apiUrl = weechat.config_string(weechat.config_get('plugins.var.python.teknik.api_url')) apiUsername = weechat.config_string(weechat.config_get('plugins.var.python.teknik.username')) apiToken = weechat.config_string(weechat.config_get('plugins.var.python.teknik.token')) data = {'file': argv[1], 'apiUrl': apiUrl, 'apiUsername': apiUsername, 'apiToken': apiToken} hook = weechat.hook_process('func:upload_file', 0, "process_upload", json.dumps(data)) # Set a config option elif command == 'set': if len(argv) < 2: weechat.prnt("", "Error: You must specify the option to set") else: option = argv[1].lower() if option == 'username': if len(argv) < 3: weechat.prnt("", "Error: You must specify a username") else: teknik_set_username(argv[2]) elif option == 'token': if len(argv) < 3: weechat.prnt("", "Error: You must specify an auth token") else: teknik_set_token(argv[2]) elif option == 'url': if len(argv) < 3: weechat.prnt("", "Error: You must specify an api url") else: teknik_set_url(argv[2]) else: weechat.prnt("", "Error: Unrecognized Option") else: weechat.prnt("", "Error: Unrecognized Command") return weechat.WEECHAT_RC_OK
def reload(self): ''' Load configuration variables. ''' self.case_sensitive = weechat.config_boolean(self.__case_sensitive) self.group_irc = weechat.config_boolean(self.__group_irc) rules_blob = weechat.config_string(self.__rules) self.rules = RuleList.decode(rules_blob)
def join_cb(data, signal, signal_data): server = signal.split(',')[0] if weechat.info_get("irc_nick_from_host", signal_data) != weechat.info_get( "irc_nick", server): # nick which has joined is not our current nick return weechat.WEECHAT_RC_OK weechat.command("", "/mute /set irc.server.%s.autoconnect on" % (server, )) channel = signal_data.split()[-1][1:] # Fix up prefixless channels, : prefixed channels channel = channel if channel[0] != ':' else channel[1:] channel = '#' + channel if channel[0] != '#' else channel autojoin = weechat.config_string( weechat.config_get("irc.server.%s.autojoin" % (server, ))) if autojoin: autojoin = ','.join( ['#' + w if w[0] != '#' else w for w in autojoin.split(',')]) if not channel in autojoin.split(','): weechat.command( "", "/mute /set irc.server.%s.autojoin %s,%s" % (server, autojoin, channel)) else: weechat.command( "", "/mute /set irc.server.%s.autojoin %s" % (server, autojoin)) else: weechat.command( "", "/mute /set irc.server.%s.autojoin %s" % (server, channel)) weechat.command("", "/save irc") return weechat.WEECHAT_RC_OK
def customize_kick_cb(data, modifier, modifier_data, string): message = weechat.config_get_plugin('kick_message') if message == '': return string parsed = get_hashtable(string) try: parsed['kicked_nick'] = parsed['arguments'].split(' ', 1)[1] parsed['kicked_nick'] = parsed['kicked_nick'].split(' :', 1)[0] except: parsed['kicked_nick'] = '' message = create_output(message,parsed,'kick') if OPTIONS['debug'] == 'on': weechat.prnt("",string) weechat.prnt("",parsed['channel']) weechat.prnt("",parsed['message']) buf_pointer = weechat.buffer_search('irc',"%s.%s" % (modifier_data,parsed['channel'])) prefix = weechat.config_string(weechat.config_get('weechat.look.prefix_quit')) prefix_color = weechat.color(weechat.config_color(weechat.config_get('weechat.color.chat_prefix_quit'))) message_tags = '' if weechat.config_get_plugin('no_log').lower() == 'on': message_tags = 'no_log' weechat.prnt_date_tags(buf_pointer,0,message_tags,'%s%s\t%s' % (prefix_color,prefix,message)) return string
def fish_alert(buffer, message): mark = "%s%s%s\t" % ( weechat.color(weechat.config_color(fish_config_option["alert"])), weechat.config_string(fish_config_option["marker"]), weechat.color("chat")) weechat.prnt(buffer, "%s%s" % (mark, message))
def theme_config_color(color): """Get a color from configuration.""" global theme_config_option option = theme_config_option.get('color_%s' % color, '') if not option: return '' return weechat.color(weechat.config_string(option))
def buffer_switch(data, signal, signal_data): full_name = weechat.buffer_get_string( signal_data, 'full_name') # get full_name of current buffer if full_name == '': # upps, something totally wrong! return weechat.WEECHAT_RC_OK for option in list(OPTIONS.keys()): option = option.split('.') customize_plugin = weechat.config_get_plugin( '%s.%s' % (option[1], full_name)) # for example: title.irc.freenode.#weechat if customize_plugin: # option exists config_pnt = weechat.config_get('weechat.bar.%s.items' % option[1]) # current_bar = weechat.config_string(weechat.config_get('weechat.bar.%s.items' % option[1])) weechat.config_option_set(config_pnt, customize_plugin, 1) # set customize_bar else: current_bar = weechat.config_string( weechat.config_get('weechat.bar.%s.items' % option[1])) default_plugin = weechat.config_get_plugin( 'default.%s' % option[1]) # option we are looking for if default_plugin == '': # default_plugin removed by user? weechat.config_set_plugin( 'default.%s' % option[1], DEFAULT_OPTION[option[1]]) # set default_plugin again! if current_bar != default_plugin: config_pnt = weechat.config_get('weechat.bar.%s.items' % option[1]) weechat.config_option_set(config_pnt, default_plugin, 1) # set customize_bar return weechat.WEECHAT_RC_OK
def get_autojoin_list(server): ptr_config_autojoin = weechat.config_get("irc.server.%s.autojoin" % server) # option not found! server does not exist if not ptr_config_autojoin: weechat.prnt(buffer, "%s%s: server '%s' does not exist." % (weechat.prefix("error"), SCRIPT_NAME, server)) return weechat.WEECHAT_RC_OK # get value from autojoin option channels = weechat.config_string(ptr_config_autojoin) if not channels: return 1, 1 # check for keys if len(re.findall(r" ", channels)) == 0: list_of_channels = channels.split(",") list_of_keys = [] elif len(re.findall(r" ", channels)) == 1: list_of_channels2, list_of_keys = channels.split(" ") list_of_channels = list_of_channels2.split(",") else: weechat.prnt("", "%s%s: irc.server.%s.autojoin not valid..." % (weechat.prefix("error"), SCRIPT_NAME, server)) return 0, 0 return list_of_channels, list_of_keys
def config_cb(data, option, value): weechat.config_set_plugin( "nick_format", weechat.config_string( weechat.config_get("plugins.var.python." + SCRIPT_NAME + ".nick_format"))) return weechat.WEECHAT_RC_OK
def wg_update_cache(): """ Download list of scripts and update local cache. """ global wg_config_option, wg_hook_process, wg_stdout # get data from website, via hook_process if wg_hook_process["update"] != "": weechat.unhook(wg_hook_process["update"]) wg_hook_process["update"] = "" weechat.prnt("", "%s: downloading list of scripts..." % SCRIPT_NAME) wg_stdout["update"] = "" wg_config_create_dir() url = weechat.config_string(wg_config_option["scripts_url"]) filename = wg_config_get_cache_filename() python2_bin = weechat.info_get("python2_bin", "") or "python" wg_hook_process["update"] = weechat.hook_process( python2_bin + " -c \"import urllib, urllib2\n" "req = urllib2.Request('" + url + "')\n" "try:\n" " response = urllib2.urlopen(req)\n" " file = open('" + filename + "', 'w')\n" " file.write(response.read())\n" " response.close()\n" " file.close()\n" "except urllib2.URLError, e:\n" " print 'error:%s' % e.code\n" "\"", TIMEOUT_UPDATE, "wg_process_update_cb", "")
def wg_config_color(color): """ Get a color from configuration. """ global wg_config_option option = wg_config_option.get("color_" + color, "") if option == "": return "" return weechat.color(weechat.config_string(option))
def get_config_options(): global COLOR_RESET, COLOR_CHAT_DELIMITERS, COLOR_CHAT_NICK, COLOR_CHAT_HOST, \ COLOR_CHAT_CHANNEL, COLOR_CHAT, COLOR_MESSAGE_JOIN, COLOR_MESSAGE_QUIT, \ COLOR_REASON_QUIT, SMART_FILTER global send_signals, znc_timestamp config_get_string = lambda s: weechat.config_string(weechat.config_get(s)) COLOR_RESET = weechat.color('reset') COLOR_CHAT_DELIMITERS = weechat.color('chat_delimiters') COLOR_CHAT_NICK = weechat.color('chat_nick') COLOR_CHAT_HOST = weechat.color('chat_host') COLOR_CHAT_CHANNEL = weechat.color('chat_channel') COLOR_CHAT = weechat.color('chat') COLOR_MESSAGE_JOIN = weechat.color( config_get_string('irc.color.message_join')) COLOR_MESSAGE_QUIT = weechat.color( config_get_string('irc.color.message_quit')) COLOR_REASON_QUIT = weechat.color( config_get_string('irc.color.reason_quit')) SMART_FILTER = weechat.config_boolean( weechat.config_get("irc.look.smart_filter")) send_signals = get_config_boolean('send_signals') znc_timestamp = weechat.config_get_plugin('timestamp')
def customize_privmsg_cb(data, modifier, modifier_data, string): weechat.prnt("",data) weechat.prnt("",modifier) weechat.prnt("",modifier_data) weechat.prnt("",string) parsed = get_hashtable(string) message = parsed['message'].strip() # Filter out non-CTCP messages and non ACTION messages if not message or ord(message[0]) != 1 or not message[1:].startswith("ACTION"): return string text = message[8:-1] parsed['kicked_nick'] = '' # dummy. no irc_KICK here parsed['message'] = text message = create_output("${*blue}%N %M",parsed,'action') buffer_ptr = weechat.buffer_search('irc',"%s.%s" % (modifier_data,parsed['channel'])) prefix = weechat.config_string(weechat.config_get('weechat.look.prefix_action')) prefix_color = weechat.color(weechat.config_color(weechat.config_get('weechat.color.chat_prefix_action'))) prefix = substitute_colors(prefix) message_tags = '' if weechat.config_get_plugin('no_log').lower() == 'on': message_tags = 'no_log' weechat.prnt_date_tags(buffer_ptr,0,message_tags,'%s%s\t%s' % (prefix_color,prefix,message)) return string
def customize_join_cb_signal(data, signal, signal_data): weechat.prnt("", "data: %s signal: %s signal_data: %s" % (data, signal, signal_data)) message = weechat.config_get_plugin("join_message") if message == "": return weechat.WEECHAT_RC_OK parsed = get_hashtable(signal_data) if parsed["nick"] == own_nick(signal.split(",", 1)[0]): return weechat.WEECHAT_RC_OK parsed["message"] = "" # dummy. no message for JOIN parsed["kicked_nick"] = "" # dummy. no KICK here message = create_output(message, parsed, "join") buffer_ptr = weechat.buffer_search("irc", "%s.%s" % (signal.split(",", 1)[0], parsed["channel"])) prefix = weechat.config_string(weechat.config_get("weechat.look.prefix_join")) prefix_color = weechat.color(weechat.config_color(weechat.config_get("weechat.color.chat_prefix_join"))) message_tags = "" if weechat.config_get_plugin("no_log").lower() == "on": message_tags = "no_log" weechat.prnt_date_tags(buffer_ptr, 0, message_tags, "%s%s\t%s" % (prefix_color, prefix, message)) return weechat.WEECHAT_RC_OK
def customize_kick_cb(data, modifier, modifier_data, string): message = weechat.config_get_plugin("kick_message") if message == "": return string parsed = get_hashtable(string) try: parsed["kicked_nick"] = parsed["arguments"].split(" ", 1)[1] parsed["kicked_nick"] = parsed["kicked_nick"].split(" :", 1)[0] except: parsed["kicked_nick"] = "" message = create_output(message, parsed, "kick") if OPTIONS["debug"] == "on": weechat.prnt("", string) weechat.prnt("", parsed["channel"]) weechat.prnt("", parsed["message"]) buffer_ptr = weechat.buffer_search("irc", "%s.%s" % (modifier_data, parsed["channel"])) if not (buffer_ptr): return string prefix = weechat.config_string(weechat.config_get("weechat.look.prefix_quit")) prefix_color = weechat.color(weechat.config_color(weechat.config_get("weechat.color.chat_prefix_quit"))) message_tags = "" if weechat.config_get_plugin("no_log").lower() == "on": message_tags = "no_log" weechat.prnt_date_tags(buffer_ptr, 0, message_tags, "%s%s\t%s" % (prefix_color, prefix, message)) return string
def theme_config_get_cache_filename(): """Get local cache filename, based on URL.""" global theme_config_option return '%s/%s' % (theme_config_get_dir(), os.path.basename( weechat.config_string( theme_config_option['scripts_url'])))
def init_options(): # check out if a default item bar exists for option, value in list(OPTIONS.items()): if not weechat.config_get_plugin(option): default_bar = weechat.config_string( weechat.config_get(value)) # get original option weechat.config_set_plugin(option, default_bar) default_option = option.split('.') default_bar_value = weechat.config_string( weechat.config_get('weechat.bar.%s.items' % default_option[1])) DEFAULT_OPTION[default_option[1]] = default_bar_value else: default_option = option.split('.') default_bar_value = weechat.config_string( weechat.config_get('weechat.bar.%s.items' % default_option[1])) DEFAULT_OPTION[default_option[1]] = default_bar_value
def buffer_switch_cb(data, signal, signal_data): global look_server look_server = "" look_server = weechat.config_string( weechat.config_get("irc.look.server_buffer")) if look_server == "independent": # server buffer independent? return weechat.WEECHAT_RC_OK # better remove script, you don't need it. if weechat.buffer_get_string( signal_data, 'name') != 'weechat': # not weechat core buffer if (weechat.buffer_get_string(signal_data, 'localvar_type') == '') or (weechat.buffer_get_string( signal_data, 'localvar_type') == 'server'): return weechat.WEECHAT_RC_OK elif weechat.buffer_get_string(signal_data, 'name') == 'weechat': return weechat.WEECHAT_RC_OK # buffer is channel or private? if (weechat.buffer_get_string(signal_data, 'localvar_type') == 'channel') or (weechat.buffer_get_string( signal_data, 'localvar_type') == 'private'): bufpointer = weechat.window_get_pointer(weechat.current_window(), "buffer") servername_from_current_buffer = weechat.buffer_get_string( bufpointer, 'localvar_server') name = weechat.buffer_get_string(bufpointer, 'name') server_switch(signal_data, servername_from_current_buffer, name) return weechat.WEECHAT_RC_OK
def on_msg(*a): if len(a) == 8: data, buffer, timestamp, tags, displayed, highlight, sender, message = a #return when sender is weechat.look.prefix_network option = w.config_get("weechat.look.prefix_network") if sender == w.config_string(option): return w.WEECHAT_RC_OK if data == "private" or highlight == "1": #set buffer buffer = "me" if data == "private" else w.buffer_get_string(buffer, "short_name") #set time - displays message forever on highlight if highlight == "1" and data == "private": mtype = "private_highlight" icon = w.config_get_plugin('pm-icon') time = w.config_get_plugin('display_time_private_highlight') elif highlight == "1": mtype = "highlight" icon = w.config_get_plugin('icon') time = w.config_get_plugin('display_time_highlight') else: mtype = "private" icon = w.config_get_plugin('pm-icon') time = w.config_get_plugin('display_time_default') urgency = w.config_get_plugin('urgency_default') #sent run_notify(mtype, urgency, icon, time, sender, buffer, message) #w.prnt("", str(a)) return w.WEECHAT_RC_OK
def print_usage(data, buffer, args): weechat.prnt( buffer, "%s\t%s: script already running..." % (string_eval_expression( weechat.config_string( weechat.config_get("weechat.look.prefix_error"))), SCRIPT_NAME)) return weechat.WEECHAT_RC_OK
def fish_secure_key_cb(data, option, value): global fish_secure_key, fish_secure_cipher fish_secure_key = weechat.config_string( weechat.config_get("fish.secure.key") ) if fish_secure_key == "": fish_secure_cipher = None return weechat.WEECHAT_RC_OK if fish_secure_key[:6] == "${sec.": decrypted = weechat.string_eval_expression( fish_secure_key, {}, {}, {} ) if decrypted: fish_secure_cipher = Blowfish(decrypted) return weechat.WEECHAT_RC_OK else: weechat.config_option_set(fish_config_option["key"], "", 0) weechat.prnt("", "Decrypt sec.conf first\n") return weechat.WEECHAT_RC_OK if fish_secure_key != "": fish_secure_cipher = Blowfish(fish_secure_key) return weechat.WEECHAT_RC_OK
def customize_join_cb(data, modifier, modifier_data, string): message = weechat.config_get_plugin("join_message") if message == "": return string parsed = get_hashtable(string) if parsed["nick"] == own_nick(modifier_data): return string parsed["message"] = "" # dummy. no message for irc_JOIN parsed["kicked_nick"] = "" # dummy. no irc_KICK here message = create_output(message, parsed, "join") if OPTIONS["debug"] == "on": weechat.prnt("", string) weechat.prnt("", parsed["channel"]) weechat.prnt("", parsed["message"]) buffer_ptr = weechat.buffer_search("irc", "%s.%s" % (modifier_data, parsed["channel"])) prefix = weechat.config_string(weechat.config_get("weechat.look.prefix_join")) prefix_color = weechat.color(weechat.config_color(weechat.config_get("weechat.color.chat_prefix_join"))) prefix = substitute_colors(prefix) message_tags = "" if weechat.config_get_plugin("no_log").lower() == "on": message_tags = "no_log" weechat.prnt_date_tags(buffer_ptr, 0, message_tags, "%s%s\t%s" % (prefix_color, prefix, message)) return string
def customize_join_cb_signal(data, signal, signal_data): weechat.prnt("","data: %s signal: %s signal_data: %s" % (data,signal,signal_data)) message = weechat.config_get_plugin('join_message') if message == '': return weechat.WEECHAT_RC_OK parsed = get_hashtable(signal_data) if parsed['nick'] == own_nick(signal.split(',', 1)[0]): return weechat.WEECHAT_RC_OK parsed['message'] = "" # dummy. no message for JOIN parsed['kicked_nick'] = '' # dummy. no KICK here message = create_output(message,parsed,'join') buf_pointer = weechat.buffer_search('irc',"%s.%s" % (signal.split(',', 1)[0],parsed['channel'])) prefix = weechat.config_string(weechat.config_get('weechat.look.prefix_join')) prefix_color = weechat.color(weechat.config_color(weechat.config_get('weechat.color.chat_prefix_join'))) message_tags = '' if weechat.config_get_plugin('no_log').lower() == 'on': message_tags = 'no_log' weechat.prnt_date_tags(buf_pointer,0,message_tags,'%s%s\t%s' % (prefix_color,prefix,message)) return weechat.WEECHAT_RC_OK
def customize_part_cb(data, modifier, modifier_data, string): message = weechat.config_get_plugin('part_message') if message == '': return string parsed = get_hashtable(string) if parsed['nick'] == own_nick(modifier_data): return string parsed['kicked_nick'] = '' # dummy. no irc_KICK here message = create_output(message,parsed,'part') if OPTIONS['debug'] == 'on': weechat.prnt("","debug mode: irc_part") weechat.prnt("","string: %s" % string) weechat.prnt("",parsed['channel']) weechat.prnt("",parsed['message']) buf_pointer = weechat.buffer_search('irc',"%s.%s" % (modifier_data,parsed['channel'])) prefix = weechat.config_string(weechat.config_get('weechat.look.prefix_quit')) prefix_color = weechat.color(weechat.config_color(weechat.config_get('weechat.color.chat_prefix_quit'))) prefix = substitute_colors(prefix) message_tags = '' if weechat.config_get_plugin('no_log').lower() == 'on': message_tags = 'no_log' weechat.prnt_date_tags(buf_pointer,0,message_tags,'%s%s\t%s' % (prefix_color,prefix,message)) return string
def fish_secure(): global fish_secure_key, fish_secure_cipher fish_secure_key = weechat.config_string(fish_config_option["key"]) # if blank, do nothing if fish_secure_key == "": fish_success() return # if ${sec.data.fish}, check if sec.conf is decrypted # and decrypt elif fish_secure_key[:6] == "${sec.": decrypted = weechat.string_eval_expression(fish_secure_key, {}, {}, {}) if decrypted: fish_secure_cipher = Blowfish(decrypted) fish_decrypt_keys() fish_success() return else: global SCRIPT_NAME fish_secure_error() weechat.command(weechat.current_buffer(), "/wait 1ms /python unload %s" % SCRIPT_NAME) return # if key is neither ${sec.data.fish} or "" # encrypt/decrypt with user supplied, plain text key if fish_secure_key != "": fish_secure_cipher = Blowfish(fish_secure_key) fish_decrypt_keys() fish_success() return
def wg_update_cache(): """ Download list of scripts and update local cache. """ global wg_config_option, wg_hook_process, wg_stdout # get data from website, via hook_process if wg_hook_process["update"] != "": weechat.unhook(wg_hook_process["update"]) wg_hook_process["update"] = "" weechat.prnt("", "%s: downloading list of scripts..." % SCRIPT_NAME) wg_stdout["update"] = "" wg_config_create_dir() url = weechat.config_string(wg_config_option["scripts_url"]) filename = wg_config_get_cache_filename() wg_hook_process["update"] = weechat.hook_process( "python -c \"import urllib, urllib2\n" "req = urllib2.Request('" + url + "')\n" "try:\n" " response = urllib2.urlopen(req)\n" " file = open('" + filename + "', 'w')\n" " file.write(response.read())\n" " response.close()\n" " file.close()\n" "except urllib2.URLError, e:\n" " print 'error:%s' % e.code\n" "\"", TIMEOUT_UPDATE, "wg_process_update_cb", "")
def print_messages(mailbox='INBOX'): ''' Print all unread messages in a folder to buffer ''' global imap_buffer, active_message_line, active_message_uid w.buffer_clear(imap_buffer) imap = Imap() typ, data = imap.messages(mailbox) if not typ == 'OK': print 'bad type returned' imap.logout() return y = 0 for num in data[0].split(): typ, data = imap.conn.fetch(num, '(FLAGS INTERNALDATE BODY[HEADER.FIELDS (SUBJECT FROM)])') data = data[0] # only one message is returned meta, headers = data[0], data[1] #flags = re.search(r'\(FLAGS \((?P<flags>.+)\) ', meta).groupdict()['flags'] internaldate = datetime.fromtimestamp(time.mktime(i.Internaldate2tuple(meta))) internaldate = internaldate.strftime(w.config_get_plugin('time_format')) internaldate = internaldate.replace(':', '%s:%s' % (w.color(w.config_string( w.config_get('weechat.color.chat_time_delimiters'))), w.color('reset'))) internaldate = internaldate.strip() sender = re.search(r'From: ?(?P<from>.+)\s', headers, re.I) if sender: sender = sender.groupdict()['from'] subject = re.search(r'Subject: ?(?P<subject>.+)\s', headers, re.I) if subject: subject = subject.groupdict()['subject'] sender = imap.decode_helper(sender) subject = imap.decode_helper(subject) bgcolor = 'default' if y == active_message_line: active_message_uid = num bgcolor = 'red' if ' ' in sender: sender = irc_nick_find_color(sender.split()[0].strip('"')) else: sender = irc_nick_find_color(sender) w.prnt(imap_buffer, '%s %s\t%s %s' % \ (internaldate, sender, w.color('default,%s' %bgcolor), subject)) y += 1 if y == 25: break imap.logout()
def hlpv_item_add(buffer, highlight, prefix, message): """ Add message to list of messages (will be displayed by item). """ global hlpv_messages if highlight == "1": color_type = weechat.config_string(weechat.config_get("weechat.color.status_data_highlight")) color_string_highlight = weechat.config_get_plugin("color_string_highlight") if color_string_highlight == "": color_string_highlight = color_type string_prefix = "%s%s" % (weechat.color(color_string_highlight), weechat.config_get_plugin("string_highlight")) else: color_type = weechat.config_string(weechat.config_get("weechat.color.status_data_private")) color_string_private = weechat.config_get_plugin("color_string_private") if color_string_private == "": color_string_private = color_type string_prefix = "%s%s" % (weechat.color(color_string_private), weechat.config_get_plugin("string_private")) color_delimiter = weechat.color(weechat.config_get_plugin("color_delimiter")) if weechat.config_get_plugin("buffer_number") == "on": color_buffer_number = weechat.config_get_plugin("color_buffer_number") if color_buffer_number == "": color_buffer_number = color_type buffer_number = "%s%s%s:" % (weechat.color(color_buffer_number), weechat.buffer_get_integer(buffer, "number"), color_delimiter) else: buffer_number = "" color_buffer_name = weechat.color(weechat.config_get_plugin("color_buffer_name")) if weechat.config_get_plugin("buffer_short_name") == "on": buffer_name = weechat.buffer_get_string(buffer, "short_name") else: buffer_name = weechat.buffer_get_string(buffer, "name") color_prefix = weechat.color(weechat.config_get_plugin("color_prefix")) string_delimiter = weechat.config_get_plugin("string_delimiter") color_message = weechat.color(weechat.config_get_plugin("color_message")) string = "%s%s%s%s: %s%s%s%s%s%s" % (string_prefix, buffer_number, color_buffer_name, buffer_name, color_prefix, prefix, color_delimiter, string_delimiter, color_message, message) if len(hlpv_messages) == 0: hlpv_timer() hlpv_messages.append(string) weechat.bar_item_update("hlpv")
def __getitem__(self, key): if key == "historysize": return weechat.config_integer(self.data[key]) elif key == 'output_main_buffer': return weechat.config_boolean(self.data[key]) #elif key.startswith('color'): # return weechat.config_color(self.data[key]) else: return weechat.config_string(self.data[key])
def irc_nick_find_color(nick): color = weechat.info_get('irc_nick_color', nick) if not color: # probably we're in WeeChat 0.3.0 color %= weechat.config_integer(weechat.config_get("weechat.look.color_nicks_number")) color = weechat.config_get('weechat.color.chat_nick_color%02d' %(color+1)) color = weechat.color(weechat.config_string(color)) return '%s%s%s' %(color, nick, weechat.color('reset'))
def fn_connected(data, signal, signal_data): global ip_from_option # check if xfer option exists own_ip_option = w.config_get("xfer.network.own_ip") if not own_ip_option: return w.WEECHAT_RC_OK ip_from_option = w.config_string(own_ip_option) w.hook_process("url:%s" % OPTIONS["url"], 60000, "fn_setip", "") return w.WEECHAT_RC_OK
def get_buffer(server, nick): msgbuffer = weechat.config_string(weechat.config_get('irc.msgbuffer.%s.%s' % (server, 'whois'))) if msgbuffer == '': msgbuffer = weechat.config_string(weechat.config_get('irc.msgbuffer.%s' % 'whois')) if msgbuffer == 'private': buffer = weechat.buffer_search('irc', '%s.%s' %(server, nick)) if buffer != '': return buffer else: msgbuffer = weechat.config_string(weechat.config_get('irc.look.msgbuffer_fallback')) if msgbuffer == "current": return weechat.current_buffer() elif msgbuffer == "weechat": return weechat.buffer_search_main() else: return weechat.buffer_search('irc', 'server.%s' % server)