chipmunkbot3/plugins/utility.js

31 lines
654 B
JavaScript
Raw Normal View History

2024-04-02 17:53:10 -04:00
const fs = require('fs/promises')
function inject (bot) {
function tellraw (text, target = '@a') {
bot.core.run(`minecraft:tellraw ${target} ${JSON.stringify(text)}`)
}
async function listFiles (filepath, styling = {}) {
const list = await fs.readdir(filepath)
const msg = []
list.forEach((filename, idx) => {
if (idx !== 0) msg.push(' ')
const highlighting = !(idx & 1) ? bot.styles.secondary : bot.styles.primary
msg.push({
text: filename,
...highlighting,
...styling
})
})
return msg
}
bot.tellraw = tellraw
bot.listFiles = listFiles
}
module.exports = inject