bitbot-3.11-fork/modules/rainbow.py

43 lines
1.3 KiB
Python
Raw Normal View History

2020-01-21 16:37:37 +00:00
import random
from src import ModuleManager, utils
COLORS = [
utils.consts.BLUE,
utils.consts.LIGHTBLUE,
utils.consts.CYAN,
utils.consts.LIGHTCYAN,
utils.consts.GREEN,
utils.consts.LIGHTGREEN,
utils.consts.YELLOW,
utils.consts.ORANGE,
utils.consts.BROWN,
utils.consts.RED,
utils.consts.PINK,
utils.consts.PURPLE
]
2020-01-21 16:40:18 +00:00
@utils.export("channelset", utils.BoolSetting("rainbow",
"Enable/disable allowing rainbowification of strings"))
2020-01-21 16:37:37 +00:00
class Module(ModuleManager.BaseModule):
@utils.hook("received.command.rainbow")
@utils.kwarg("help", "Rainbowify a given string or the last message")
@utils.kwarg("usage", "[string]")
def rainbow(self, event):
2020-01-21 16:40:18 +00:00
if event["is_channel"] and not event["target"].get_setting(
"rainbow", False):
return
2020-01-21 16:37:37 +00:00
args = event["args"]
if not args:
args = event["target"].buffer.get()
if not args:
raise utils.EventError("No line found to rainbowify")
args = utils.irc.strip_font(args)
2020-01-21 16:37:37 +00:00
offset = random.randint(0, len(COLORS))
out = ""
2020-01-22 16:32:31 +00:00
for i, c in enumerate(args):
2020-01-21 16:37:37 +00:00
color = COLORS[(i+offset)%len(COLORS)]
out += utils.irc.color(c, color, terminate=False)
event["stdout"].write(out)