chipmunkbot3/commands/rainbowify.js
2024-07-31 22:34:19 -04:00

31 lines
No EOL
806 B
JavaScript

const { literal, argument, greedyString } = require('brigadier-commands')
const colorsys = require('colorsys')
module.exports = {
register (dispatcher) {
const node = dispatcher.register(
literal('rainbowify')
.then(
argument('message', greedyString())
.executes(c => this.rainbowifyCommand(c))
)
)
node.description = 'Makes text rainbow'
node.permissionLevel = 0
},
rainbowifyCommand (context) {
const source = context.source
const message = context.getArgument('message')
const result = []
let hue = 0
message.split('').forEach((char) => {
result.push({ text: char, color: colorsys.hsv2Hex(hue, 100, 100) })
hue += 355 / Math.max(message.length, 20)
})
source.sendFeedback(result, false)
}
}