forked from sfan5/minetestbot-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrainbow.py
executable file
·49 lines (45 loc) · 1.08 KB
/
rainbow.py
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
#!/usr/bin/env python
"""
rainbow.py - Rainbows
Copyright 2013, sfan5
Licensed under GNU General Public License v2.0
"""
import random
rainbowcolors = ["4", "7", "8", "3", "12", "6", "13"]
def colorize(text, cyclelen=3):
if cyclelen == -1: # Auto-detect
if len(text) < 6:
cyclelen = 1
elif len(text) < 13:
cyclelen = 2
elif len(text) < 25:
cyclelen = 3
else:
cyclelen = 4
out = ""
i = 0
j = 0
for c in text:
if j == 0:
if c in list(str(i) for i in range(10)):
c = u"\u200b" + c # 'ZERO WIDTH SPACE' cuz IRC clients are stupid
out += "\x03" + str(rainbowcolors[i])
out += c
j += 1
if j >= cyclelen:
i += 1
j = 0
if i >= len(rainbowcolors):
i = 0
return out
def rainbow(phenny, input):
arg = input.group(2)
if not arg:
return phenny.say(colorize("Rainbow", cyclelen=1) + "\x03 What?")
if arg.startswith("#") and ' ' in arg and input.admin:
ch = arg.split(" ")[0]
arg = " ".join(arg.split(" ")[1:])
phenny.write(['PRIVMSG', ch], colorize(arg, cyclelen=-1))
else:
phenny.say(colorize(arg, cyclelen=-1))
rainbow.commands = ['rainbow']