From f2281a7cb3c9b1f26cd2807195a4e14309a95124 Mon Sep 17 00:00:00 2001 From: jay Date: Thu, 24 Dec 2020 19:41:52 +0500 Subject: [PATCH] feat(command): :sparkles: temp. move inventory chat handling to command This is temporary, and only the `toss` function. Old functionality is still intact. New code will eventually move back as a subcommand to replace the old. --- lib/plugins/command.js | 68 ++++++++++++++++++++++++++-------------- lib/plugins/inventory.js | 2 +- 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/lib/plugins/command.js b/lib/plugins/command.js index fc5b443..8986943 100644 --- a/lib/plugins/command.js +++ b/lib/plugins/command.js @@ -426,29 +426,51 @@ function command(username, message) { // case "take": // // TODO take only what's requested, then throw all the rest // // TODO take all - // case "toss": - // case "drop": - // if (!message_parts[1]) { return false } // FIXME, works but ugly - // if (!checkItemExists(message_parts[1])) { return false } - // switch (message_parts.length) { - // case 2: - // bot.toss(mcData.blocksByName[message_parts[1]].id) - // break - // case 3: - // bot.tossStack( - // mcData.itemsByName[message_parts[1]].id, - // (err) => { - // if (err) { - // console.log(err) - // bot.chat(err) - // } - // } - // ) - // break - // default: - // break - // } - // break; + + // TODO move subcommands to cfg.plugins.inventory.itemByName + case "toss": + case "drop": + if (!message_parts[1]) { return false } // FIXME, works but ugly + // TODO use cfg.plugins.inventory.itemByName + const item = cfg.plugins.inventory.itemByName(message_parts[1]) + if (!mcData.findItemOrBlockByName(message_parts[1])) { + console.log("doesn't exist:", message_parts[1]) + cfg.quiet || bot.chat(`item doesn't exist: ${message_parts[1]}`) + return false + } else if (!item) { + console.log("don't have:", message_parts[1]) + cfg.quiet || bot.chat(`don't have item: ${message_parts[1]}`) + } + switch (message_parts.length) { + case 2: + bot.tossStack( + item, + (err) => { + if (err) { + console.error(err) + cfg.quiet || bot.chat(err.message) + } + } + ) + break + case 3: + const amount = parseInt(message_parts[2]) + bot.toss( + item.type, + null, //metadata + amount, + (err) => { + if (err) { + console.error(err) + cfg.quiet || bot.chat(err.message) + } + } + ) + break + default: + break + } + break; case "location": // TODO put in /lib/location switch (message_parts[1]) { diff --git a/lib/plugins/inventory.js b/lib/plugins/inventory.js index c5f3a83..ce65bfb 100644 --- a/lib/plugins/inventory.js +++ b/lib/plugins/inventory.js @@ -225,4 +225,4 @@ const unload = () => { bot.off('chat', inventory) } -module.exports = { load, unload, equipItem, craftItem } \ No newline at end of file +module.exports = { load, unload, equipItem, craftItem, itemByName } \ No newline at end of file