fix for a bug where the role would get overwritten

This commit is contained in:
Jack 2020-07-07 20:30:39 +01:00
parent bc4ea7baf4
commit 4925224b0f
2 changed files with 21 additions and 11 deletions

View file

@ -367,16 +367,27 @@ exports.testCompleted = functions.https.onCall((request, response) => {
request.obj
)}`
);
if (
obj.mode === "time" &&
String(obj.mode2) === "60" &&
obj.discordId !== null &&
obj.discordId !== undefined
) {
console.log(
`sending command to the bot to update the role for user ${request.uid} with wpm ${obj.wpm}`
);
updateDiscordRole(obj.discordId, obj.wpm);
if (obj.mode === "time" && String(obj.mode2) === "60") {
db.collection("users")
.doc(request.uid)
.get()
.then((ret) => {
let userdata = ret.data();
let besttime60 = 0;
try {
dbSnapshot.personalBests.time[60].forEach((result) => {
if (result.wpm > besttime60) besttime60 = result.wpm;
});
} catch (e) {}
if (obj.wpm > besttime60) {
console.log(
`sending command to the bot to update the role for user ${request.uid} with wpm ${obj.wpm}`
);
updateDiscordRole(userdata.discordId, obj.wpm);
}
});
}
return 2;
} else {

View file

@ -1008,7 +1008,6 @@ function showResult(difficultyFailed = false) {
blindMode: config.blindMode,
theme: config.theme,
tags: activeTags,
discordId: dbSnapshot !== null ? dbSnapshot.discordId : null,
};
if (
config.difficulty == "normal" ||