chipmunkbot3/plugins/server_features.js

47 lines
1 KiB
JavaScript
Raw Permalink Normal View History

2024-02-29 22:15:16 -05:00
const defaults = {
amnesicCommandBlocks: false,
2024-09-11 07:41:23 -04:00
commandNamespaces: false,
commandSpy: false
2024-02-29 22:15:16 -05:00
}
function inject (bot, options) {
if (options.features) {
bot.features = { ...defaults, ...options.features }
return
}
bot.features = { ...defaults }
bot.on('packet.declare_commands', packet => {
const rootNode = packet.nodes[0]
if (!rootNode) return
for (const nodeIdx of rootNode.children) {
const node = packet.nodes[nodeIdx]
if (!node) continue
const name = node.extraNodeData.name
if (name) {
const seperatorIdx = name.indexOf(':')
if (seperatorIdx !== -1) {
bot.features.commandNamespaces = true
const namespace = name.substring(0, seperatorIdx)
switch (namespace) {
case 'extras':
bot.features.amnesicCommandBlocks = true
break
2024-09-11 07:41:23 -04:00
case 'commandspy':
bot.features.commandSpy = true
break
2024-02-29 22:15:16 -05:00
}
}
}
}
})
}
module.exports = inject