chomens-bot-js/plugins/draw.js
ChomeNS 6895a37104 bot.tellraw()
i totally did not used the search icon thing in vscode
2022-11-07 18:30:37 +07:00

47 lines
947 B
JavaScript

/* eslint-disable max-len */
const convert = require('color-convert');
function inject(bot) {
function draw(data, info, prefix = {}) {
const pixels = [];
// Data Buffer -> RGB Array
for (let i = 0; i < data.length; i += info.channels) {
pixels.push([
data[i + 0],
data[i + 1],
data[i + 2],
]);
}
const rows = [];
// RGB Array -> Rows Array
for (let i = 0; i < pixels.length; i += info.width) {
const row = pixels.slice(i, i + info.width);
rows.push(row);
}
const messages = [];
for (const row of rows) {
const message = [{...prefix, text: ''}];
for (const rgb of row) {
message.push({
text: '⎮',
color: `#${convert.rgb.hex(rgb)}`,
});
}
messages.push(message);
}
for (const message of messages) bot.tellraw('@a', message);
}
bot.draw = draw;
}
module.exports = {inject};