mindcraft/utils/commands.js

85 lines
2.5 KiB
JavaScript
Raw Normal View History

2023-10-19 22:49:52 -05:00
import { getStats, getInventory, getBlocks, getNearbyEntities, getCraftable } from './context.js';
2023-11-05 15:38:52 -06:00
import { currentCode, writeCode } from '../act.js';
const pad = (str) => {
return '\n\`\`\`\n' + str + '\n\`\`\`';
}
const commandsList = [
{
name: "!stats",
description: "Get the bot's stats (name, health, food, saturation, armor, held item, position, velocity, gamemode, experience, level, effects).",
2023-11-05 15:38:52 -06:00
perform: function (bot, user, turns) {
return pad(getStats(bot));
}
},
{
name: "!inventory",
description: "Get the bot's inventory.",
2023-11-05 15:38:52 -06:00
perform: function (bot, user, turns) {
return pad(getInventory(bot));
}
},
{
name: "!blocks",
description: "Get the blocks near the bot.",
2023-11-05 15:38:52 -06:00
perform: function (bot, user, turns) {
return pad(getBlocks(bot));
}
},
{
name: "!craftable",
description: "Get the craftable items with the bot's inventory.",
2023-11-05 15:38:52 -06:00
perform: function (bot, user, turns) {
return pad(getCraftable(bot));
}
},
{
name: "!entities",
description: "Get the nearby players and entities.",
2023-11-05 15:38:52 -06:00
perform: function (bot, user, turns) {
2023-10-19 22:49:52 -05:00
return pad(getNearbyEntities(bot));
}
},
{
name: "!action",
description: "Get the currently executing code.",
2023-11-05 15:38:52 -06:00
perform: function (bot, user, turns) {
return pad(currentCode(bot));
}
},
{
name: "!execute",
2023-11-05 15:38:52 -06:00
description: "Write javascript code to move, mine, build, or do anything else in the minecraft world. Example usage: \n!execute\n\`\`\`\nCODE\n\`\`\`",
perform: function (bot, user, turns) {
return writeCode(bot, user, turns);
}
}
];
const commandsMap = {};
for (let command of commandsList) {
commandsMap[command.name] = command;
}
export function getCommand(name) {
return commandsMap[name];
}
2023-11-05 15:38:52 -06:00
export function containsCommand(message) {
for (let command of commandsList) {
if (message.includes(command.name)) {
return command.name;
}
}
return null;
}
export function getCommandDocs() {
2023-11-05 15:38:52 -06:00
let docs = `COMMAND DOCS\n***\n You can use the following commands to query for information about the world.
The first word of your response must be a command name in order to use commands. \n`;
for (let command of commandsList) {
docs += command.name + ': ' + command.description + '\n';
}
return docs + '\n***\n';
}