def modifier_cb(data, modifier, modifier_data, string): plugin, bufname, tags = modifier_data.split(";") tags = tags.split(",") # find nick nick = "" for tag in tags: if tag[:5] == "nick_": nick = tag[5:] break if not nick: return string # handle service notices if re.search(SERVICE, nick): # remove color and excess whitespace sstring = " ".join(weechat.string_remove_color(string, "").split()) for pattern, replacement in SERVICEPATTERNS: m = re.match(pattern, sstring) if m: return replacement.format(*m.groups()) # handle snotices if re.search(SERVER, nick): # remove color and excess whitespace sstring = " ".join(weechat.string_remove_color(string, "").split()) for pattern, replacement in SERVERPATTERNS: m = re.match(pattern, sstring) if m: return replacement.format(*m.groups()) return string
def input_modifier_cb(data, modifier, modifier_data, string): """Modifier that will add help on command line (for display only).""" global cmdhelp_settings line = weechat.string_remove_color(string, '') if line == '': return string command = '' arguments = '' if weechat.string_input_for_buffer(line) != '': return string items = line.split(' ', 1) if len(items) > 0: command = items[0] if len(command) < 2: return string if len(items) > 1: arguments = items[1] if command[1:].lower() in cmdhelp_settings['ignore_commands'].split(','): return string current_buffer = weechat.current_buffer() current_window = weechat.current_window() plugin = weechat.buffer_get_pointer(current_buffer, 'plugin') msg_help = (get_help_command(plugin, command[1:], arguments) or get_list_commands(plugin, command[1:], arguments)) if not msg_help: if cmdhelp_settings['display_no_help'] != 'on': return string msg_help = weechat.color(cmdhelp_settings['color_no_help']) if command: msg_help += 'No help for command %s' % command else: msg_help += 'No help' if cmdhelp_settings['right_align'] == 'on': win_width = weechat.window_get_integer(current_window, 'win_width') input_length = weechat.buffer_get_integer(current_buffer, 'input_length') help_length = len(weechat.string_remove_color(msg_help, "")) min_space = int(cmdhelp_settings['space']) padding = int(cmdhelp_settings['right_padding']) space = win_width - input_length - help_length - padding if space < min_space: space = min_space else: space = int(cmdhelp_settings['space']) color_delimiters = cmdhelp_settings['color_delimiters'] return '%s%s%s%s%s%s%s' % (string, space * ' ', weechat.color(color_delimiters), cmdhelp_settings['prefix'], msg_help, weechat.color(color_delimiters), cmdhelp_settings['suffix'])
def input_modifier_cb(data, modifier, modifier_data, string): """Modifier that will add help on command line (for display only).""" global cmdhelp_settings line = weechat.string_remove_color(string, '') if line == '': return string command = '' arguments = '' if weechat.string_input_for_buffer(line) != '': return string items = line.split(' ', 1) if len(items) > 0: command = items[0] if len(command) < 2: return string if len(items) > 1: arguments = items[1] if command[1:].lower() in cmdhelp_settings['ignore_commands'].split(','): return string current_buffer = weechat.current_buffer() current_window = weechat.current_window() plugin = weechat.buffer_get_pointer(current_buffer, 'plugin') msg_help = get_help_command(plugin, command[1:], arguments) or get_list_commands( plugin, command[1:], arguments) if not msg_help: if cmdhelp_settings['display_no_help'] != 'on': return string msg_help = weechat.color(cmdhelp_settings['color_no_help']) if command: msg_help += 'No help for command %s' % command else: msg_help += 'No help' if cmdhelp_settings['right_align'] == 'on': win_width = weechat.window_get_integer(current_window, 'win_width') input_length = weechat.buffer_get_integer(current_buffer, 'input_length') help_length = len(weechat.string_remove_color(msg_help, "")) min_space = int(cmdhelp_settings['space']) padding = int(cmdhelp_settings['right_padding']) space = win_width - input_length - help_length - padding if space < min_space: space = min_space else: space = int(cmdhelp_settings['space']) color_delimiters = cmdhelp_settings['color_delimiters'] return '%s%s%s%s%s%s%s' % ( string, space * ' ', weechat.color(color_delimiters), cmdhelp_settings['prefix'], msg_help, weechat.color(color_delimiters), cmdhelp_settings['suffix'])
def privmsg_print_cb(server_name, modifier, modifier_data, string): plugin, buffer, tags = modifier_data.split(';', 2) if plugin != 'irc' \ or buffer[:buffer.find('.')] != server_name \ or 'irc_privmsg' not in tags: return string #debug("print data: %s" %modifier_data) #debug("print string: %s" %repr(string)) nick = string[:string.find('\t')] nick_key = weechat.string_remove_color(nick, '').lstrip('@+') #debug('print nick: %s' %_nick) try: ident = ident_nick[nick_key] #if (buffer, nick_key) not in nicklist: #debug('updating nicklist for %s %s' %(buffer, nick)) #update_nicklist(buffer) #debug('added! %s' %str((buffer, nick_key))) #nicklist.add((buffer, nick_key)) if not ident: msg = string[string.find('\t'):] return '%s~%s%s' %(ident_color, nick, msg) #return '%s%s+%s' %(nick, ident_color, msg) except KeyError: pass return string
def test_strings(): """Test string functions.""" check(weechat.charset_set('iso-8859-15') == 1) check(weechat.charset_set('') == 1) check(weechat.iconv_to_internal('iso-8859-15', 'abc') == 'abc') check(weechat.iconv_from_internal('iso-8859-15', 'abcd') == 'abcd') check(weechat.gettext('abcdef') == 'abcdef') check(weechat.ngettext('file', 'files', 1) == 'file') check(weechat.ngettext('file', 'files', 2) == 'files') check(weechat.strlen_screen('abcd') == 4) check(weechat.string_match('abcdef', 'abc*', 0) == 1) check(weechat.string_eval_path_home('test ${abc}', {}, {'abc': '123'}, {}) == 'test 123') check(weechat.string_mask_to_regex('test*mask') == 'test.*mask') check(weechat.string_has_highlight('my test string', 'test,word2') == 1) check(weechat.string_has_highlight_regex('my test string', 'test|word2') == 1) check(weechat.string_remove_color('test', '?') == 'test') check(weechat.string_is_command_char('/test') == 1) check(weechat.string_is_command_char('test') == 0) check(weechat.string_input_for_buffer('test') == 'test') check(weechat.string_input_for_buffer('/test') == '') check(weechat.string_input_for_buffer('//test') == '/test') check(weechat.string_eval_expression("100 > 50", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("-50 < 100", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("18.2 > 5", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("0xA3 > 2", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("${buffer.full_name}", {}, {}, {}) == 'core.weechat')
def banmask_cb(data, signal, signal_data): if not get_config_boolean('autowarn_bans'): return WEECHAT_RC_OK #debug('BAN: %s %s', signal, signal_data) args = signal_data.split() # sanity check if not len(args) == 4: return WEECHAT_RC_OK op, channel, mask, users = args mode = signal[-1] if '$' in mask: mask, forward = mask.split('$', 1) if forward in ignoreForwards: return WEECHAT_RC_OK if mode == 'b' and mask not in warnDB: s = ' '.join(users.split(',')) op_nick = weechat.info_get('irc_nick_from_host', op) comment = "Ban in %s by %s: %s" % (channel, op_nick, s) comment = weechat.string_remove_color(comment, '') # FIXME make expire time configurable warnDB.add(mask, comment=comment, expires=3600*24*7) return WEECHAT_RC_OK
def my_modifier_cb(data, modifier, modifier_data, string): if w.buffer_get_string(w.buffer_search('irc',modifier_data.split(";")[1]),"localvar_noirccolors") == "true": try: nick, message = string.split("\t") except ValueError, e: return string return "%s\t%s" % (nick, w.string_remove_color(message,""))
def urlscan(data, buf, args): infolist = weechat.infolist_get("buffer_lines", buf, "") lines = [] while weechat.infolist_next(infolist) == 1: lines.append( weechat.string_remove_color( weechat.infolist_string(infolist, "message"), "" ) ) weechat.infolist_free(infolist) if not lines: weechat.prnt(buf, "No URLs found") return weechat.WEECHAT_RC_OK if not weechat.config_is_set_plugin("command"): weechat.config_set_plugin("command", "urlscan") command = weechat.config_get_plugin("command") text = "\n".join(reversed(lines)) response = os.system("echo %s | %s" % (pipes.quote(text), command)) if response != 0: weechat.prnt(buf, "No URLs found") weechat.command(buf, "/window refresh") return weechat.WEECHAT_RC_OK
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 privmsg_print_cb(server_name, modifier, modifier_data, string): plugin, buffer, tags = modifier_data.split(';', 2) if plugin != 'irc' \ or buffer[:buffer.find('.')] != server_name \ or 'irc_privmsg' not in tags: return string #debug("print data: %s" %modifier_data) #debug("print string: %s" %repr(string)) nick = string[:string.find('\t')] nick_key = weechat.string_remove_color(nick, '').lstrip('@+') #debug('print nick: %s' %_nick) try: ident = ident_nick[nick_key] #if (buffer, nick_key) not in nicklist: #debug('updating nicklist for %s %s' %(buffer, nick)) #update_nicklist(buffer) #debug('added! %s' %str((buffer, nick_key))) #nicklist.add((buffer, nick_key)) if not ident: msg = string[string.find('\t'):] return '%s~%s%s' % (ident_color, nick, msg) #return '%s%s+%s' %(nick, ident_color, msg) except KeyError: pass return string
def banmask_cb(data, signal, signal_data): if not get_config_boolean('autowarn_bans'): return WEECHAT_RC_OK #debug('BAN: %s %s', signal, signal_data) args = signal_data.split() # sanity check if not len(args) == 4: return WEECHAT_RC_OK op, channel, mask, users = args mode = signal[-1] if '$' in mask: mask, forward = mask.split('$', 1) if forward in ignoreForwards: return WEECHAT_RC_OK if mode == 'b' and mask not in warnDB: s = ' '.join(users.split(',')) op_nick = weechat.info_get('irc_nick_from_host', op) comment = "Ban in %s by %s: %s" % (channel, op_nick, s) comment = weechat.string_remove_color(comment, '') # FIXME make expire time configurable warnDB.add(mask, comment=comment, expires=3600 * 24 * 7) return WEECHAT_RC_OK
def test_strings(): """Test string functions.""" check(weechat.charset_set('iso-8859-15') == 1) check(weechat.charset_set('') == 1) check(weechat.iconv_to_internal('iso-8859-15', 'abc') == 'abc') check(weechat.iconv_from_internal('iso-8859-15', 'abcd') == 'abcd') check(weechat.gettext('abcdef') == 'abcdef') check(weechat.ngettext('file', 'files', 1) == 'file') check(weechat.ngettext('file', 'files', 2) == 'files') check(weechat.strlen_screen('abcd') == 4) check(weechat.string_match('abcdef', 'abc*', 0) == 1) check(weechat.string_match('abcdef', 'abc*', 1) == 1) check(weechat.string_match('ABCDEF', 'abc*', 1) == 0) check(weechat.string_match_list('abcdef', '*,!abc*', 0) == 0) check(weechat.string_match_list('ABCDEF', '*,!abc*', 1) == 1) check(weechat.string_match_list('def', '*,!abc*', 0) == 1) check(weechat.string_eval_path_home('test ${abc}', {}, {'abc': '123'}, {}) == 'test 123') check(weechat.string_mask_to_regex('test*mask') == 'test.*mask') check(weechat.string_has_highlight('my test string', 'test,word2') == 1) check(weechat.string_has_highlight_regex('my test string', 'test|word2') == 1) check(weechat.string_format_size(0) == '0 bytes') check(weechat.string_format_size(1) == '1 byte') check(weechat.string_format_size(2097152) == '2.10 MB') check(weechat.string_format_size(420000000) == '420.00 MB') check(weechat.string_remove_color('test', '?') == 'test') check(weechat.string_is_command_char('/test') == 1) check(weechat.string_is_command_char('test') == 0) check(weechat.string_input_for_buffer('test') == 'test') check(weechat.string_input_for_buffer('/test') == '') check(weechat.string_input_for_buffer('//test') == '/test') check(weechat.string_eval_expression("100 > 50", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("-50 < 100", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("18.2 > 5", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("0xA3 > 2", {}, {}, {"type": "condition"}) == '1') check(weechat.string_eval_expression("${buffer.full_name}", {}, {}, {}) == 'core.weechat')
def parse_in(server, modifier, data, the_string): '''Parses incoming messages''' if data.startswith('0x'): # WeeChat >= 2.9 buffer, flags = data.split(';', 1) else: # WeeChat <= 2.8 plugin, buffer_name, flags = data.split(';', 2) buffer = weechat.buffer_search(plugin, buffer_name) channel = weechat.buffer_get_string(buffer, 'localvar_channel') flag = flags.split(',') if channel == weechat.config_get_plugin( 'channel') and 'irc_privmsg' in flag: the_string = weechat.string_remove_color(the_string, '') matcher = re.compile(weechat.config_get_plugin('re'), re.UNICODE) m = matcher.search(the_string) if not m \ or m.group('update') == weechat.config_get_plugin('username'): return colorize(the_string) dent = colorize(clean(m.group('dent'))) username = nick_color(m.group('username')) the_string = ''.join([username, m.group('separator'), dent]) return the_string
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 text = "\n".join(reversed(lines)) response = os.system("echo %s | urlview" % pipes.quote(text)) if response != 0: weechat.prnt(buf, "No URLs found") weechat.command(buf, "/window refresh") return weechat.WEECHAT_RC_OK
def input_modifier_cb(data, modifier, modifier_data, string): """Modifier that will add help on command line (for display only).""" global cmdhelp_settings line = weechat.string_remove_color(string, '') if line == '': return string command = '' arguments = '' if weechat.string_input_for_buffer(line) != '': return string items = line.split(' ', 1) if len(items) > 0: command = items[0] if len(command) < 2: return string if len(items) > 1: arguments = items[1] if command[1:].lower() in cmdhelp_settings['ignore_commands'].split(','): return string plugin = weechat.buffer_get_pointer(weechat.current_buffer(), 'plugin') msg_help = get_help_command(plugin, command[1:], arguments) or get_list_commands( plugin, command[1:], arguments) if not msg_help: if cmdhelp_settings['display_no_help'] != 'on': return string msg_help = weechat.color(cmdhelp_settings['color_no_help']) if command: msg_help += 'No help for command %s' % command else: msg_help += 'No help' color_delimiters = cmdhelp_settings['color_delimiters'] return '%s %s%s%s%s%s' % ( string, weechat.color(color_delimiters), cmdhelp_settings['prefix'], msg_help, weechat.color(color_delimiters), cmdhelp_settings['suffix'])
def my_modifier_cb(data, modifier, modifier_data, string): if w.buffer_get_string(w.buffer_search('irc',modifier_data.split(";")[1]),"localvar_noirccolors") == "true": try: nick, message = string.split("\t") except ValueError, e: return string return "%s\t%s" % (nick, w.string_remove_color(message,""))
def modifier_hook(data, modifier, modifier_data, string): buffer = wc.current_buffer() if buffer in BUFFERS: browser = BUFFERS.current().browser string = wc.string_remove_color(string, "") if string != browser.input: browser.input = string return browser.render() return string
def print_332(data, buffer, time, tags, displayed, highlight, prefix, message): """ Find the buffer when a new one is open """ if weechat.string_remove_color(message, "") == TOPIC: name = weechat.buffer_get_string(buffer, "name") set_options(name) request_completion() return weechat.WEECHAT_RC_OK
def print_332(data, buffer, time, tags, displayed, highlight, prefix, message): """ Find the buffer when a new one is open """ if weechat.string_remove_color(message, "") == TOPIC: name = weechat.buffer_get_string(buffer, "name") set_options(name) request_completion() return weechat.WEECHAT_RC_OK
def grep_buffer(buffer, head, tail, *args): """Return a list of lines that match 'regexp' in 'buffer', if no regexp returns all lines.""" lines = [] # Using /grep in grep's buffer can lead to some funny effects # We should take measures if that's the case grep_buffer = weechat.buffer_search('python', SCRIPT_NAME) grep_buffer = buffer == grep_buffer infolist = weechat.infolist_get('buffer_lines', buffer, '') if tail: # like with grep_file() if we need the last few matching lines, we move the cursor to # the end and search backwards infolist_next = weechat.infolist_prev else: infolist_next = weechat.infolist_next limit = head or tail append = lines.append check = check_string infolist_time = weechat.infolist_time while infolist_next(infolist): prefix = weechat.infolist_string(infolist, 'prefix') message = weechat.infolist_string(infolist, 'message') prefix = weechat.string_remove_color(prefix, '') message = weechat.string_remove_color(message, '') if grep_buffer: if script_nick == prefix: # ignore our lines continue date = prefix line = '%s\t%s' % (date, message.replace(' ', '\t', 1)) else: date = infolist_time(infolist, 'date') line = '%s\t%s\t%s' % (date, prefix, message) line = check(line, *args) if line: append(line) if limit and len(lines) >= limit: break weechat.infolist_free(infolist) if tail: lines.reverse() return lines
def grep_buffer(buffer, head, tail, *args): """Return a list of lines that match 'regexp' in 'buffer', if no regexp returns all lines.""" lines = [] # Using /grep in grep's buffer can lead to some funny effects # We should take measures if that's the case grep_buffer = weechat.buffer_search('python', SCRIPT_NAME) grep_buffer = buffer == grep_buffer infolist = weechat.infolist_get('buffer_lines', buffer, '') if tail: # like with grep_file() if we need the last few matching lines, we move the cursor to # the end and search backwards infolist_next = weechat.infolist_prev else: infolist_next = weechat.infolist_next limit = head or tail append = lines.append check = check_string infolist_time = weechat.infolist_time while infolist_next(infolist): prefix = weechat.infolist_string(infolist, 'prefix') message = weechat.infolist_string(infolist, 'message') prefix = weechat.string_remove_color(prefix, '') message = weechat.string_remove_color(message, '') if grep_buffer: if script_nick == prefix: # ignore our lines continue date = prefix line = '%s\t%s' %(date, message.replace(' ', '\t', 1)) else: date = infolist_time(infolist, 'date') line = '%s\t%s\t%s' %(date, prefix, message) line = check(line, *args) if line: append(line) if limit and len(lines) >= limit: break weechat.infolist_free(infolist) if tail: lines.reverse() return lines
def find_buffer(): """ Find the buffer when the plugin starts """ infolist = weechat.infolist_get("buffer", "", "") while weechat.infolist_next(infolist): topic = weechat.infolist_string(infolist, "title") if weechat.string_remove_color(topic, "") == TOPIC: name = weechat.infolist_string(infolist, "name") set_options(name) request_completion() break weechat.infolist_free(infolist)
def find_buffer(): """ Find the buffer when the plugin starts """ infolist = weechat.infolist_get("buffer", "", "") while weechat.infolist_next(infolist): topic = weechat.infolist_string(infolist, "title") if weechat.string_remove_color(topic, "") == TOPIC: name = weechat.infolist_string(infolist, "name") set_options(name) request_completion() break weechat.infolist_free(infolist)
def retrieve(data, buffer, args): index = -1 #We need to index the list back to front, so negative indices if len(args) > 0: index = -(int(args[0])+1) if not buffer in storage: w.prnt(buffer, "Error: No messages stored for this buffer") return w.WEECHAT_RC_OK if -index > len(storage[buffer]): w.prnt(buffer, "Error: I only have %d messages for this buffer" % len(storage[buffer])) return w.WEECHAT_RC_OK w.prnt(buffer, w.string_remove_color(storage[buffer][index], "")) return w.WEECHAT_RC_OK
def my_modifier_cb(data, modifier, modifier_data, string): if modifier_data.startswith('0x'): # WeeChat >= 2.9 buffer, tags = modifier_data.split(';', 1) else: # WeeChat <= 2.8 plugin, buffer_name, tags = modifier_data.split(';', 2) buffer = w.buffer_search(plugin, buffer_name) if w.buffer_get_string(buffer, "localvar_noirccolors") == "true": try: nick, message = string.split("\t") except ValueError as e: return string return "%s\t%s" % (nick, w.string_remove_color(message, "")) else: return string
def update_title(data, signal, signal_data): title = w.buffer_get_string(w.current_buffer(), 'name') num = w.buffer_get_integer(w.current_buffer(), 'number') title = w.string_remove_color(title, '') title = "[WeeChat] [" + str(num) + ":" + title + "]" hotlist = w.infolist_get('hotlist', '', '') while w.infolist_next(hotlist): number = w.infolist_integer(hotlist, 'buffer_number') thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer') name = w.buffer_get_string(thebuffer, 'short_name') if not number == num: title += ' (%s:%s)' % (number, name) w.infolist_free(hotlist) w.window_set_title(title) return w.WEECHAT_RC_OK
def parse(server, modifier, data, the_string): flags = data.split(';')[2].split(',') # This is the user we should be parsing messages from, with # nick_ prepended username = '******' + weechat.config_get_plugin('username') if username in flags: matcher = re.compile(weechat.config_get_plugin('re'), re.UNICODE) m = matcher.search(weechat.string_remove_color(the_string, "")) if m: dent = colorize(m.group('dent')) username = color(nick_color(m.group('username')), m.group('username')) the_string = ''.join([username, m.group('separator'), dent]) return the_string
def input_modifier(data, modifier, modifier_data, string): """ This modifier is called when input text item is built by WeeChat (commonly after changes in input or cursor move), it builds new input with prefix ("Commands:"), and suffix (list of commands found) """ global old_input, commands, commands_pos if modifier_data != w.current_buffer(): return "" input = w.string_remove_color(string, "") input = input.strip() if old_input == None or input != old_input: old_commands = commands commands = get_matching_commands(input) if commands != old_commands and len(input) > 0: commands_pos = 0 old_input = input commandstr = get_command_string(commands, commands_pos, input) return w.config_get_plugin("message") + string + commandstr
def input_modifier(data, modifier, modifier_data, string): """ This modifier is called when input text item is built by WeeChat (commonly after changes in input or cursor move), it builds new input with prefix ("Go to:"), and suffix (list of buffers found) """ global old_input, buffers, buffers_pos if modifier_data != weechat.current_buffer(): return "" names = "" input = weechat.string_remove_color(string, "") input = input.lstrip() if old_input == None or input != old_input: old_buffers = buffers buffers = get_matching_buffers(input) if buffers != old_buffers and len(input) > 0: buffers_pos = 0 old_input = input names = buffers_to_string(buffers, buffers_pos, input.strip()) return weechat.config_get_plugin("message") + string + names
def input_modifier(data, modifier, modifier_data, string): """ This modifier is called when input text item is built by WeeChat (commonly after changes in input or cursor move), it builds new input with prefix ("Go to:"), and suffix (list of buffers found) """ global old_input, buffers, buffers_pos if modifier_data != weechat.current_buffer(): return "" names = "" input = weechat.string_remove_color(string, "") input = input.lstrip() if old_input == None or input != old_input: old_buffers = buffers buffers = get_matching_buffers(input) if buffers != old_buffers and len(input) > 0: buffers_pos = 0 old_input = input names = buffers_to_string(buffers, buffers_pos, input.strip()) return weechat.config_get_plugin("message") + string + names
def _reconstruct_print(prefix, message, highlighted): # as printing without alignment also strips timestamp and delimiter, # they must be reconstructed timestamp = strftime(_s("weechat.look.buffer_time_format")) timestamp = _c("weechat.color.chat_time") + "".join([ l if l.isdigit() else _c("weechat.color.chat_time_delimiters")+l+_c("weechat.color.chat_time") for l in timestamp]) if highlighted: prefix = "".join((_c("weechat.color.chat_highlight", "weechat.color.chat_highlight_bg"), weechat.string_remove_color(prefix, ""))) prefix = "".join((_c("weechat.color.chat_nick_prefix"), _s("weechat.look.nick_prefix"), prefix, _c("weechat.color.chat_nick_suffix"), _s("weechat.look.nick_suffix"), weechat.color("reset"))) delimiter = "".join((" ", _c("weechat.color.chat_delimiters"), _s("weechat.look.prefix_suffix"), weechat.color("reset"), " ")) if _s("weechat.look.prefix_align") != "none" else " " return "{} {}{}{}".format(timestamp, prefix, delimiter, message)
def update_title(data, signal, signal_data): ''' The callback that adds title. ''' # prefix title = w.config_get_plugin('title_prefix') # current buffer title += w.config_get_plugin('current_buffer_prefix') if w.config_get_plugin('short_name') == 'on': title += w.buffer_get_string(w.current_buffer(), 'short_name') else: title += w.buffer_get_string(w.current_buffer(), 'name') title += w.config_get_plugin('current_buffer_suffix') if w.config_get_plugin('show_hotlist') == 'on': # hotlist buffers hotlist = w.infolist_get('hotlist', '', '') pnumber = w.config_get_plugin('hotlist_number_prefix') snumber = w.config_get_plugin('hotlist_number_suffix') pname = w.config_get_plugin('hotlist_buffer_prefix') sname = w.config_get_plugin('hotlist_buffer_suffix') separator = w.config_get_plugin('hotlist_separator') while w.infolist_next(hotlist): priority = w.infolist_integer(hotlist, 'priority') if priority >= int(w.config_get_plugin('title_priority')): number = w.infolist_integer(hotlist, 'buffer_number') thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer') name = w.buffer_get_string(thebuffer, 'short_name') title += ' {0}{1}{2}{3}{4}{5}{6}'.format(pnumber, \ number, snumber, separator, pname, name, sname) w.infolist_free(hotlist) # suffix title += w.config_get_plugin('title_suffix') title = w.string_remove_color(title, '') w.window_set_title(title) return w.WEECHAT_RC_OK
def go_input_modifier(data, modifier, modifier_data, string): """This modifier is called when input text item is built by WeeChat. This is commonly called after changes in input or cursor move: it builds a new input with prefix ("Go to:"), and suffix (list of buffers found). """ global old_input, buffers, buffers_pos if modifier_data != weechat.current_buffer(): return '' names = '' new_input = weechat.string_remove_color(string, '') new_input = new_input.lstrip() if old_input is None or new_input != old_input: old_buffers = buffers buffers = go_matching_buffers(new_input) if buffers != old_buffers and len(new_input) > 0: if len(buffers) == 1 and go_option_enabled('auto_jump'): weechat.command(modifier_data, '/wait 1ms /input return') buffers_pos = 0 old_input = new_input names = go_buffers_to_string(buffers, buffers_pos, new_input.strip()) return weechat.config_get_plugin('message') + string + names
def go_input_modifier(data, modifier, modifier_data, string): """This modifier is called when input text item is built by WeeChat. This is commonly called after changes in input or cursor move: it builds a new input with prefix ("Go to:"), and suffix (list of buffers found). """ global old_input, buffers, buffers_pos if modifier_data != weechat.current_buffer(): return '' names = '' new_input = weechat.string_remove_color(string, '') new_input = new_input.lstrip() if old_input is None or new_input != old_input: old_buffers = buffers buffers = go_matching_buffers(new_input) if buffers != old_buffers and len(new_input) > 0: if len(buffers) == 1 and go_option_enabled('auto_jump'): weechat.command(modifier_data, '/wait 1ms /input return') buffers_pos = 0 old_input = new_input names = go_buffers_to_string(buffers, buffers_pos, new_input.strip()) return weechat.config_get_plugin('message') + string + names
def update_title(data, signal, signal_data): ''' The callback that adds title. ''' # prefix title = w.config_get_plugin('title_prefix') # current buffer title += w.config_get_plugin('current_buffer_prefix') if w.config_get_plugin('short_name') == 'on': title += w.buffer_get_string(w.current_buffer(), 'short_name') else: title += w.buffer_get_string(w.current_buffer(), 'name') title += w.config_get_plugin('current_buffer_suffix') if w.config_get_plugin('show_hotlist') == 'on': # hotlist buffers hotlist = w.infolist_get('hotlist', '', '') pnumber = w.config_get_plugin('hotlist_number_prefix') snumber = w.config_get_plugin('hotlist_number_suffix') pname = w.config_get_plugin('hotlist_buffer_prefix') sname = w.config_get_plugin('hotlist_buffer_suffix') separator = w.config_get_plugin('hotlist_separator') while w.infolist_next(hotlist): priority = w.infolist_integer(hotlist, 'priority') if priority >= int(w.config_get_plugin('title_priority')): number = w.infolist_integer(hotlist, 'buffer_number') thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer') name = w.buffer_get_string(thebuffer, 'short_name') title += ' {0}{1}{2}{3}{4}{5}{6}'.format(pnumber, \ number, snumber, separator, pname, name, sname) w.infolist_free(hotlist) # suffix title += w.config_get_plugin('title_suffix') title = w.string_remove_color(title, '') w.window_set_title(title) return w.WEECHAT_RC_OK
def parse (server, modifier, data, the_string): """Parses weechat_print modifier on [email protected] pv""" #weechat.prnt("", the_string) #weechat.prnt("", data) plugin, channel, flags = data.split(';') flag = flags.split(',') if channel == weechat.config_get_plugin('channel') and 'irc_privmsg' in flag: the_string = weechat.string_remove_color(the_string, "") matcher = re.compile(weechat.config_get_plugin('re'), re.UNICODE) m = matcher.search(the_string) if not m: return colorize(the_string) dent = colorize(clean(m.group('dent'))) username = nick_color(m.group('username')) the_string = ''.join([ username, m.group('separator'), dent ]) return the_string
def parse_in (server, modifier, data, the_string): '''Parses incoming messages''' plugin, channel, flags = data.split(';') flag = flags.split(',') if channel == weechat.config_get_plugin('channel') and 'irc_privmsg' in flag: the_string = weechat.string_remove_color(the_string, '') matcher = re.compile(weechat.config_get_plugin('re'), re.UNICODE) m = matcher.search(the_string) if not m \ or m.group('update') == weechat.config_get_plugin('username'): return colorize(re.sub("^x_twitter", "[^^^]", the_string)) dent = colorize(clean(m.group('dent'))) username = nick_color(m.group('username')) the_string = ''.join([ username, m.group('separator'), dent ]) return the_string
def update_title(data, signal, signal_data): ''' The callback that adds title. ''' if w.config_get_plugin('short_name') == 'on': title = w.buffer_get_string(w.current_buffer(), 'short_name') else: title = w.buffer_get_string(w.current_buffer(), 'name') title = w.string_remove_color(title, '') hotlist = w.infolist_get('hotlist', '', '') while w.infolist_next(hotlist): priority = w.infolist_integer(hotlist, 'priority') if priority >= int(w.config_get_plugin('title_priority')): number = w.infolist_integer(hotlist, 'buffer_number') thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer') name = w.buffer_get_string(thebuffer, 'short_name') title += ' %s:%s' % (number, name) w.infolist_free(hotlist) w.window_set_title(title) return w.WEECHAT_RC_OK
def parse_in(server, modifier, data, the_string): '''Parses incoming messages''' plugin, channel, flags = data.split(';') flag = flags.split(',') if channel == weechat.config_get_plugin( 'channel') and 'irc_privmsg' in flag: the_string = weechat.string_remove_color(the_string, '') matcher = re.compile(weechat.config_get_plugin('re'), re.UNICODE) m = matcher.search(the_string) if not m \ or m.group('update') == weechat.config_get_plugin('username'): return colorize(the_string) dent = colorize(clean(m.group('dent'))) username = nick_color(m.group('username')) the_string = ''.join([username, m.group('separator'), dent]) return the_string
def update_title(data, signal, signal_data): ''' The callback that adds title. ''' if w.config_get_plugin('short_name') == 'on': title = w.buffer_get_string(w.current_buffer(), 'short_name') else: title = w.buffer_get_string(w.current_buffer(), 'name') title = w.string_remove_color(title, '') hotlist = w.infolist_get('hotlist', '', '') while w.infolist_next(hotlist): priority = w.infolist_integer(hotlist, 'priority') if priority >= int(w.config_get_plugin('title_priority')): number = w.infolist_integer(hotlist, 'buffer_number') thebuffer = w.infolist_pointer(hotlist, 'buffer_pointer') name = w.buffer_get_string(thebuffer, 'short_name') title += ' %s:%s' % (number, name) w.infolist_free(hotlist) w.window_set_title(title) return w.WEECHAT_RC_OK
def parse(server, modifier, data, the_string): """Parses weechat_print modifier on [email protected] pv""" #weechat.prnt("", the_string) #weechat.prnt("", data) plugin, channel, flags = data.split(';') flag = flags.split(',') if channel == weechat.config_get_plugin( 'channel') and 'irc_privmsg' in flag: the_string = weechat.string_remove_color(the_string, "") matcher = re.compile(weechat.config_get_plugin('re'), re.UNICODE) m = matcher.search(the_string) if not m: return colorize(the_string) dent = colorize(clean(m.group('dent'))) username = nick_color(m.group('username')) the_string = ''.join([username, m.group('separator'), dent]) return the_string
def input_modifier_cb(data, modifier, modifier_data, string): """Modifier that will add help on command line (for display only).""" global cmdhelp_settings line = weechat.string_remove_color(string, '') if line == '': return string command = '' arguments = '' if weechat.string_input_for_buffer(line) != '': return string items = line.split(' ', 1) if len(items) > 0: command = items[0] if len(command) < 2: return string if len(items) > 1: arguments = items[1] if command[1:].lower() in cmdhelp_settings['ignore_commands'].split(','): return string plugin = weechat.buffer_get_pointer(weechat.current_buffer(), 'plugin') msg_help = get_help_command(plugin, command[1:], arguments) or get_list_commands(plugin, command[1:], arguments) if not msg_help: if cmdhelp_settings['display_no_help'] != 'on': return string msg_help = weechat.color(cmdhelp_settings['color_no_help']) if command: msg_help += 'No help for command %s' % command else: msg_help += 'No help' color_delimiters = cmdhelp_settings['color_delimiters'] return '%s %s%s%s%s%s' % (string, weechat.color(color_delimiters), cmdhelp_settings['prefix'], msg_help, weechat.color(color_delimiters), cmdhelp_settings['suffix'])
def stripcolor(string): return w.string_remove_color(string, '')
def search_trig_cb(data, buf, date, tags, displayed, highlight, prefix, message): """ function for parsing sent messages """ global pcooldown """ Prevent infinite loop/flood, no more messages than n (approx 3) in 300 secs """ if (pcooldown > 300): return weechat.WEECHAT_RC_OK """ Save some CPU cycles """ if (prefix == '-->' or prefix == '<--' or prefix == '--' or prefix == ' *' or prefix == ""): return weechat.WEECHAT_RC_OK bufname = weechat.buffer_get_string(buf, "name") if bufname == 'weechat': return weechat.WEECHAT_RC_OK """ Ignore myself """ mynick = weechat.buffer_get_string(buf, "localvar_nick") if re.search('[@+~]?' + mynick, prefix): """ weechat.prnt("", "Ignored myself.") """ return weechat.WEECHAT_RC_OK database = sqlite3.connect(db_file) cursor = database.cursor() pure = weechat.string_remove_color(message, "") debug( 1, "Nick in question:'%s" % bufname + '.' + prefix.translate(None, '@+~') + "'") for row in cursor.execute("SELECT ignored from ignorenicks;"): if re.search(row[0], bufname + '.' + prefix.translate(None, '@+~')): """ weechat.prnt("", "Nick ignored: %s" % row[0]) """ return weechat.WEECHAT_RC_OK for row in cursor.execute("SELECT ignored from banchans;"): if bufname == row[0]: return weechat.WEECHAT_RC_OK for row in cursor.execute("SELECT * FROM triggers"): delay = random.randint(4, 9) pattern = row[1].encode('utf8') pattern = pattern.replace("%N", mynick) replydata = row[2].encode('utf8') prob = int(row[3]) for ccode, chex in colorcodes.items(): replydata = replydata.replace(ccode, chex) try: nick = re.sub('^[+%@]', '', prefix) debug( 2, "prefix: %s, mynick: %s, nick: %s, pattern: %s, prob: %s, pure: %s" % (prefix, mynick, nick, pattern, str(prob), pure)) r = re.compile(pattern, re.I | re.U) if r.search(pure) is not None: weechat.prnt("", "Matched") """ Meh, not really sure how random it is, but probably good enough """ if (prob > 1 and random.randint(1, prob) == 1): debug(1, "Randomly ignored.") return weechat.WEECHAT_RC_OK weechat.prnt("", "Match: %s" % r.search(pure).group(0)) myreply = "n/a" if prob < 0: """ -1 means this is action, not saying """ delay = 0 debug(1, "Command mode triggered.") infolist = weechat.infolist_get("irc_nick", "", bufname.replace(".", ",")) while weechat.infolist_next(infolist): _nick = weechat.infolist_string(infolist, 'name') if _nick == nick: hostinfo = weechat.infolist_string( infolist, 'host') break mask = hostinfo.split('@')[1] weechat.prnt("", "mask: %s" % mask) weechat.infolist_free(infolist) for myreply in replydata.split('|'): myreply = myreply.replace("%n", nick) myreply = myreply.replace("%N", mynick) myreply = myreply.replace("%m", mask) myreply = myreply.replace("%c", bufname.split(".")[1]) weechat.prnt("", "Command: %s" % myreply) if delay > 0: weechat.command(buf, "/wait %s %s" % (delay, myreply)) else: weechat.command(buf, "%s" % myreply) delay + +2 return weechat.WEECHAT_RC_OK myreply = random.choice(replydata.split('|')) myreply = myreply.replace("%n", nick) weechat.prnt("", "reply: %s" % myreply) weechat.prnt("", "%s triggered." % pattern) weechat.command(buf, "/wait %s /say %s" % (delay, myreply)) pcooldown += 100 except: weechat.prnt("", "NOMatch") if pattern == pure: weechat.command(buf, "/wait %s /say %s" % (delay, myreply)) pcooldown += 120 return weechat.WEECHAT_RC_OK
def strip_symbols(string): return re_remove_chars.sub('', w.string_remove_color(string, ''))
def cstrip(text): ''' Use weechat color strip on text''' return w.string_remove_color(text, '')
def cstrip(text): """strip color codes""" return w.string_remove_color(text, '')
def cstrip(text): ''' Use weechat color strip on text''' return w.string_remove_color(text, '')
def playback_cb(data, modifier, modifier_data, string): 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 if modifier_data.startswith('0x'): buffer, tags = modifier_data.split(';', 1) plugin = weechat.buffer_get_string(buffer, 'plugin') buffer_name = weechat.buffer_get_string(buffer, 'name') else: plugin, buffer_name, tags = modifier_data.split(';', 2) buffer = weechat.buffer_search(plugin, buffer_name) if plugin != 'irc' or buffer_name == 'irc_raw': return string if tags: tags = set(tags.split(',')) else: tags = set() global buffer_playback if 'nick_***' in tags: line = string.partition('\t')[2] if line in ['Buffer Playback...', 'Backlog playback...']: weechat.hook_signal_send("znc-playback-start", WEECHAT_HOOK_SIGNAL_STRING, buffer_name) debug("* buffer playback for %s", buffer_name) get_config_options() nick_talked.clear() buffer_playback.add(buffer) elif line == 'Playback Complete.': buffer_playback.remove(buffer) debug("* end of playback for %s", buffer_name) weechat.hook_signal_send("znc-playback-stop", WEECHAT_HOOK_SIGNAL_STRING, buffer_name) tags.discard('notify_message') tags.discard('irc_privmsg') prnt_date_tags(buffer, 0, ','.join(tags), string) return '' elif buffer not in buffer_playback: return string #debug(string) def strip_timestamp(s): words = znc_timestamp.count(' ') + 1 p = 0 for i in range(words): p = s[p:].find(' ') + p + 1 return s[:p - 1], s[p:] prefix, s, line = string.partition('\t') if 'irc_action' in tags or 'irc_notice' in tags: _prefix, _, line = line.partition(' ') timestamp, line = strip_timestamp(line) line = '%s %s' % (_prefix, line) else: timestamp, line = strip_timestamp(line) try: t = time.strptime(timestamp, znc_timestamp) except ValueError as e: # bad time format. error(e) debug("Timestamp error: %s\n%s" % (modifier_data, string)) return string else: if t[0] == 1900: # only hour information, complete year, month and day with today's date # might be incorrect though if day changed during playback. t = datetime.time(*t[3:6]) d = datetime.datetime.combine(datetime.date.today(), t) else: d = datetime.datetime(*t[:6]) time_epoch = int(time.mktime(d.timetuple())) if 'nick_*buffextras' not in tags: # not a line coming from ZNC buffextras module. nick_talked.add((buffer, weechat.string_remove_color(prefix, ''))) prnt_date_tags(buffer, time_epoch, ','.join(tags), "%s\t%s" % (prefix, line)) return '' tags.discard('notify_message') tags.discard('irc_privmsg') tags.discard('nick_*buffextras') hostmask, s, line = line.partition(' ') nick = hostmask[:hostmask.find('!')] host = hostmask[len(nick) + 1:] server = weechat.buffer_get_string(buffer, 'localvar_server') channel = weechat.buffer_get_string(buffer, 'localvar_channel') s = None if line == 'joined': tags.add('irc_join') s = weechat.gettext("%s%s%s%s%s%s%s%s%s%s has joined %s%s%s") s = s % ( weechat.prefix('join'), COLOR_CHAT_NICK, # TODO there's a function for use nick's color nick, COLOR_CHAT_DELIMITERS, ' (', COLOR_CHAT_HOST, # TODO host can be hidden in config host, COLOR_CHAT_DELIMITERS, ')', COLOR_MESSAGE_JOIN, COLOR_CHAT_CHANNEL, channel, COLOR_MESSAGE_JOIN) if send_signals: weechat.hook_signal_send(server + ",irc_in_JOIN", WEECHAT_HOOK_SIGNAL_STRING, ":%s JOIN :%s" % (hostmask, channel)) elif line.startswith('parted with message:'): tags.add('irc_part') reason = line[line.find('[') + 1:-1] if reason: s = weechat.gettext( "%s%s%s%s%s%s%s%s%s%s has left %s%s%s %s(%s%s%s)") s = s % (weechat.prefix('quit'), COLOR_CHAT_NICK, nick, COLOR_CHAT_DELIMITERS, ' (', COLOR_CHAT_HOST, host, COLOR_CHAT_DELIMITERS, ')', COLOR_MESSAGE_QUIT, COLOR_CHAT_CHANNEL, channel, COLOR_MESSAGE_QUIT, COLOR_CHAT_DELIMITERS, COLOR_REASON_QUIT, reason, COLOR_CHAT_DELIMITERS) if send_signals: weechat.hook_signal_send( server + ",irc_in_PART", WEECHAT_HOOK_SIGNAL_STRING, ":%s PART %s :%s" % (hostmask, channel, reason)) else: s = weechat.gettext("%s%s%s%s%s%s%s%s%s%s has left %s%s%s") s = s % (weechat.prefix('quit'), COLOR_CHAT_NICK, nick, COLOR_CHAT_DELIMITERS, ' (', COLOR_CHAT_HOST, host, COLOR_CHAT_DELIMITERS, ')', COLOR_MESSAGE_QUIT, COLOR_CHAT_CHANNEL, channel, COLOR_MESSAGE_QUIT) if send_signals: weechat.hook_signal_send(server + ",irc_in_PART", WEECHAT_HOOK_SIGNAL_STRING, ":%s PART %s" % (hostmask, channel)) elif line.startswith('quit with message:'): tags.add('irc_quit') reason = line[line.find('[') + 1:-1] s = weechat.gettext("%s%s%s%s%s%s%s%s%s%s has quit %s(%s%s%s)") s = s % (weechat.prefix('quit'), COLOR_CHAT_NICK, nick, COLOR_CHAT_DELIMITERS, ' (', COLOR_CHAT_HOST, host, COLOR_CHAT_DELIMITERS, ')', COLOR_MESSAGE_QUIT, COLOR_CHAT_DELIMITERS, COLOR_REASON_QUIT, reason, COLOR_CHAT_DELIMITERS) # QUIT messages should be sent only once, but since there's # one quit per channel, use PART instead. if send_signals: if not reason: weechat.hook_signal_send(server + ",irc_in_PART", WEECHAT_HOOK_SIGNAL_STRING, ":%s PART %s" % (hostmask, channel)) else: weechat.hook_signal_send( server + ",irc_in_PART", WEECHAT_HOOK_SIGNAL_STRING, ":%s PART %s :%s" % (hostmask, channel, reason)) elif line.startswith('is now known as '): tags.add('irc_nick') new_nick = line.rpartition(' ')[-1] s = weechat.gettext("%s%s%s%s is now known as %s%s%s") s = s % (weechat.prefix('network'), COLOR_CHAT_NICK, nick, COLOR_CHAT, COLOR_CHAT_NICK, new_nick, COLOR_CHAT) # NICK messages should be sent only once, but since there's one # per every channel, we fake it with a PART/JOIN if send_signals: new_hostmask = new_nick + hostmask[hostmask.find('!'):] weechat.hook_signal_send(server + ",irc_in_PART", WEECHAT_HOOK_SIGNAL_STRING, ":%s PART %s" % (hostmask, channel)) weechat.hook_signal_send(server + ",irc_in_JOIN", WEECHAT_HOOK_SIGNAL_STRING, ":%s JOIN :%s" % (new_hostmask, channel)) elif line.startswith('set mode: '): tags.add('irc_mode') modes = line[line.find(':') + 2:] s = weechat.gettext("%sMode %s%s %s[%s%s%s]%s by %s%s") s = s % (weechat.prefix('network'), COLOR_CHAT_CHANNEL, channel, COLOR_CHAT_DELIMITERS, COLOR_CHAT, modes, COLOR_CHAT_DELIMITERS, COLOR_CHAT, COLOR_CHAT_NICK, nick) if send_signals: # buffextras can send an invalid hostmask "nick!@" sometimes # fix it so at least is valid. if not is_hostmask(hostmask): nick = hostmask[:hostmask.find('!')] hostmask = nick + '!unknow@unknow' weechat.hook_signal_send( server + ",irc_in_MODE", WEECHAT_HOOK_SIGNAL_STRING, ":%s MODE %s %s" % (hostmask, channel, modes)) elif line.startswith('kicked'): tags.add('irc_kick') _, nick_kicked, reason = line.split(None, 2) reason = reason[reason.find('[') + 1:-1] s = weechat.gettext("%s%s%s%s has kicked %s%s%s %s(%s%s%s)") s = s % (weechat.prefix('quit'), COLOR_CHAT_NICK, nick, COLOR_MESSAGE_QUIT, COLOR_CHAT_NICK, nick_kicked, COLOR_MESSAGE_QUIT, COLOR_CHAT_DELIMITERS, COLOR_CHAT, reason, COLOR_CHAT_DELIMITERS) if send_signals: weechat.hook_signal_send( server + ",irc_in_KICK", WEECHAT_HOOK_SIGNAL_STRING, ":%s KICK %s %s :%s" % (hostmask, channel, nick_kicked, reason)) elif line.startswith('changed the topic to: '): tags.add('irc_topic') topic = line[line.find(':') + 2:] s = weechat.gettext( "%s%s%s%s has changed topic for %s%s%s to \"%s%s\"") s = s % (weechat.prefix('network'), COLOR_CHAT_NICK, nick, COLOR_CHAT, COLOR_CHAT_CHANNEL, channel, COLOR_CHAT, topic, COLOR_CHAT) # crude smart filter if SMART_FILTER and (buffer, nick) not in nick_talked \ and ('irc_join' in tags \ or 'irc_part' in tags \ or 'irc_quit' in tags \ or 'irc_nick' in tags): tags.add('irc_smart_filter') if s is None: error('Unknown message from ZNC: %r' % string) return string else: prnt_date_tags(buffer, time_epoch, ','.join(tags), s) return ''
error(e) #debug("%s\n%s" % (modifier_data, string)) return string else: if t[0] == 1900: # only hour information, complete year, month and day with today's date # might be incorrect though if day changed during playback. t = datetime.time(*t[3:6]) d = datetime.datetime.combine(datetime.date.today(), t) else: d = datetime.datetime(*t[:6]) time_epoch = int(time.mktime(d.timetuple())) if 'nick_*buffextras' not in tags: # not a line coming from ZNC buffextras module. nick_talked.add((buffer, weechat.string_remove_color(prefix, ''))) prnt_date_tags(buffer, time_epoch, ','.join(tags), "%s\t%s" % (prefix, line)) return '' tags.discard('notify_message') tags.discard('irc_privmsg') tags.discard('nick_*buffextras') hostmask, s, line = line.partition(' ') nick = hostmask[:hostmask.find('!')] host = hostmask[len(nick) + 1:] server, channel = buffer_name.split('.', 1) s = None if line == 'joined':
def input_append_value(buffer, value): old = wc.string_remove_color(wc.buffer_get_string(buffer, "input"), "") space = " " if old and old[-1] != " " else "" new = old + space + value wc.buffer_set(buffer, "input", new) wc.buffer_set(buffer, "input_pos", str(len(new) - 1))
error(e) #debug("%s\n%s" % (modifier_data, string)) return string else: if t[0] == 1900: # only hour information, complete year, month and day with today's date # might be incorrect though if day changed during playback. t = datetime.time(*t[3:6]) d = datetime.datetime.combine(datetime.date.today(), t) else: d = datetime.datetime(*t[:6]) time_epoch = int(time.mktime(d.timetuple())) if 'nick_*buffextras' not in tags: # not a line coming from ZNC buffextras module. nick_talked.add((buffer, weechat.string_remove_color(prefix, ''))) prnt_date_tags(buffer, time_epoch, ','.join(tags), "%s\t%s" % (prefix, line)) return '' tags.discard('notify_message') tags.discard('irc_privmsg') tags.discard('nick_*buffextras') hostmask, s, line = line.partition(' ') nick = hostmask[:hostmask.find('!')] host = hostmask[len(nick) + 1:] server, channel = buffer_name.split('.', 1) s = None if line == 'joined': tags.add('irc_join')
def strip_symbols(string): return re_remove_chars.sub('', w.string_remove_color(string, ''))
def cstrip(text): return weechat.string_remove_color(text, '')