File: noirccolors.py

package info (click to toggle)
weechat-scripts 20221022-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,688 kB
  • sloc: python: 42,639; perl: 24,814; ruby: 2,261; lisp: 338; tcl: 244; javascript: 138; makefile: 14; sh: 9
file content (29 lines) | stat: -rw-r--r-- 1,183 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import weechat as w

SCRIPT_NAME    = "noirccolors"
SCRIPT_AUTHOR  = "Fredrick Brennan <fredrick.brennan1@gmail.com>"
SCRIPT_VERSION = "0.4"
SCRIPT_LICENSE = "Public domain"
SCRIPT_DESC    = "Remove IRC colors from buffers with the localvar 'noirccolors' set. To disable IRC colors in the current buffer, type /buffer set localvar_set_noirccolors true. You can also set this with script buffer_autoset.py. :)"

w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', '')


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

hook = w.hook_modifier("weechat_print", "my_modifier_cb", "")