Added hmmscoreboard

This commit is contained in:
aewens 2018-07-17 11:59:52 -04:00
parent d5f415cee2
commit c0df2150ae
2 changed files with 30 additions and 0 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ config.json
blacklist.json
blacklist.log
memories.json
demo.js
# ---> Node
# Logs

29
bot.js
View File

@ -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 ") ||