fix(sleeper): 🥅 catch sleeping edge case errors

Happens when trying to sleep while previously unable to move.
Or maybe when trying to sleep during dawn.
This commit is contained in:
jay 2021-01-16 16:39:42 +05:00
parent 9a6e684b11
commit 67932b2f6a

View File

@ -33,17 +33,20 @@ function sleep(quiet = cfg.sleep.quiet) {
cfg.plugins.mover && cfg.plugins.mover.moveNear(bed.position, 2) cfg.plugins.mover && cfg.plugins.mover.moveNear(bed.position, 2)
bot.once('goal_reached', (goal) => { bot.once('goal_reached', (goal) => {
console.info(goal) console.info(goal)
try {
bot.sleep(bed, (err) => { bot.sleep(bed, (err) => {
if (err) { if (err) {
!quiet && bot.chat(`can't sleep: ${err.message}`) !quiet && bot.chat(`can't sleep: ${err.message}`)
} else { } else {
!quiet && bot.chat("zzz") !quiet && bot.chat("zzz")
// apparently, `bot.isSleeping = true` takes a while
// maybe it's async
console.log("sleeping? ", bot.isSleeping) console.log("sleeping? ", bot.isSleeping)
// hack until this is fixed
// TODO confirm this is fixed
// bot.isSleeping = true
} }
}) })
} catch (error) {
console.error(error)
}
}) })
}) })
} else if (bed = bot.inventory.items().filter(bot.isABed)[0]) { } else if (bed = bot.inventory.items().filter(bot.isABed)[0]) {