chipmunkbot3/commands/rainbowify.js

31 lines
806 B
JavaScript
Raw Normal View History

2024-04-02 17:53:10 -04:00
const { literal, argument, greedyString } = require('brigadier-commands')
2024-02-11 21:23:41 -05:00
const colorsys = require('colorsys')
2024-04-02 17:53:10 -04:00
module.exports = {
register (dispatcher) {
const node = dispatcher.register(
literal('rainbowify')
.then(
argument('message', greedyString())
.executes(c => this.rainbowifyCommand(c))
2024-04-02 17:53:10 -04:00
)
)
node.description = 'Makes text rainbow'
node.permissionLevel = 0
},
2024-02-11 21:23:41 -05:00
2024-04-02 17:53:10 -04:00
rainbowifyCommand (context) {
const source = context.source
const message = context.getArgument('message')
2024-02-11 21:23:41 -05:00
2024-04-02 17:53:10 -04:00
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)
})
2024-02-11 21:23:41 -05:00
2024-04-02 17:53:10 -04:00
source.sendFeedback(result, false)
}
}