Skip to content

Commit

Permalink
QUEST #2: create situation messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Markkop committed Dec 15, 2019
1 parent db3889c commit 6ef7356
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,25 @@ const getStats = async (userid) => {
}
}

const selectMessage = ({ hp = 0, maxHealth = 0, exp = 0, toNextLevel = 0 }) => {
const status = `[HP: ${hp}/${maxHealth}] [EXP: ${exp.toFixed()}/${toNextLevel}]`

if (hp <= maxHealth * 0.3) {
return `I'm almost dying, help! ${status}`
}

if (exp >= toNextLevel * 0.7) {
return `I'm almost leveling up! ${status}`
}

return `Things are fine for now. ${status}`
}

const reportStatus = async () => {
try {
const stats = await getStats(process.env.HABITICA_USERID)
console.log(stats)
const message = selectMessage(stats)
console.log(message)
} catch (error) {
console.log(error)
}
Expand Down

0 comments on commit 6ef7356

Please sign in to comment.