mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-12 23:20:25 +08:00
announcing lb updates
This commit is contained in:
parent
7a52519736
commit
e8d73a898d
3 changed files with 80 additions and 14 deletions
|
@ -23,17 +23,17 @@ class BotDAO {
|
|||
return await addCommand("awardChallenge", [discordId, challengeName]);
|
||||
}
|
||||
|
||||
// static async announceLbUpdate(discordId, pos, lb, wpm, raw, acc, con) {
|
||||
// return await addCommand("sayLbUpdate", [
|
||||
// discordId,
|
||||
// pos,
|
||||
// lb,
|
||||
// wpm,
|
||||
// raw,
|
||||
// acc,
|
||||
// con,
|
||||
// ]);
|
||||
// }
|
||||
static async announceLbUpdate(discordId, pos, lb, wpm, raw, acc, con) {
|
||||
return await addCommand("sayLbUpdate", [
|
||||
discordId,
|
||||
pos,
|
||||
lb,
|
||||
wpm,
|
||||
raw,
|
||||
acc,
|
||||
con,
|
||||
]);
|
||||
}
|
||||
|
||||
// this probably will be rewritten but keeping the old code just in case
|
||||
// static async announceDailyLbResult(lbdata) {
|
||||
|
|
|
@ -46,6 +46,7 @@ class LeaderboardsDAO {
|
|||
$set: {
|
||||
[str + ".uid"]: "$uid",
|
||||
[str + ".name"]: "$name",
|
||||
[str + ".discordId"]: "$discordId",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@ const admin = require("firebase-admin");
|
|||
const Logger = require("./handlers/logger.js");
|
||||
const serviceAccount = require("./credentials/serviceAccountKey.json");
|
||||
const { connectDB, mongoDB } = require("./init/mongodb");
|
||||
const BotDAO = require("./dao/bot");
|
||||
|
||||
const PORT = process.env.PORT || 5005;
|
||||
|
||||
|
@ -87,9 +88,73 @@ app.listen(PORT, async () => {
|
|||
});
|
||||
console.log("Database Connected");
|
||||
|
||||
let lbjob = new CronJob("30 4/5 * * * *", async () => {
|
||||
LeaderboardsDAO.update("time", "15", "english");
|
||||
LeaderboardsDAO.update("time", "60", "english");
|
||||
let lbjob = new CronJob("*/20 * * * * *", async () => {
|
||||
let before15 = await mongoDB()
|
||||
.collection("leaderboards.english.time.15")
|
||||
.find()
|
||||
.limit(10)
|
||||
.toArray();
|
||||
LeaderboardsDAO.update("time", "15", "english").then(async () => {
|
||||
let after15 = await mongoDB()
|
||||
.collection("leaderboards.english.time.15")
|
||||
.find()
|
||||
.limit(10)
|
||||
.toArray();
|
||||
|
||||
let changed;
|
||||
for (let index in before15) {
|
||||
if (before15[index].uid !== after15[index].uid) {
|
||||
//something changed at this index
|
||||
changed = after15[index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
let name = changed.discordId ?? changed.name;
|
||||
BotDAO.announceLbUpdate(
|
||||
name,
|
||||
changed.rank,
|
||||
"time 15 english",
|
||||
changed.wpm,
|
||||
changed.raw,
|
||||
changed.acc,
|
||||
changed.consistency
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
let before60 = await mongoDB()
|
||||
.collection("leaderboards.english.time.60")
|
||||
.find()
|
||||
.limit(10)
|
||||
.toArray();
|
||||
LeaderboardsDAO.update("time", "60", "english").then(async () => {
|
||||
let after60 = await mongoDB()
|
||||
.collection("leaderboards.english.time.60")
|
||||
.find()
|
||||
.limit(10)
|
||||
.toArray();
|
||||
let changed;
|
||||
for (let index in before60) {
|
||||
if (before60[index].uid !== after60[index].uid) {
|
||||
//something changed at this index
|
||||
changed = after60[index];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
let name = changed.discordId ?? changed.name;
|
||||
BotDAO.announceLbUpdate(
|
||||
name,
|
||||
changed.rank,
|
||||
"time 60 english",
|
||||
changed.wpm,
|
||||
changed.raw,
|
||||
changed.acc,
|
||||
changed.consistency
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
lbjob.start();
|
||||
|
||||
|
|
Loading…
Reference in a new issue