chipmunkbot-archive/plugins/video.js
2023-06-26 23:04:54 -04:00

53 lines
No EOL
1.4 KiB
JavaScript

const fs = require('fs')
const crypto = require('crypto')
const toNBTUUID = require('./../util/uuid-to-nbt-uuid.js')
function inject(bot) {
let cancel = false
bot.video = {}
bot.video.play = function (filepath, uuids) {
cancel = false
const frames = fs.readFileSync(filepath).toString().replace(/\r\n|\r/g, '\n').split(/\n--/)
let i = 0
clearInterval(bot.video.playInterval)
bot.video.playInterval = setInterval(() => {
const lines = frames[i].split('\n')
for (const j in lines) {
bot.core.run(`/data merge entity ${uuids[j]} {CustomName: "${JSON.stringify(lines[j]).replace(/"/g, '\\"')}"}`)
}
i++//; bot.core.run(`/bcraw Frame: ${i}, Frames: ${frames.length}`)
if (i >= frames.length || cancel)
clearInterval(bot.video.playInterval)
}, 100)
}
bot.video.summon = function (sel, callback) {
const uuids = []
let i = 0
const interval = setInterval(() => {
const uuid = crypto.randomUUID()
bot.exploits.execute(`at ${/*uuids.length < 1 ? */sel/* : uuids[0]*/} run summon armor_stand ~ ~${(i * -0.2) + 1} ~ {UUID: ${toNBTUUID(uuid)}, NoGravity: 1b, CustomNameVisible: 1b, Invisible: 1b, Marker: 1b}`)
uuids.push(uuid)
i++
if (i > 20) {
clearInterval(interval)
if (callback)
callback(uuids)
}
}, 1)
}
bot.video.stop = function () {
cancel = true
}
}
module.exports = inject