minetestbot-modules/rainbow.py

40 lines
827 B
Python
Raw Normal View History

2013-11-09 09:22:51 -08:00
#!/usr/bin/env python
"""
rainbow.py - Rainbows
Copyright 2013, sfan5
"""
import random
2014-01-04 07:06:51 -08:00
rainbowcolors = ["4", "7", "8", "3", "12", "6", "13"]
2013-11-09 09:22:51 -08:00
def colorize(text):
out = ""
2014-01-04 07:06:51 -08:00
i = 0
2014-01-04 07:19:19 -08:00
j = 0
2013-11-09 09:22:51 -08:00
for c in text:
2014-07-28 10:07:46 -07:00
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
2014-01-04 07:19:19 -08:00
j += 1
if j >= 3:
i += 1
j = 0
2014-01-04 07:06:51 -08:00
if i >= len(rainbowcolors):
i = 0
2013-11-09 09:22:51 -08:00
return out
def rainbow(phenny, input):
arg = input.group(2)
if not arg:
2013-11-09 11:53:47 -08:00
return phenny.say(colorize("Rainbow") + "\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))
else:
phenny.say(colorize(arg))
2013-11-09 09:22:51 -08:00
rainbow.commands = ['rainbow']