embellish.py v1.3

This commit is contained in:
wowaname 2016-07-26 00:29:52 +00:00
parent d1e0893a13
commit 3b8fb95eb8

View File

@ -4,6 +4,8 @@
"""embellish: make your chats noticable""" """embellish: make your chats noticable"""
# v1.3 - wowaname
# changed hook so script doesn't modify the input buffer
# v1.2 - wowaname # v1.2 - wowaname
# whitelist_buffers added # whitelist_buffers added
# message won't be decorated if blank # message won't be decorated if blank
@ -21,18 +23,18 @@ import weechat
SCRIPT_NAME = "embellish" SCRIPT_NAME = "embellish"
SCRIPT_AUTHOR = "The Krusty Krab <wowaname@volatile.ch>" SCRIPT_AUTHOR = "The Krusty Krab <wowaname@volatile.ch>"
SCRIPT_VERSION = "1.1" SCRIPT_VERSION = "1.3"
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": ( "pre": (
"13♥", "\x0313♥",
"Text to add to the beginning of messages.", "Text to add to the beginning of messages.",
), ),
"suf": ( "suf": (
"13♥", "\x0313♥",
"Text to add to the end of messages.", "Text to add to the end of messages.",
), ),
"fgs": ( "fgs": (
@ -83,15 +85,15 @@ 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_command_run("/input return", "cb_embellish", "") weechat.hook_modifier("input_text_for_buffer", "cb_embellish", "")
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, buffer, command): def cb_embellish(data, mod, buf, input):
buffer_name = weechat.buffer_get_string(buffer, "name").lower() buffer_name = weechat.buffer_get_string(buf, "name").lower()
output = "" output = ""
profile = "" profile = ""
@ -103,22 +105,22 @@ def cb_embellish(data, buffer, command):
for pattern in weechat.config_get_plugin("ignore_buffers").lower().split(","): for pattern in weechat.config_get_plugin("ignore_buffers").lower().split(","):
if (pattern.startswith("re:") and if (pattern.startswith("re:") and
re.search(pattern[3:], buffer_name)) or glob_match(pattern, buffer_name): re.search(pattern[3:], buffer_name)) or glob_match(pattern, buffer_name):
return weechat.WEECHAT_RC_OK return input
if command == "/input return":
input = weechat.buffer_get_string(buffer, "input").rstrip()
if not input: if not input:
return weechat.WEECHAT_RC_OK return input
if input.startswith("/"): if input != "/" and input.startswith("/") and input.split(" ",
1)[0].split("\n", 1)[0].find("/", 1) < 0:
for cmd in weechat.config_get_plugin("whitelist_cmds").lower().split(","): for cmd in weechat.config_get_plugin("whitelist_cmds").lower().split(","):
if not input.startswith("/%s " % cmd): continue if not input.startswith("/%s " % cmd): continue
output = "/%s " % cmd output = "/%s " % cmd
input = input.split(" ", 1)[1] if " " in input else "" input = input.split(" ", 1)[1] if " " in input else ""
break break
else: else:
return weechat.WEECHAT_RC_OK return input
if input.startswith("//"): input = input[1:]
for profile_pairs in weechat.config_get_plugin("profiles").split(","): for profile_pairs in weechat.config_get_plugin("profiles").split(","):
prefix, name = profile_pairs.split() prefix, name = profile_pairs.split()
@ -132,7 +134,7 @@ def cb_embellish(data, buffer, command):
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 = "%s%s%s" % ( base = "\x0f\x03%s%s%s" % (
random.choice(fgs), random.choice(fgs),
"," if bgs != [""] else "", "," if bgs != [""] else "",
random.choice(bgs), random.choice(bgs),
@ -141,18 +143,21 @@ def cb_embellish(data, buffer, command):
input = re.sub( input = re.sub(
"\x03([^0-9])", "\x03([^0-9])",
"\x03%s\\1" % base, "\x03%s\\1" % base,
input.replace("\x0f","\x0f%s" % base).replace( input.replace("\x0f","\x0f%s" % base))
"\r","\r%s" % base).replace(
"\n","\n%s" % base) #l = (409 - len(base) * 3 -
) # weechat.info_get("irc_server_isupport_value", "*,NICKLEN")
output += "%s%s%s %s%s %s" % ( l = 400 - len(base) * 3
o = []
for line in input.replace("\r", "").split("\n"):
for i in xrange(0, len(line), l):
o.append("%s%s%s %s%s %s" % (
base, base,
weechat.config_get_plugin("%spre" % profile), weechat.config_get_plugin("%spre" % profile),
base, base,
input, line[i:i+l].rstrip(),
base, base,
weechat.config_get_plugin("%ssuf" % profile), weechat.config_get_plugin("%ssuf" % profile),
) ))
weechat.buffer_set(buffer, "input", output) return output + "\n".join(o)
return weechat.WEECHAT_RC_OK