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.
cover
jay 3 years ago
parent 9a6e684b11
commit 67932b2f6a
  1. 25
      lib/plugins/sleeper.js

@ -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)
bot.sleep(bed, (err) => { try {
if (err) { bot.sleep(bed, (err) => {
!quiet && bot.chat(`can't sleep: ${err.message}`) if (err) {
} else { !quiet && bot.chat(`can't sleep: ${err.message}`)
!quiet && bot.chat("zzz") } else {
console.log("sleeping? ", bot.isSleeping) !quiet && bot.chat("zzz")
// hack until this is fixed // apparently, `bot.isSleeping = true` takes a while
// TODO confirm this is fixed // maybe it's async
// bot.isSleeping = true console.log("sleeping? ", bot.isSleeping)
} }
}) })
} 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]) {

Loading…
Cancel
Save