mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-04 21:09:18 +08:00
35 lines
841 B
JavaScript
35 lines
841 B
JavaScript
|
|
function incrementT60Bananas(uid, result, userData) {
|
|
try {
|
|
let best60;
|
|
try {
|
|
best60 = Math.max(
|
|
...userData.personalBests.time[60].map((best) => best.wpm)
|
|
);
|
|
if (!Number.isFinite(best60)) {
|
|
throw "Not finite";
|
|
}
|
|
} catch (e) {
|
|
best60 = undefined;
|
|
}
|
|
|
|
if (best60 != undefined && result.wpm < best60 - best60 * 0.25) {
|
|
// console.log("returning");
|
|
} else {
|
|
//increment
|
|
// console.log("checking");
|
|
User.findOne({ uid: uid }, (err, user) => {
|
|
if (user.bananas === undefined) {
|
|
user.bananas.t60bananas = 1;
|
|
} else {
|
|
user.bananas.t60bananas += 1;
|
|
}
|
|
user.save();
|
|
});
|
|
}
|
|
} catch (e) {
|
|
console.log(
|
|
"something went wrong when trying to increment bananas " + e.message
|
|
);
|
|
}
|
|
}
|