aboutsummaryrefslogtreecommitdiff
path: root/modules/rainbow.py
diff options
context:
space:
mode:
authorGravatar jesopo2020-01-21 16:37:37 +0000
committerGravatar jesopo2020-01-21 16:37:37 +0000
commiteaf96b6c679718eda975772f76f9d5726c8dd9c5 (patch)
tree1cf6910aff53c9aa1ca4467a68a84b85a34fa813 /modules/rainbow.py
parentsplit permission for !alias/!balias in to two (diff)
signature
add rainbow.py
Diffstat (limited to 'modules/rainbow.py')
-rw-r--r--modules/rainbow.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/rainbow.py b/modules/rainbow.py
new file mode 100644
index 00000000..cb79e4d2
--- /dev/null
+++ b/modules/rainbow.py
@@ -0,0 +1,35 @@
+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
+]
+
+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):
+ args = event["args"]
+ if not args:
+ args = event["target"].buffer.get()
+ if not args:
+ raise utils.EventError("No line found to rainbowify")
+
+ offset = random.randint(0, len(COLORS))
+ out = ""
+ for i, c in enumerate(event["args"]):
+ color = COLORS[(i+offset)%len(COLORS)]
+ out += utils.irc.color(c, color, terminate=False)
+ event["stdout"].write(out)