update and rename embellish to colo
This commit is contained in:
parent
d4e8cc830c
commit
0b2d8156f6
@ -2,8 +2,11 @@
|
|||||||
#
|
#
|
||||||
# Released into the Public Domain
|
# Released into the Public Domain
|
||||||
|
|
||||||
"""embellish: make your chats noticable"""
|
"""colo: make your chats noticable"""
|
||||||
|
|
||||||
|
# v2.0 - wowaname
|
||||||
|
# format strings instead of pre/suf
|
||||||
|
# rename
|
||||||
# v1.3 - wowaname
|
# v1.3 - wowaname
|
||||||
# changed hook so script doesn't modify the input buffer
|
# changed hook so script doesn't modify the input buffer
|
||||||
# v1.2 - wowaname
|
# v1.2 - wowaname
|
||||||
@ -21,21 +24,19 @@ import random
|
|||||||
import re
|
import re
|
||||||
import weechat
|
import weechat
|
||||||
|
|
||||||
SCRIPT_NAME = "embellish"
|
SCRIPT_NAME = "colo"
|
||||||
SCRIPT_AUTHOR = "The Krusty Krab <wowaname@volatile.ch>"
|
SCRIPT_AUTHOR = "The Krusty Krab <wowaname@volatile.ch>"
|
||||||
SCRIPT_VERSION = "1.3"
|
SCRIPT_VERSION = "2.0"
|
||||||
SCRIPT_LICENSE = "Public domain"
|
SCRIPT_LICENSE = "Public domain"
|
||||||
SCRIPT_DESC = "Makes your chats noticable"
|
SCRIPT_DESC = "Makes your chats noticable"
|
||||||
|
|
||||||
# script options
|
# script options
|
||||||
settings = {
|
settings = {
|
||||||
"pre": (
|
"fmt": (
|
||||||
"\x0313♥",
|
"%c13♥ %0%s%o %c13♥",
|
||||||
"Text to add to the beginning of messages.",
|
"Format string for text. %0 - %9 are different colours, %s is text, "
|
||||||
),
|
"%c %b %u %r %o are ^C ^B ^U ^R ^O respectively, and %% is a literal "
|
||||||
"suf": (
|
"percent sign.",
|
||||||
"\x0313♥",
|
|
||||||
"Text to add to the end of messages.",
|
|
||||||
),
|
),
|
||||||
"fgs": (
|
"fgs": (
|
||||||
"04,05,06,13",
|
"04,05,06,13",
|
||||||
@ -60,7 +61,7 @@ settings = {
|
|||||||
),
|
),
|
||||||
"whitelist_cmds": (
|
"whitelist_cmds": (
|
||||||
"me,amsg,say",
|
"me,amsg,say",
|
||||||
"Commands to embellish.",
|
"Commands to colour.",
|
||||||
),
|
),
|
||||||
"profiles": (
|
"profiles": (
|
||||||
"> greentext,! alert",
|
"> greentext,! alert",
|
||||||
@ -69,10 +70,8 @@ settings = {
|
|||||||
"the options will switch to (profile)_pre, "
|
"the options will switch to (profile)_pre, "
|
||||||
"(profile)_suf, (profile)_fgs, and (profile)_bgs. ",
|
"(profile)_suf, (profile)_fgs, and (profile)_bgs. ",
|
||||||
),
|
),
|
||||||
"greentext_pre": ">",
|
"greentext_fmt": "%c3> %s",
|
||||||
"greentext_suf": "",
|
"alert_fmt": "%c1,8/!\\ %c8,1%s%o %c1,8/!\\"
|
||||||
"greentext_fgs": "03",
|
|
||||||
"greentext_bgs": "",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -85,14 +84,14 @@ if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
|
|||||||
if weechat.config_is_set_plugin(opt): continue
|
if weechat.config_is_set_plugin(opt): continue
|
||||||
weechat.config_set_plugin(opt, setting)
|
weechat.config_set_plugin(opt, setting)
|
||||||
|
|
||||||
weechat.hook_modifier("input_text_for_buffer", "cb_embellish", "")
|
weechat.hook_modifier("input_text_for_buffer", "cb_colo", "")
|
||||||
|
|
||||||
def glob_match (haystack, needle):
|
def glob_match (haystack, needle):
|
||||||
return re.search("^%s$" %
|
return re.search("^%s$" %
|
||||||
re.escape(haystack).replace(r"\?", ".").replace(r"\*", ".*?"),
|
re.escape(haystack).replace(r"\?", ".").replace(r"\*", ".*?"),
|
||||||
needle)
|
needle)
|
||||||
|
|
||||||
def cb_embellish(data, mod, buf, input):
|
def cb_colo (data, mod, buf, input):
|
||||||
buffer_name = weechat.buffer_get_string(buf, "name").lower()
|
buffer_name = weechat.buffer_get_string(buf, "name").lower()
|
||||||
output = ""
|
output = ""
|
||||||
profile = ""
|
profile = ""
|
||||||
@ -127,37 +126,42 @@ def cb_embellish(data, mod, buf, input):
|
|||||||
if not input.startswith("%s " % prefix): continue
|
if not input.startswith("%s " % prefix): continue
|
||||||
profile = "%s_" % name
|
profile = "%s_" % name
|
||||||
input = input.split(" ",1)[1] if " " in input else ""
|
input = input.split(" ",1)[1] if " " in input else ""
|
||||||
for opt in ("pre", "suf", "fgs", "bgs"):
|
for opt in ("fmt", "fgs", "bgs"):
|
||||||
if weechat.config_is_set_plugin(profile + opt): continue
|
if weechat.config_is_set_plugin(profile + opt): continue
|
||||||
weechat.config_set_plugin(profile + opt, "")
|
weechat.config_set_plugin(profile + opt, "")
|
||||||
break
|
break
|
||||||
|
|
||||||
fgs = weechat.config_get_plugin("%sfgs" % profile).split(",")
|
fgs = weechat.config_get_plugin("%sfgs" % profile).split(",")
|
||||||
bgs = weechat.config_get_plugin("%sbgs" % profile).split(",")
|
bgs = weechat.config_get_plugin("%sbgs" % profile).split(",")
|
||||||
base = "\x0f\x03%s%s%s" % (
|
fmt = weechat.config_get_plugin("%sfmt" % profile).split("%%")
|
||||||
random.choice(fgs),
|
|
||||||
"," if bgs != [""] else "",
|
|
||||||
random.choice(bgs),
|
|
||||||
) if fgs != [""] or bgs != [""] else ""
|
|
||||||
if base:
|
|
||||||
input = re.sub(
|
|
||||||
"\x03([^0-9])",
|
|
||||||
"\x03%s\\1" % base,
|
|
||||||
input.replace("\x0f","\x0f%s" % base))
|
|
||||||
|
|
||||||
#l = (409 - len(base) * 3 -
|
for i in xrange(len(fmt)):
|
||||||
# weechat.info_get("irc_server_isupport_value", "*,NICKLEN")
|
fmt[i] = fmt[i].replace("%c", "\x03").replace("%b",
|
||||||
l = 400 - len(base) * 3
|
"\x02").replace("%u", "\x1f").replace("%r",
|
||||||
|
"\x16").replace("%o", "\x0f")
|
||||||
|
if fgs == [""] and bgs == [""]: continue
|
||||||
|
for j in xrange(10):
|
||||||
|
base = "\x0f\x03%s%s%s" % (
|
||||||
|
random.choice(fgs),
|
||||||
|
"," if bgs != [""] else "",
|
||||||
|
random.choice(bgs),
|
||||||
|
)
|
||||||
|
fmt[i] = fmt[i].replace("%%%d" % j, base)
|
||||||
|
if j: continue
|
||||||
|
input = re.sub(
|
||||||
|
"\x03([^0-9])",
|
||||||
|
"\x03%s\\1" % base,
|
||||||
|
input.replace("\x0f","\x0f%s" % base))
|
||||||
|
|
||||||
|
fmt = "%".join(fmt)
|
||||||
|
|
||||||
|
l = (409 - len(fmt) -
|
||||||
|
int( weechat.info_get("irc_server_isupport_value", "%s,NICKLEN" %
|
||||||
|
weechat.buffer_get_string(buf, "localvar_server")) )
|
||||||
|
)
|
||||||
o = []
|
o = []
|
||||||
for line in input.replace("\r", "").split("\n"):
|
for line in input.replace("\r", "").split("\n"):
|
||||||
for i in xrange(0, len(line), l):
|
for i in xrange(0, len(line), l):
|
||||||
o.append("%s%s%s %s%s %s" % (
|
o.append(fmt.replace("%s", line[i:i+l].rstrip()))
|
||||||
base,
|
|
||||||
weechat.config_get_plugin("%spre" % profile),
|
|
||||||
base,
|
|
||||||
line[i:i+l].rstrip(),
|
|
||||||
base,
|
|
||||||
weechat.config_get_plugin("%ssuf" % profile),
|
|
||||||
))
|
|
||||||
|
|
||||||
return output + "\n".join(o)
|
return output + "\n".join(o)
|
41
scripts/coloconv.pl
Executable file
41
scripts/coloconv.pl
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
=pod
|
||||||
|
|
||||||
|
Reads plugins.conf from stdin, writes new plugins.conf to stdout, and
|
||||||
|
writes commands to restore the rest of the config options to stderr
|
||||||
|
|
||||||
|
Suggested operation:
|
||||||
|
cd .weechat
|
||||||
|
./coloconv.pl < plugins.conf > plugins.conf.new 2> commands
|
||||||
|
diff plugins.conf plugins.conf.new # to make sure nothing got clobbered
|
||||||
|
|
||||||
|
Then in WeeChat:
|
||||||
|
/exec -o .weechat/commands
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
my %profs;
|
||||||
|
|
||||||
|
while (<>) {
|
||||||
|
$_ !~ /^python\.embellish\./ and print, next;
|
||||||
|
s/^python\.embellish/python.colo/;
|
||||||
|
$_ !~ /^python\.colo\..*(?:pre|suf)/ and print, next;
|
||||||
|
|
||||||
|
my ($prof, $k, $v) = /^python\.colo\.(.*)(pre|suf) = "(.*)"$/;
|
||||||
|
$v =~ s/\x02/%b/g;
|
||||||
|
$v =~ s/\x03/%c/g;
|
||||||
|
$v =~ s/\x0f/%o/g;
|
||||||
|
$v =~ s/\x16/%r/g;
|
||||||
|
$v =~ s/\x1f/%u/g;
|
||||||
|
|
||||||
|
if ($k eq 'pre') {
|
||||||
|
$profs{$prof} = "%0$v%o%0 %s%o%0 ";
|
||||||
|
} elsif ($k eq 'suf') {
|
||||||
|
$profs{$prof} .= $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for my $prof (keys %profs) {
|
||||||
|
print STDERR "/set plugins.var.python.colo.${prof}fmt $profs{$prof}\n";
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user