From 67932b2f6a44b5085ec260156924c724e3c51c65 Mon Sep 17 00:00:00 2001 From: jay Date: Sat, 16 Jan 2021 16:39:42 +0500 Subject: [PATCH] fix(sleeper): :goal_net: catch sleeping edge case errors Happens when trying to sleep while previously unable to move. Or maybe when trying to sleep during dawn. --- lib/plugins/sleeper.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/plugins/sleeper.js b/lib/plugins/sleeper.js index a01c3ec..5985f07 100644 --- a/lib/plugins/sleeper.js +++ b/lib/plugins/sleeper.js @@ -33,17 +33,20 @@ function sleep(quiet = cfg.sleep.quiet) { cfg.plugins.mover && cfg.plugins.mover.moveNear(bed.position, 2) bot.once('goal_reached', (goal) => { console.info(goal) - bot.sleep(bed, (err) => { - if (err) { - !quiet && bot.chat(`can't sleep: ${err.message}`) - } else { - !quiet && bot.chat("zzz") - console.log("sleeping? ", bot.isSleeping) - // hack until this is fixed - // TODO confirm this is fixed - // bot.isSleeping = true - } - }) + try { + bot.sleep(bed, (err) => { + if (err) { + !quiet && bot.chat(`can't sleep: ${err.message}`) + } else { + !quiet && bot.chat("zzz") + // apparently, `bot.isSleeping = true` takes a while + // maybe it's async + console.log("sleeping? ", bot.isSleeping) + } + }) + } catch (error) { + console.error(error) + } }) }) } else if (bed = bot.inventory.items().filter(bot.isABed)[0]) {