Added hmmscoreboard
This commit is contained in:
parent
d5f415cee2
commit
c0df2150ae
|
@ -3,6 +3,7 @@ config.json
|
|||
blacklist.json
|
||||
blacklist.log
|
||||
memories.json
|
||||
demo.js
|
||||
|
||||
# ---> Node
|
||||
# Logs
|
||||
|
|
29
bot.js
29
bot.js
|
@ -295,6 +295,35 @@ const runLogic = (client, from, to, message) => {
|
|||
if (check) {
|
||||
useCheatCode(client, from, to, cheatCode);
|
||||
}
|
||||
} else if (message.startsWith("!hmmscoreboard")) {
|
||||
const check = checkBlacklist(client, from, to, "");
|
||||
const size = 3;
|
||||
const compare = (a, b) => {
|
||||
if (a.score < b.score) {
|
||||
return -1;
|
||||
} else if (a.score > b.score) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (check) {
|
||||
const hmmscores = client.brain.memories.hmmscores || {};
|
||||
const scores = [];
|
||||
Object.keys(hmmscores).forEach((user) => {
|
||||
const hmmscore = hmmscores[user];
|
||||
scores.push({
|
||||
user: user,
|
||||
score: hmmscore
|
||||
});
|
||||
});
|
||||
const leaderBoard = scores.sort(compare).reverse().splice(0, size);
|
||||
const header = "Hmm Score Leaderboard:";
|
||||
const entries = [];
|
||||
leaderBoard.forEach((entry) => {
|
||||
entries.push(`${entry.user} ${entry.score}`);
|
||||
});
|
||||
client.say(to, `${header} ${entries.join(" | ")}`);
|
||||
}
|
||||
} else if (
|
||||
message.startsWith("!summon ") ||
|
||||
message.startsWith("!hmmscore ") ||
|
||||
|
|
Loading…
Reference in New Issue