Script: aesthetic.py

Make messages more A E S T H E T I C A L L Y pleasing.
Author: Wojciech Siewierski — Version: 1.0.5 — License: GPL3
For WeeChat ≥ 0.3.0.
Added: 2019-10-09
Download

 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
#
# Script Name: aesthetic.py
# Script Author: Wojciech Siewierski
# Script License: GPLv3
# Contact: vifon @ irc.freenode.net

SCRIPT_NAME = 'aesthetic'
SCRIPT_AUTHOR = 'Wojciech Siewierski'
SCRIPT_VERSION = '1.0.5'
SCRIPT_LICENSE = 'GPLv3'
SCRIPT_DESC = 'Make messages more A E S T H E T I C A L L Y pleasing.'

import_ok = True

try:
    import weechat
except ImportError:
    print('This script must be run under WeeChat')
    print('You can obtain a copy of WeeChat, for free, at https://weechat.org')
    import_ok = False

weechat_version = 0

import shlex
import sys

def aesthetic_(args):
    for arg in args:
        try:
            arg = arg.decode('utf8')
        except AttributeError:
            pass
        yield " ".join(arg.upper())
        for n, char in enumerate(arg[1:]):
            yield " ".join(" "*(n+1)).join(char.upper()*2)

def aesthetic(args):
    if sys.version_info < (3,):
        return (x.encode('utf8') for x in aesthetic_(args))
    else:
        return aesthetic_(args)

def aesthetic_cb(data, buffer, args):
    for x in aesthetic(shlex.split(args)):
        weechat.command(buffer, x)
    return weechat.WEECHAT_RC_OK

if __name__ == "__main__" and import_ok:
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
        weechat_version = weechat.info_get("version_number", "") or 0
        weechat.hook_command(
            "aesthetic",
            """Format a message like this:

E X A M P L E
X X
A   A
M     M
P       P
L         L
E           E

Each argument is formatted separately, use sh-like quotes for grouping.  For example '/aesthetic foo bar' will send two such blocks while '/aesthetic "foo bar"' would send one larger one.

Use with care to not cause undesirable message spam.""",
            "message", "",
            "",
            "aesthetic_cb", ""
        )