|
| 1 | +# # Weechat-Greentext |
| 2 | +# Version: v1 |
| 3 | +# Min WeeChat |
| 4 | +# version tested: 3.8 |
| 5 | +# Author: AGVXOV |
| 6 | + |
| 7 | +# Project Home: https://github.com/agvxov/weechat-greentext |
| 8 | +# This script is Public Domain. |
| 9 | +# |
| 10 | +# Weechat script for applying imageboard formatting to messages. The following are supported: |
| 11 | +# + greentext |
| 12 | +# + purpletext |
| 13 | +# + redtext |
| 14 | +# |
| 15 | +# Both inbound and outbound messages are colored. |
| 16 | +# Since the coloring uses IRC color codes, |
| 17 | +# outbound greentexting will be visible to both you and your friends. |
| 18 | +# |
| 19 | +import weechat |
| 20 | +import re |
| 21 | + |
| 22 | +SCRIPT_NAME = "greentext" |
| 23 | +SCRIPT_AUTHOR = "AGVXOV" |
| 24 | +SCRIPT_VERSION = "1" |
| 25 | +SCRIPT_LICENSE = "PD" |
| 26 | +SCRIPT_DESC = "Colorize imageboard-style text formatting." |
| 27 | + |
| 28 | +greentext_re = re.compile("^\s*>.*$") |
| 29 | +purpletext_re = re.compile("^\s*<.*$") |
| 30 | +redtext_re = re.compile("^.*(==.*==).*$") |
| 31 | + |
| 32 | +COLOR_GREEN = chr(3) + str(3) |
| 33 | +COLOR_PURPLE = chr(3) + str(6) |
| 34 | +COLOR_RED = chr(3) + str(4) + chr(2) |
| 35 | +COLOR_END = chr(3) + str(0) |
| 36 | + |
| 37 | +def hi_greentext(modifier, s): |
| 38 | + if greentext_re.search(s): |
| 39 | + if modifier == 'irc_out1_PRIVMSG': |
| 40 | + s = COLOR_GREEN + s |
| 41 | + else: |
| 42 | + s = weechat.color("green") + s |
| 43 | + return s |
| 44 | + |
| 45 | +def hi_purpletext(modifier, s): |
| 46 | + if purpletext_re.search(s): |
| 47 | + if modifier == 'irc_out1_PRIVMSG': |
| 48 | + s = COLOR_PURPLE + s |
| 49 | + else: |
| 50 | + s = weechat.color("magenta") + s |
| 51 | + return s |
| 52 | + |
| 53 | +def hi_redtext(modifier, s): |
| 54 | + if redtext_re.search(s): |
| 55 | + if modifier == 'irc_out1_PRIVMSG': |
| 56 | + m = redtext_re.search(s) |
| 57 | + s = s[:m.start(1)] + COLOR_RED + m.group(1) + COLOR_END + s[m.end(1):] |
| 58 | + else: |
| 59 | + s = weechat.color("red") + s |
| 60 | + return s |
| 61 | + |
| 62 | +def hi(data, modifier, modifier_data, s): |
| 63 | + msg = weechat.info_get_hashtable('irc_message_parse', {'message': s}) |
| 64 | + r = msg["text"] |
| 65 | + r = hi_greentext(modifier, r) |
| 66 | + r = hi_purpletext(modifier, r) |
| 67 | + r = hi_redtext(modifier, r) |
| 68 | + r = s[:-len(msg["text"])] + r |
| 69 | + return r |
| 70 | + |
| 71 | +def main(): |
| 72 | + if not weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""): |
| 73 | + return |
| 74 | + weechat.hook_modifier('irc_in2_privmsg', 'hi', '') |
| 75 | + weechat.hook_modifier('irc_out1_privmsg', 'hi', '') |
| 76 | + |
| 77 | +if __name__ == "__main__": |
| 78 | + main() |
0 commit comments