2022-11-27 02:35:28 -05:00
|
|
|
const convert = require('color-convert')
|
2022-10-15 08:53:48 -04:00
|
|
|
|
2022-11-16 06:41:30 -05:00
|
|
|
// eslint-disable-next-line require-jsdoc
|
2022-11-27 02:35:28 -05:00
|
|
|
function inject (bot) {
|
2022-11-16 06:41:30 -05:00
|
|
|
/**
|
|
|
|
* draw which is totallynotskidded from ybot
|
|
|
|
* @param {buffer} data data buffer
|
|
|
|
* @param {*} info idk bout this
|
|
|
|
* @param {object} prefix prefix in the output compoenent
|
|
|
|
*/
|
2022-11-27 02:35:28 -05:00
|
|
|
function draw (data, info, prefix = {}) {
|
|
|
|
const pixels = []
|
2022-10-15 08:53:48 -04:00
|
|
|
|
|
|
|
// Data Buffer -> RGB Array
|
|
|
|
for (let i = 0; i < data.length; i += info.channels) {
|
|
|
|
pixels.push([
|
|
|
|
data[i + 0],
|
|
|
|
data[i + 1],
|
2022-11-27 02:35:28 -05:00
|
|
|
data[i + 2]
|
|
|
|
])
|
2022-10-15 08:53:48 -04:00
|
|
|
}
|
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
const rows = []
|
2022-10-15 08:53:48 -04:00
|
|
|
|
|
|
|
// RGB Array -> Rows Array
|
|
|
|
for (let i = 0; i < pixels.length; i += info.width) {
|
2022-11-27 02:35:28 -05:00
|
|
|
const row = pixels.slice(i, i + info.width)
|
2022-10-15 08:53:48 -04:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
rows.push(row)
|
2022-10-15 08:53:48 -04:00
|
|
|
}
|
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
const messages = []
|
2022-10-15 08:53:48 -04:00
|
|
|
|
|
|
|
for (const row of rows) {
|
2022-11-27 02:35:28 -05:00
|
|
|
const message = [{ ...prefix, text: '' }]
|
2022-10-15 08:53:48 -04:00
|
|
|
|
|
|
|
for (const rgb of row) {
|
|
|
|
message.push({
|
|
|
|
text: '⎮',
|
2022-11-27 02:35:28 -05:00
|
|
|
color: `#${convert.rgb.hex(rgb)}`
|
|
|
|
})
|
2022-10-15 08:53:48 -04:00
|
|
|
}
|
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
messages.push(message)
|
2022-10-15 08:53:48 -04:00
|
|
|
}
|
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
for (const message of messages) bot.tellraw('@a', message)
|
2022-10-15 08:53:48 -04:00
|
|
|
}
|
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
bot.draw = draw
|
2022-10-15 08:53:48 -04:00
|
|
|
}
|
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
module.exports = { inject }
|