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

55 lines
1.4 KiB
JavaScript
Executable file

const { literal, argument, greedyString } = require('brigadier-commands')
const colorsys = require('colorsys')
module.exports = {
isBruhifying: false,
create () {
return Object.create(this)
},
register (dispatcher) {
const node = dispatcher.register(
literal('bruhify')
.then(
argument('message', greedyString())
.executes(c => this.bruhifyCommand(c))
)
)
node.description = 'recyclebot'
node.permissionLevel = 0
},
bruhifyCommand (context) {
if (this.isBruhifying) throw new Error('The bot is already bruhifying text!')
this.isBruhifying = true
const source = context.source
const bot = source.bot
const message = context.getArgument('message')
const lines = []
let j = 0
for (let i = 0; i < message.length; i++) {
const result = []
let hue = j
message.split('').forEach((char) => {
result.push({ text: char, color: colorsys.hsv2Hex(hue, 100, 100) })
hue += 355 / Math.max(message.length, 20)
})
lines.push([{ text: '▚ ', color: 'light_purple' }].concat(result, [' ▚']))
j += 355 / Math.max(message.length, 20)
}
let k = 0
const interval = setInterval(() => {
source.sendFeedback(lines[k], false)
if (++k >= lines.length) {
clearInterval(interval)
this.isBruhifying = false
}
}, 50)
}
}