feat(command): ✨ 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.
This commit is contained in:
		| @@ -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]) { | ||||
|   | ||||
| @@ -225,4 +225,4 @@ const unload = () => { | ||||
|     bot.off('chat', inventory) | ||||
| } | ||||
|  | ||||
| module.exports = { load, unload, equipItem, craftItem } | ||||
| module.exports = { load, unload, equipItem, craftItem, itemByName } | ||||
		Reference in New Issue
	
	Block a user