31 lines
654 B
JavaScript
31 lines
654 B
JavaScript
|
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
|