minetestbot-modules/rainbow.py

39 lines
992 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"]
#TODO: make this rainbow better (can't really make it that better because IRC colors suck)
2013-11-09 09:22:51 -08:00
def colorize(text):
out = ""
2014-01-04 07:06:51 -08:00
i = 0
2013-11-09 09:22:51 -08:00
for c in text:
2013-11-09 11:53:47 -08:00
if c in list(str(i) for i in range(10)):
c = u"\u200b" + c # 'ZERO WIDTH SPACE' cuz IRC clients are stupid
2014-01-04 07:06:51 -08:00
out += "\x03" + str(rainbowcolors[i]) + c
i += 1
if i >= len(rainbowcolors):
i = 0
2013-11-09 09:22:51 -08:00
return out
def rainbow(phenny, input):
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
return # Abort function
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']