File: glitter.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 (25 lines) | stat: -rw-r--r-- 971 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
import weechat, re

SCRIPT_NAME    = "glitter"
SCRIPT_AUTHOR  = "jotham.read@gmail.com"
SCRIPT_VERSION = "0.1"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC    = "Replaces ***text*** you write with rainbow text"

if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
   weechat.hook_command_run("/input return", "command_run_input", "")

glitter_pat = re.compile("\*\*\*([^\*]+)\*\*\*")
def glitter_it(match):
   lut = ("13","4","8","9","11","12") # len=6
   text = match.group(1)
   return "".join(["\03"+lut[i%6]+text[i] for i in range(len(text))]) + "\03"

def command_run_input(data, buffer, command):
   if command == "/input return":
      input = weechat.buffer_get_string(buffer, 'input')
      if input.startswith('/set '): # Skip modification of settings
         return weechat.WEECHAT_RC_OK
      input = glitter_pat.sub(glitter_it, input)
      weechat.buffer_set(buffer, 'input', input)
   return weechat.WEECHAT_RC_OK